greenrobot/greenDAO — Issue #15: Easy Datastore Integration
Author: funk78
Created: 2012-01-30 02:51:40+00:00
State: open

For me its a common use case to synch a local database with a datastore on App Engine and I dont want to use any framework like objectify.

So i need methods to map Datastore Entities to POJOs.

It would be nice to be able to automatically generate something like this and the corresponding static Variables:

public Record(Entity entity) {
try {
this.id = (Long) entity.getProperty(ID);
} catch (ClassCastException e) {}
try {
this.recordTitle = (String) entity.getProperty(TITLE);
} catch (ClassCastException e) {}
try {
this.recordDescription = (String) entity.getProperty(DESCRIPTION);
} catch (ClassCastException e) {}
try {
this.created = (Date) entity.getProperty(CREATED);
} catch (ClassCastException e) {}
try {
this.recordDataBlobStoreKey = (String) entity.getProperty(DATA_BLOB_STORE_KEY);
} catch (ClassCastException e) {}
}

public Entity toDataStoreEntity() {
Entity entity = new Entity(recordEntityName);
entity.setProperty(CREATED, this.created);
entity.setProperty(DESCRIPTION, this.recordDescription);
entity.setProperty(this.recordDataBlobStoreKey, DATA_BLOB_STORE_KEY);
entity.setProperty(this.recordTitle, TITLE);
entity.setProperty(String.valueOf(this.id), ID);
return entity;
}

I could extend the generator myself, if you would just give me some hints about which steps are needed and which classes should be modified to achieve that. I dont want to break your design.

Probably the generator could have a Method generateDatastoreConvinience(), so i could just enable and disable the feature?