What is ObjectBox

A few days ago, when I was upgrading EventBus, I saw ObjectBox. Then I checked it and found it was a super fast database. So I integrated it in the project and made some mistakes.

IO / 2 is still fast, sqLite, greenDAO, Room, github.com/objectbox/o… Here are the results of running 200,000 pieces of data on Nut Pro:

Starting tests with 200000 entities at Mon Nov 20 09:35:31 GMT+08:00 2017 ObjectBox Basic operations (CRUD) (1/1) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ObjectBox 1.2.0 - the 2017-10-31 insert: 2635 ms (2006 ms) thread: update: 2577 ms (thread: 2155 ms) load: 1838 ms (thread: 1811 ms) access: 100 ms (thread: 98 ms) delete: 570 ms (thread: 539 ms) Testsdone at Mon Nov 20 09:35:45 GMT+08:00 2017
Starting tests with 200000 entities at Mon Nov 20 09:35:45 GMT+08:00 2017

Realm Basic operations (CRUD) (1/1)
------------------------------
insert: 11395 ms (thread: 10308 ms)
update: 6757 ms (thread: 5998 ms)
load: 11 ms (thread: 4 ms)
access: 6656 ms (thread: 6542 ms)
delete: 2014 ms (thread: 1930 ms)

Tests doneat Mon Nov 20 09:36:17 GMT+08:00 2017 Starting tests with 200000 entities at Mon Nov 20 09:36:17 GMT+08:00 2017 greenDAO Basic operations (CRUD) (1/1) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- SQLite version 3.9.2 insert: 8452 ms (thread: 8172 ms) update: 12213 ms (thread: 11024 ms) load: 9811 ms (thread: 9729 ms) access: 125 ms (thread: 125 ms) delete: 5302 ms (thread: 4721 ms) DB deleted:true

Tests doneat Mon Nov 20 09:36:59 GMT+08:00 2017 Starting tests with 200000 entities at Mon Nov 20 09:36:59 GMT+08:00 2017 Room Basic operations (CRUD) (1/1) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- SQLite version 3.9.2 insert: 9553 ms (thread: 9144 ms) update: 13038 ms (thread: 11900 ms) load: 9398 ms (thread: 9316 ms) access: 119 ms (thread: 115 ms) delete: 6137 ms (thread: 5665 ms) DB deleted:true

Tests done at Mon Nov 20 09:37:43 GMT+08:00 2017
Copy the code

Kotlin: Objectbox.io /documentati… 4 Simple interfaces and easy to use, and can be quickly replaced by greenDAO. 5 Responsive interfaces: Objectbox. IO /documentati… IO /objectbox-1…

Quick access to the

Demo I will not provide, there are multiple official demo for reference: github.com/objectbox/o… These include:

  1. Objectbox-example: Objectbox is used in Java
  2. Objectbox-kotlin-example: objectbox kotlin used
  3. Daocompat – example: that’s rightgreenDAOThe compatible
  4. Objectbox-relation-example: advanced usage, one-to-one, one-to-many, etc

Access is very simple, the official introduction:

Gradle adds dependencies

1 gradle to add the remote warehouse and its name

buildscript {
    ext.objectboxVersion = '1.2.1'
    repositories {
        maven { url "http://objectbox.net/beta-repo/" }
    }
    dependencies {
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
    }
}

allprojects {
    repositories {
        maven { url "http://objectbox.net/beta-repo/"}}}Copy the code

Add add-ins to Gradle app

apply plugin: 'io.objectbox'// Put it after the Android pluginCopy the code

Add dependencies for Gradle app:

debugCompile 'IO. Objectbox: objectbox - android - objectbrowser: 1.2.1'
releaseCompile 'IO. Objectbox: objectbox - android: 1.2.1'
Copy the code

Projects using

Get a BoxStore under Application:

boxStore = MyObjectBox.builder().androidContext(this).build();
Copy the code

3 Then get the Box for add, delete, change and query

Box<Student> box = boxStore.boxFor(Student.class);
Copy the code

4 Add, delete, modify, and query: put, get, remove, and query.

Fill in the pit

Can’t findMyObjectBox

Compile the project and it will be generated automatically

Where is the database stored

The default location in the/data/data/package/files/objectbox/data. The MDB

You can set the save location during BoxStore initialization

How do I use ToMany

ToMany inherits from List and is very handy to use. See this demo: github.com/objectbox/o…

Set the number of queries

Use query.find (long offset, long limit), refer to this issue: github.com/objectbox/o…

Can’t find “libobjectbox. So”

Armeabi is considered outdated by the author, so is only available for Armeabi-V7A and ARM64-V8A, please check your app Settings

upgrade

This basically involves changing the entity class name and the variable name or type in the entity class, simply by using the @uid annotation

Take changing the entity class name as an example:

1 Add an annotation @uid to the entity class you want to change.

[ObjectBox] Starting ObjectBox Processor (debug:false[ObjectBox] UID operationsfor property "LocationEntity.locationTime": [Rename] apply the current UID using @Uid(3939342872662404404L) - [Change/reset] apply a new UID using @Uid(7349095691908173825L)
Copy the code

3 Add a new number to the comment in the error message: @uid (3939342872662404404L) 4 Change your class name and compile

debugging

Configure your Gradle:

dependencies {
    debugCompile "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseCompile "io.objectbox:objectbox-android:$objectboxVersion"
}
Copy the code

Put ‘apply plugin:’ IO. Objectbox ‘on the last line of gradle file

3 Open debugging information in Application:

new AndroidObjectBrowser(boxStore).start(this);
Copy the code

After completing these two steps, there will be an OB notification in the notification bar after compiling and running. Click it to view the database in the mobile browser.

If you view it on your computer, you need to add another step:

4 Run the ADB command on the PC:

adb forward tcp:8090 tcp:8090
Copy the code

So open the http://localhost:8090/index.html can view the database

Here first, have a question can leave a message or the official issue: github.com/objectbox/o…

Cooooooooooooooooooooool!

Finally, thank you very much for reading. If you have any questions, please feel free to comment. Thank you!

Amazing Android development site: Androidcat.com/

Android open source library collection: github.com/XXApple/And…

Sharing is a virtue and a way of life!!

You may say I am a dreamer, but I am not the only one.

Happy share, the more happy ^_^

Welcome to exchange, reprint please indicate the source, thank you!