OrmLite - shiraji/androidannotations GitHub Wiki

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 one mandatory attribute :

  • helper should hold the class of your database helper (which should extend com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper)

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)
	UserDao userDao;

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

}

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

Before AndroidAnnotations 4.0

In earlier versions of AndroidAnnotations @OrmLiteDao had model as second mandatory attribute. It was required to point to the model class that the DAO relates to. It should match the type of the first generic parameter of your Dao

RuntimeExceptionDao

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.3

It's now possible to inject custom classes that extend from RuntimeExceptionDao. The class requires a constructor that takes a Dao for the Model that should be used.

public class UserRuntimeExceptionDao extends RuntimeExceptionDao<User, Long> {

	public UserRuntimeExceptionDao(Dao<User, Long> dao) {
		super(dao);
	}

}

@EActivity
public class MyActivity extends Activity {

	@OrmLiteDao(helper = DatabaseHelper.class)
	UserRuntimeExceptionDao userDao;

}
⚠️ **GitHub.com Fallback** ⚠️