-1

I understand why you need a pass a SQLiteDatabase to an annotated method. However, in my case I fail to see a good way to handle this.

I like to abstract the CRUD on a table using a manager class. This class owns the SQLiteHelper instance and also instantiates readable/writable databases. If I use the annotation this means that I have to either instantiate them outside the manager class, or I have to expose another method like this:

Device add(Device device) {
    return add(sqliteHelper.getWritableDatabase(), device);
}

@Transactional
Device add(SQLiteDatabase db, Device device) {
    // ...
    return device;
}

How do you guys use it or what are the best practices?

ndsc
  • 1,173
  • 2
  • 13
  • 22

1 Answers1

0

Using @Transactional looks like syntatic sugar and you could not use it and add the try/finally yourself to achieve the same effect without needing the extra method. http://code.google.com/p/androidannotations/wiki/SQLiteTransactions

I'm assuming for the annotation to work you need to expose this method as public?

Eric Woodruff
  • 6,380
  • 3
  • 36
  • 33
  • The idea is to not have to repeat the code needed to make transactions. However, in the case of AndroidAnnotations this means you will have to supply the SQLiteDatabase as an argument. I can't find a good example of where to instantiate the database's. Ideally I don't want to do this inside the UI classes. – ndsc Jan 25 '14 at 11:47
  • You may need to reevaluate your design. You should push this sql work down to an intent service or something. I exclusively use a ContentProvider for database persistence. – Eric Woodruff Jan 25 '14 at 17:01