Slide 1

Slide 1 text

greenDao2ObjectBox @kaelaela(Yuichi Maekawa) Work @ CyberAgent Twitter : kaelaela31 Github : kaelaela

Slide 2

Slide 2 text

Agenda ● What is greenDAO and ObjectBox ● How to convert greenDAO to ObjectBox

Slide 3

Slide 3 text

What is greenDAO and ObjectBox ● Made by greenrobot ● SQLite database ● ORM ● Based on code generation

Slide 4

Slide 4 text

● Since 2011 ● ~ v2 :Need to make yourself DAOgenerator ● v3 ~ : Enable annotation ● Latest version is v3.2.1

Slide 5

Slide 5 text

● 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

Slide 6

Slide 6 text

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)

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

● A new database based on greenDAO ● Do not use SQLite ● Pretty fast ● Latest version is v0.9.7(beta)

Slide 9

Slide 9 text

ObjectBox ● Important concept ○ Object(POJO) ○ Box ○ BoxStore(like db) Memo Box Memo object

Slide 10

Slide 10 text

ObjectBox ● Important concept ○ Object(POJO) ○ Box ○ BoxStore(like db) Memo Box

Slide 11

Slide 11 text

ObjectBox ● Important concept ○ Object(POJO) ○ Box ○ BoxStore(like db) Memo Box some Box some Box some Box BoxStore

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

interface box.put(memo); //insert, update box.remove(memo); box.getAll(); box.query().equal(Memo_.content, "test").build().find();

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Good news. Let’s try it.

Slide 17

Slide 17 text

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/" } } }

Slide 18

Slide 18 text

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 }

Slide 19

Slide 19 text

Replace annotations ● File paths are chended org.greenrobot.greendao.annotation > io.objectbox.annotation ● Relpace @ToOne @ToMany annotations with @Relation

Slide 20

Slide 20 text

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; }

Slide 21

Slide 21 text

That’s all. Let’s build!!

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

It is not work yet well. And source code is not public Wait for v1.

Slide 24

Slide 24 text

Sample code https://github.com/kaelaela/greenDAO2ObjectBox

Slide 25

Slide 25 text

See you next version released!