Compact25

Posts   
 
    
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 10-Jan-2009 14:56:23   

Hi, I've a small problem and hope you'll have more idea than me to fix it. It's not a pb in llblgen, just a pb in the way I use it :-)

I serialize an entity collection in compact25 then this xml is handled by an external script that can change fields etc. When the xml come back I make deserialization and have my EntityCollection back. It's fine.

But ... of course all entity and all fields have IsDirty=false :-(. I understand that it's normal. But with that I can't save the entities (except if I mark all as modified but it's not a good solutions) I've checked that modified fields have same value (=the new value) for both DbValue and CurrentValue (so I can't compare it to know if the fields have been modified).

Do you have any idea on how to detect modified fields ? so I can put it as dirty... and then I can save that.

ps: I can modify the external script, so if I know where to change in the xml to mark the field as modified ... it can solve my problem

Tx for any help

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 10-Jan-2009 15:55:02   

Please see the Compact25 specification: http://www.llblgen.com/documentation/2.6/hh_goto.htm#Using%20the%20generated%20code/gencode_xmlsupport.htm%23compact

In short: if a field has been changed, the original value has to be placed in a dbv element and you have to set the right flag in the compacted bit array. If you can't figure it out from the description in the manual, you could try to load an entity from the DB, change a couple of fields and serialize it to a file in the Compact25 format. You'll see the Xml gets an _lps section. simple_smile

These sections contain the change tracking information, so deserializing the xml into entities will mark the right fields dirty and will allow you to save the entities simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 10-Jan-2009 16:26:01   

Hehe yes I was trying to understand the doc, tx for the tip I'll try to serialize modified entity to see how it's done.

In the doc it's say that the bit are placed in the order of FieldIndex with 2 bit for each field. But: How to know the fieldindex of a field ?

I know it's not clear so if I've this output:

    <OrderEntity ObjectID="d8117794-675c-45ce-bd97-f23c22391039">
        <OrderId>10746</OrderId>
        <CustomerId>CHOPS</CustomerId>
        <EmployeeId>1</EmployeeId>
        <OrderDate>1997-11-19T00:00:00.0000000+01:00</OrderDate>
        <RequiredDate>1997-12-17T00:00:00.0000000+01:00</RequiredDate>
        <ShippedDate>1997-11-21T00:00:00.0000000+01:00</ShippedDate>
        <ShipVia>3</ShipVia>
        <Customer Ref="df7c7b33-1fd2-4fe9-b3b4-ec8d00eeebed" />
        <NullableDateTime></NullableDateTime>
        <CompanyName>Foo Inc.</CompanyName>
        <NullableDec></NullableDec>
        <NulledString></NulledString>
        <_lps fs="AACAAA==" es="1" />
    </OrderEntity>

Ok I modify the "CompanyName" so to change the the bitarray I need to know the fieldindex of the field "CompanyName". How can I have this info ?

I know Compact25 is for communication between 2 components that have the entity schema, so I know I use it in a quite strange way. I took this format because I'm making web components (in javascript!!) that are taking and modifying entity(collection) via ajax. So I need the most compact format. Then I'll have to find away to handle the bit array .. in javascript I don't think it'll be easy smile . Yes it's not yet finished simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 13-Jan-2009 18:18:38   

The index is indeed a good point... that information isn't in the XML. To assume given indexes in the javascript might be too fragile I think... If you're ok with that, you can go that route.

There is a way I think, but it's a bit difficult, and only works if javascript modifies existing entities. When a field has been changed, its DbValue is stored in the _dbv section. The IsNull/IsChanged flags aren't set when a field has a DbValue set in the _dbv section during deserialization, as new entities have to have this change information also, so the change info is in the bitfield. You could try (but I admit, this is pretty hard), to check which fields are in the _dbv section, then grab their index and then build the bitfield and then deserialize. You can also use the _dbv section to post-process the deserialized entities and set IsChanged flags of the fields found in the _dbv section of the xml.

Frans Bouma | Lead developer LLBLGen Pro
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 14-Jan-2009 19:29:58   

As the _dbv can be empty, so no info available, I think I'll go for your second idea, which seem to be the best in this case. Thanks for the tip !