Wednesday, 15 June 2011

entities - android greendao update only specific fields in entity -



entities - android greendao update only specific fields in entity -

i have been searching while solution problem without success.

i have application in receive info particular entity in database different services, using greendaos insertorreplace methods whenever entity exists in db gets updated instead of recreated.

so far good.

the problem is.. let's illustration sake entity called user, fields id, title, , displayname.

so in first phone call json object containing user id , title fields, insert db , naturally displayname gets inserted null.

afterwards service json containing same user (same id field), comes displayname well, doesn't include title info @ all.

so whenever run insertorreplace on dao object automatically generated greendao, user gets updated title info not present, when gets updated title field gets reset null, end losing data.

unfortunately unable alter info beingness returned services, , haven't been able prepare issue. find hard believe there no easy way tell dao object update fields , no of them.

i looking @ code generated greendao , in dao objects generated there bindvalues method gets called before query gets executed, , apparently filters out null properties object, either way gets updated null value.

i able come sort of prepare modifying final dao object beingness generated adding methods parent class, don't think solution because have dao objects. (i know it's possible define custom superclass applies entity object , not dao one).

i appreciate if has thought on how resolve this, , sorry long explanation, wanted clear on issue.

thanks.

first of all: wouldn't temper generated code unless know doing. modifications may have effects on caches , data-integrity.

generally next (insert-or)-update-approach if using orm-framework (like greendao):

try entity, want modify db (maybe in cache, may not real database operation) if don't have such entity: create it modify entity according needs insert or update in database (in greendao utilize insertorreplace)

android entities greendao greendao-generator

No comments:

Post a Comment