Eight days after the public launch of greenDAO, we are releasing the next preview version of our ORM Mapper for Android. This version brings quite a few new features:
- DaoSession: A concept similar to a Hibernate Session or the persistence context of JPA’s (Java Persistence API) EntityManager. The session cache is not just a plain data cache to improve performance, but also manages object identities. For example, if you load the same entity twice in a query, you will get a single Java object instead of two when using a session cache. This is particular useful for relations pointing to a common set of entities.
- Active entities: A new type of entities that can resolve relations on the fly. Getters and setters for the referenced entities are generated. This is currently available for to-one relations; to-many and many-to-many will follow soon.
- To-one eager loading: To-one relation entities can be loaded within the same SQL SELECT as the base entity. This improves performance alot when you navigate through entities using to-one relations. The interface keeps simple, greenDAO handles left outer joins for you in the background.
- Transaction convenience: DaoSession provides two methods (runInTx and callInTx) to which you pass Runnable or Callable objects. The code inside of Runnable or Callable is executed in a database transaction.
- Date type: A new property type for dates was added, which maps to java.util.Date and a long INTEGER on the database.
- Entity refresh: Resets the values of an existing entity by loading the current database state.
- SQL scripts: Surprisingly, Android does not offer executing of SQL scripts out of the box. Because this comes in handy for several tasks including data import and schema manipulation, we added this feature in greenDAO.
Despite we added some advanced ORM features, greenDAO keeps slim and fast. The APK of the example project is only 34 KByte including the full greenDAO runtime library with unit test base classes. We believe performance and size are crucial features for a mobile ORM framework.
The best way to get started with greenDAO is to download and play around with it. The download includes greenDAO jar files, javadocs, and an example project.
Let us know your thoughts on greenDAO.