0

I'm having the following issue with GreenDao and don't know how to solve it. I have some entity - lets say USER, that has 4 potentials param:FIRST_NAME,LAST_NAME,AGE,LOCAL_VAL and when I'm getting a USER from the server it has only 3 params: FIRST_NAME,LAST_NAME,AGE. Now, I'm guessing that when I'm getting user from the server and using InsertOrReplace then this user(with the same Id) get overrides and the value in LOCAL_VAL sets to 0 because the server doesn't return it.

a naive solution is to get the USER entity from the database with his ID and to check the value of LOCAL_VAL, if it's not equals 0 then we save it again in the new USER from the server. This solution isn't good because it contains to many database access.

Is it possible not to override all the entities values?

( In my scenario this VAL contains Id of different entity from 1-N relation)

Nativ
  • 3,092
  • 6
  • 38
  • 69
  • we have the same problem (different API endpoints return response in different granularity) and we load the existing item and update it. To make it easier, for each Entity, we generate an updateNotNull method that overwrites non-null values from the new one. This helps in a case where if some code already has a reference to that object, that exact object gets refreshed. – yigit May 20 '13 at 19:06
  • Yes this solution is very expensive in db accesses, for every entity you are doing 1 db access. In my payload there's 20-100 entities so it might be a problem. – Nativ May 20 '13 at 19:09
  • for our case, we already use a unique identity scope so each item has only 1 copy in memory. If we are pulling data from network, if is very likely to be shown to the user (+ we always show local copy while updating it so most of the time, read happens even before the network request for update). If you look at the overall picture, instead of writing to disk and later reading to show (because you need all fields), we first read than write. I agree this can still be more expensive but for our use case overall cost is almost the same (unless you don't use the identity scope as we do) – yigit May 20 '13 at 23:19

0 Answers0