Android ORM / JPA
Coming from the server-side, I find it hard to live without ORM (Object-Relational Mapping) such as JPA. Now that I've started writing Android Apps, I set about finding a JPA ORM tool for Android.
Here is a comparison of the tools I found that do ORM and are lightweight enough for use with Android.
|OrmLite||JPA or custom||DAO or Entity||200kb||Open||docs||1yr|
|greenDAO||N/A Codegen||DAO or Entity||<100kb||Apache2||docs|
"DB Ops" refers to how database operations such as persist() and update() are handled. Normally either by a DAO (data access object) or by the entity themselves.
Performance counts - especially since I need to handle large data sets. I don't want to load 3000 records into memory at once when the device only has room to display 10 at a time. Native Android supplies a Cursor to interate large data sets, and some ORM tools provide their own method too.
greenDAO has Query.lazyList() and OrmLite has DAO.iterator(Query) to do this, however Android adapters do not bind to an iterator so a custom adapter would need to be written in any case. There is a thread online that discusses this, however I think I can rig up a something similar to my LazyList for JPA to make this happen.
I've started my project with OrmLite because it is the most mature. Lazy loading query results will need some custom code, but in the long run I think it will be better than polluting my code with column names and SQL hacks.
greenDAO was a good candidate from the performance perspective, but really I want to write my Entities myself so I can add the methods that I need.Android ORM / JPA