GDG Chicago Android

Google Developers Group

How to simplify db layer in android? There is no single answer so lets consider possible solutions.

 

In Android you have several possibilities to store your data: SharedPreferences, file system (Properties, XML, Serialization etc...) and SQLite3 database embedded in
Android.


To work with SQLite3 you need to hand code all operations with db including SQL queries, content providers and code inside app components relat....


Very often you need to implement trivial operations and write duplicated code for CRUD operations.

 

So how to simplify this? How to make your code more readable hence with less machinery mistakes?


The first solutions is to introduce an ORM or alternative to Sqlite3



As ORM you you can use:

ORMLite - Object Relational Mapping Lite (ORM Lite) provides some lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages. It supports a number of
SQL databases using JDBC and also supports Sqlite with native calls to Android
OS database APIs. Documentation about how to configure ORMLite for Android
specifically is available in the manual. This framework follows standard J2EE DAO pattern.

ActiveAndroid - is an active record style ORM (object relational mapper).


Androdb - is an OR-Mapper for Android, it's under development so I'am not sure which principals it follows and which capabilities provides.


As alternative to SQLite3 you can use DB4O  instead


DB4O requires less code and should be easier to use, check it out and see the code difference.

 

Also you can see this http://code.google.com/p/androsql/ it's not an ORM as for me, but you can take from there general concept how to organize your db components.



One more thing which may be useful is SQL-DSL.

 

If you know other solutions/frameworks/approaches just leave a comment there...

Tags: Android, DB, Java, ORM, SQLite

Views: 1140

Reply to This

© 2014   Created by Uki Dominque Lucas.

Badges  |  Report an Issue  |  Terms of Service