Ormlite

Kay-Uwe Janssen edited this page Oct 9, 2016 · 15 revisions

This annotation is part of the ormlite plugin.

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;

}

Method based injection

Since AndroidAnnotations 4.0.0

@EActivity
public class MyActivity extends Activity {

  @OrmLiteDao(helper = DatabaseHelper.class)
  void setUserDao(UserDao userDao){
    // do something with userDao
  }

}

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

Before AndroidAnnotations 4.0.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;

}

21/10/2018 The 4.5.2 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.