On Monday 12 May 2014 18:05:04 Matt Quinn wrote: > I'm using what CBL gives you natively for saving changes, yeah. For new > docs, I do something similar to your code (but in that case there's no > map copying: just fill map->save). For updating documents, I use > Document.update() instead: it streamlines handling update conflicts, and > lets you bail on making the update if you see another change that > obsoletes it came in first.
Do have a code sample you can share for using the Document.update()?
> In my experience using CBL without an ORM isn't too much of a pain, but
> - our app has been designed around that, and
> - our data model has changed enough over time that we have
> ORM-unfriendly warts to handle anyway.
> I totally understand the case for one though.
So far ORMlite saves me the whole interaction with the database and casting /
converting classes. Given the right annotations, I can simply call:
// GET
Date birthday = aUser.getBirthday();
// SET
aUser.setBirthday(new Date());
// PERSIST
dbHelper.save(aUser);
In CBL it would look like this (which I could wrap it into a static methods of
a class "User" just like the ToDoLite example does):
// GET
// toString() or a class cast?
String dateString =
aDocument.getProperty(ATTRIBUTE_BIRTHDAY).toString();
DateFormat formatter = new SimpleDateFormat("d-MMM-yyyy,HH:mm:ss aaa");
Date birthday = formatter.parse(dateString);
// SET
Map<String, Object> curProperties = aDocument.getProperties();
Map<String, Object> newProperties = new HashMap<String, Object>();
newProperties.putAll(curProperties);
newProperties.put(ATTRIBUTE_BIRTHDAY, formatter.format(new Date()));
aDocument.putProperties(newProperties);
// PERSIST
// already done by using putProperties
Is that how you do it?
Regards,
Sascha
signature.asc
Description: This is a digitally signed message part.
