Skip to content
WonderCsabo edited this page Nov 20, 2014 · 9 revisions

Since AndroidAnnotations 2.7

Thanks to Johan Poirier, you may inject your OrmLite DAOs with the @OrmLiteDao annotation.

Note : The minimum version required of ORMLite is 4.21

The @OrmLiteDao has two mandatory attributes :

  • helper should hold the class of your database helper (which should extend com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper)
  • model should point to the model class that the DAO relates to. It should match the type of the first generic parameter of your Dao

Note : For getting and releasing the helper, we use the OpenHelperManager class, which cannot handle two different helpers at the same time. So if you are using multiple database helpers, be careful with OrmLiteDao annotations.

Usage:

@EActivity
public class MyActivity extends Activity {

	// UserDao is a Dao<User, Long>
	@OrmLiteDao(helper = DatabaseHelper.class, model = User.class)
	UserDao userDao;

	@OrmLiteDao(helper = DatabaseHelper.class, model = Car.class)
	Dao<Car, Long> carDao;

}

The @OrmLiteDao annotation can be used from within all enhanced components.

Since AndroidAnnotations 3.0

Before 3.0, only subclasses of Dao could be annotated with @OrmLiteDao. Now we also handle subclasses of RuntimeExceptionDao

Since AndroidAnnotations 3.1

The parameter model is deprecated since AndroidAnnotations 3.1 because the model class is inferred from the class of the annotated field. The parameter will be removed in a next major version of AndroidAnnotations.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally