Saturday, April 14, 2012

ORMLite

After finishing creating everything with generic classes, I was trying to upgrade my design, so that the developer could create multiple tables and relations between them. While documenting, I walked into ORMLite. This is the ORM for SQLite. I found it so easy to use and developer friendly, that I thought of giving it a try.

You can add it very easily to your project - just download the 2 needed jars from ormlite.com (ormlite-core.jar and ormlite-android.jar - version 4.39 at the time of this post) and everything will work like a charm. What you need to do is Annotate your Classes using ORMLite Annotations or javax.persistence Annotations. The next step is to configure a DAO, but for more examples and information use this link.

What got me thinking about ORMLite is the size of it - approximately 250KB. Since I don't really need all the options that ORMLite offers, I started working on my own ORM (very simple one). I created some custom Annotations for my classes, but what I am working now on is dealing with Content Provider, which is mostly used with databases with single tables, and even if you have multiple tables, the most common way to distinguish between them is through URIs. I cannot do this, because I only have the name and number of the tables at run-time, when the Content Provider has already been initialized.

Currently I can create the query for creating a new table, but I don't get the chance to use it. I will write in the future about the solution I found. I hope I will find something better than rawQuery.

The steps I want to follow in the near future are:

  • Update the Content Provider so that it can work with multiple tables 
    • create tables at run-time
    • update the needed URIs used in Content Provider
  • Use C2DM to update the SQLite database. Currently I am only receiving "Hello world" messages from the server. 

1 comment:

  1. Hi Andreea. Please, take a look at the https://github.com/blandware/android-atleap library. It looks like it is the same you plan to implement.

    ReplyDelete