AndroidAnnnotations injection framework integration with a third-party framework OrmLite (15th)

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.