greenDAO2ObjectBox

 greenDAO2ObjectBox

A967476c5855d593710a9a580f6b2aed?s=128

Yuichi Maekawa

February 15, 2017
Tweet

Transcript

  1. 2.
  2. 3.

    What is greenDAO and ObjectBox • Made by greenrobot •

    SQLite database • ORM • Based on code generation
  3. 4.

    • Since 2011 • ~ v2 :Need to make yourself

    DAOgenerator • v3 ~ : Enable annotation • Latest version is v3.2.1
  4. 5.

    • Two Important concept ◦ Schema: create db and make

    all tables and entities ◦ Entity: add properties and relations to POJO • Daos and entiries are generated by DaoGenerator
  5. 6.

    v2 architecture DaoGenerator: generated class. Do not white code. DaoMaster:

    generated class. Use to get settion. DaoSession: generated class. Use to get dao. EntityDao: generated class. CRUD from database. Entity: generated entity(It has getter/setter. Editable)
  6. 7.

    v3 architecture DaoGenerator: generated class. Do not white code. DaoMaster:

    generated class. Use to get settion. DaoSession: generated class. Use to get dao. EntityDao: generated class. CRUD from database. Entity: your entity. Annotate this. And generate code into this.
  7. 8.

    • A new database based on greenDAO • Do not

    use SQLite • Pretty fast • Latest version is v0.9.7(beta)
  8. 11.

    ObjectBox • Important concept ◦ Object(POJO) ◦ Box ◦ BoxStore(like

    db) Memo Box some Box some Box some Box BoxStore
  9. 12.

    v0.9.7(beta) architecture • MyObjectBox: build BoxStore • BoxStore: provide box

    for your object. Likes database. • default.json: crucial ids here. Do not touch. • Memo: your entity. Generated CRUD methods into this. • Memo_: Property class. It is used to access member (ex. Memo_.id)
  10. 14.

    Convert to ObjectBox(from v3) http://greenrobot.org/objectbox/documentation/introduction/ > Have an app with

    greenDAO? DaoCompat is for you! DaoCompat is an compatibility layer that gives you an greenDAO like API for ObjectBox. http://greenrobot.org/news/objectbox-presentation-thank-you/ > For existing apps using greenDAO Easy switch to ObjectBox
  11. 15.

    Convert to ObjectBox(from v3) http://greenrobot.org/objectbox/documentation/introduction/ > Have an app with

    greenDAO? DaoCompat is for you! DaoCompat is an compatibility layer that gives you an greenDAO like API for ObjectBox. http://greenrobot.org/news/objectbox-presentation-thank-you/ > For existing apps using greenDAO Easy switch to ObjectBox
  12. 17.

    Build setting buildscript { repositories { maven { url "http://objectbox.net/beta-repo/"

    } } } dependencies { classpath 'io.objectbox:objectbox-gradle-plugin:0.9.7' } allprojects { repositories { maven { url "http://objectbox.net/beta-repo/" } } }
  13. 18.

    Build setting apply plugin: 'io.objectbox' dependencies { compile 'org.greenrobot:greendao:3.2.0' compile

    'io.objectbox:objectbox-android:0.9.7' compile 'io.objectbox:objectbox-daocompat:0.9.7' } objectbox { daoCompat true }
  14. 20.

    Initialize MyObjectBox in Application @Override public void onCreate() { super.onCreate();

    boxStore = MyObjectBox.builder().androidContext(this).build(); //use to old interface daoSession = new DaoSession(boxStore); } public BoxStore getBoxStore() { return boxStore; } public BoxStore getDaoSession() { return daoSession; }
  15. 22.
  16. 23.