AndroidAnnnotations injection framework integration with a third-party framework OrmLite (15th)
(1). Preface:
We have explained how to integrate the AndroidAnnotations framework with the Otto event bus. Today we will start to learn more about the third-party framework integration with the Ormlite database persistence framework. It is mainly used to facilitate database operations.
OrmLite official site: http://ormlite.com/sqlite_java_android_orm.shtml
(2). Usage:
Since AndroidAnnotations2.7, we can use @ OrmLiteDao to annotate the OrmLite DAOs framework.
[Note] the minimum supported version is ORMLite4.21.
@ OrmLiteDao has the following mandatory attribute:
Helper should hold the reference of databasehelper (this class must inherit from com. j256.ormlite. android. apptools. OrmLiteSqliteOpenHelper)
[Note] do not obtain and release the helper. The OpenHelperManager we use cannot process different helpers in the same event at the same time. So if you are using multiple databasehelpers, you need to use the OrmLite Annotation with caution. Example:
@EActivitypublic classMyActivity extends Activity { // UserDao is a Dao
@OrmLiteDao(helper = DatabaseHelper.class) UserDao userDao; @OrmLiteDao(helper = DatabaseHelper.class) Dao
carDao; }
In earlier versions of AndroidAnnotations4.0 and earlier versions of AndroidAnnotations, @ OrmLiteDao has the second mandatory attribute of the model, which is related to the model object of DAO.
(3) exceptions during DAO running:
Since AndroidAnnotations3.0, all DAO subclasses can be annotated using @ OrmLiteDao before version 3.0. Now we can still use the RuntimeExceptionDao subclass for processing.
Since AndroidAnnotations3.3, you can now annotate and extend the subclass from RuntimeExceptionsDao. This class must have a constructor, input, and Dao model. Example:
public classUserRuntimeExceptionDao extends RuntimeExceptionDao
{ public UserRuntimeExceptionDao(Dao
dao) { super(dao); } } @EActivitypublic classMyActivity extends Activity { @OrmLiteDao(helper = DatabaseHelper.class) UserRuntimeExceptionDao userDao; }
At this point, the OrmLite integration for third-party framework integration of AndroidAnnotations has been fully explained.