├── settings.gradle ├── android-perf-screenshot.png ├── app ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ ├── colors.xml │ │ │ └── dimens.xml │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── java │ │ └── io │ │ │ └── objectbox │ │ │ └── performanceapp │ │ │ ├── room │ │ │ ├── AppDatabase.java │ │ │ ├── SimpleEntityIndexedDao.java │ │ │ ├── SimpleEntityDao.java │ │ │ ├── SimpleEntity.java │ │ │ ├── SimpleEntityIndexed.java │ │ │ └── RoomPerfTest.java │ │ │ ├── TestType.java │ │ │ ├── greendao │ │ │ ├── DaoSession.java │ │ │ ├── SimpleEntity.java │ │ │ ├── SimpleEntityIndexed.java │ │ │ ├── DaoMaster.java │ │ │ ├── SimpleEntityDao.java │ │ │ ├── SimpleEntityIndexedDao.java │ │ │ └── GreendaoPerfTest.java │ │ │ ├── PerfTest.java │ │ │ ├── realm │ │ │ ├── SimpleEntity.java │ │ │ ├── SimpleEntityIndexed.java │ │ │ └── RealmPerfTest.java │ │ │ ├── RandomValues.java │ │ │ ├── objectbox │ │ │ ├── SimpleEntity.java │ │ │ ├── SimpleEntityIndexed.java │ │ │ └── ObjectBoxPerfTest.java │ │ │ ├── MainActivity.java │ │ │ ├── Benchmark.java │ │ │ └── PerfTestRunner.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle.kts ├── objectbox-models │ └── default.json └── schemas │ └── io.objectbox.performanceapp.room.AppDatabase │ └── 1.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── greenDAO-generator ├── build.gradle └── src │ └── io │ └── objectbox │ └── performanceapp │ └── generator │ └── TestDaoGenerator.java ├── gradle.properties ├── .github └── workflows │ └── gradle.yml ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | include ':greenDAO-generator' 3 | -------------------------------------------------------------------------------- /android-perf-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/android-perf-screenshot.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ObjectBox Performance 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | build/ 7 | /captures 8 | .externalNativeBuild 9 | default.json.bak -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-performance/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /greenDAO-generator/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java-library" 2 | 3 | java { 4 | sourceCompatibility = JavaVersion.VERSION_1_8 5 | targetCompatibility = JavaVersion.VERSION_1_8 6 | } 7 | 8 | sourceSets { 9 | main { 10 | java { 11 | srcDir 'src' 12 | } 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation("org.greenrobot:greendao-generator:3.3.0") 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/room/AppDatabase.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.performanceapp.room; 2 | 3 | import androidx.room.Database; 4 | import androidx.room.RoomDatabase; 5 | 6 | @Database(entities = {SimpleEntity.class, SimpleEntityIndexed.class}, version = 1) 7 | public abstract class AppDatabase extends RoomDatabase { 8 | 9 | public abstract SimpleEntityDao simpleEntityDao(); 10 | 11 | public abstract SimpleEntityIndexedDao simpleEntityIndexedDao(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Java\adt\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | org.gradle.daemon=true 20 | android.useAndroidX=true 21 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | pull_request: 9 | workflow_dispatch: # Allow running manually from web UI 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Check out 18 | uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 19 | 20 | - name: Set up JDK 17 21 | uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 22 | with: 23 | distribution: 'temurin' 24 | java-version: '17' 25 | cache: gradle 26 | 27 | - name: Gradle Info 28 | run: ./gradlew -version 29 | 30 | - name: Build with Gradle 31 | run: ./gradlew build 32 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/room/SimpleEntityIndexedDao.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.performanceapp.room; 2 | 3 | import androidx.room.Dao; 4 | import androidx.room.Delete; 5 | import androidx.room.Insert; 6 | import androidx.room.Query; 7 | import androidx.room.Update; 8 | 9 | import java.util.List; 10 | 11 | @Dao 12 | public interface SimpleEntityIndexedDao { 13 | 14 | @Insert 15 | void insertInTx(List entities); 16 | 17 | @Query("SELECT * FROM simpleentityindexed") 18 | List loadAll(); 19 | 20 | @Update 21 | void updateInTx(List entities); 22 | 23 | @Delete 24 | void deleteInTx(List entities); 25 | 26 | @Query("SELECT * from simpleentityindexed where simpleInt = :value") 27 | List whereSimpleIntEq(int value); 28 | 29 | @Query("SELECT * FROM simpleentityindexed WHERE simpleString = :value") 30 | List whereSimpleStringEq(String value); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/room/SimpleEntityDao.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.performanceapp.room; 2 | 3 | import androidx.room.Dao; 4 | import androidx.room.Delete; 5 | import androidx.room.Insert; 6 | import androidx.room.Query; 7 | import androidx.room.Update; 8 | 9 | import java.util.List; 10 | 11 | @Dao 12 | public interface SimpleEntityDao { 13 | 14 | @Insert 15 | void insertInTx(List entities); 16 | 17 | @Query("SELECT * from simpleentity where id = :id LIMIT 1") 18 | SimpleEntity load(long id); 19 | 20 | @Query("SELECT * FROM simpleentity") 21 | List loadAll(); 22 | 23 | @Update 24 | void updateInTx(List entities); 25 | 26 | @Delete 27 | void deleteInTx(List entities); 28 | 29 | @Query("SELECT * from simpleentity where simpleInt = :value") 30 | List whereSimpleIntEq(int value); 31 | 32 | @Query("SELECT * FROM simpleentity WHERE simpleString = :value") 33 | List whereSimpleStringEq(String value); 34 | 35 | @Query("SELECT COUNT(*) from simpleentity") 36 | int count(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ObjectBox Java Database Performance Benchmarks 2 | 3 | This is an Android app to measure object persistence performance of 4 | - [ObjectBox](/app/src/main/java/io/objectbox/performanceapp/objectbox) 5 | - [Realm](/app/src/main/java/io/objectbox/performanceapp/realm) 6 | - [SQLite using Room](/app/src/main/java/io/objectbox/performanceapp/room) 7 | - [SQLite using greenDAO](/app/src/main/java/io/objectbox/performanceapp/greendao) (deprecated) 8 | 9 | Results are printed on the UI and saved as tab-separated files (`.tvs`) that can be easily imported 10 | into a spreadsheet. The files are located on external storage. 11 | 12 | 13 | 14 | ## How to get good results 15 | 16 | * Tests perform differently when multiple databases are selected: 17 | For comparable results, run only a single database at a time. 18 | * Put the test device into air plane mode to avoid background apps doing sync over the network. 19 | * Screen must be on at all times (e.g. plug the device in). 20 | * Beware of lazy loaded data (e.g. properties on live objects of Realm): 21 | loading objects may seem very fast because no data is actually loaded. 22 | For better comparison it may be necessary to access data (at least once) and combine load and access time to get actual read time. 23 | * We also have written some general notes on [benchmarking on Android](https://greenrobot.org/android/benchmarking-on-android/). -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("io.objectbox") 4 | id("realm-android") 5 | } 6 | 7 | android { 8 | namespace = "io.objectbox.performanceapp" 9 | compileSdk = 34 // Android 14 10 | 11 | buildFeatures { 12 | viewBinding = true 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility = JavaVersion.VERSION_1_8 17 | targetCompatibility = JavaVersion.VERSION_1_8 18 | } 19 | 20 | defaultConfig { 21 | applicationId = "io.objectbox.performanceapp" 22 | minSdk = 19 // Android 4.4 23 | targetSdk = 34 // Android 14 24 | versionCode = 1 25 | versionName = "1.0" 26 | 27 | javaCompileOptions { 28 | annotationProcessorOptions { 29 | arguments(mapOf("room.schemaLocation" to "$projectDir/schemas")) 30 | } 31 | } 32 | } 33 | 34 | buildTypes { 35 | getByName("release") { 36 | isMinifyEnabled = false 37 | proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") 38 | signingConfig = signingConfigs.getByName("debug") 39 | } 40 | create("releaseDebugCert") { 41 | initWith(getByName("release")) 42 | // Just to use without checkjni 43 | signingConfig = signingConfigs.getByName("debug") 44 | } 45 | create("debugJniNoDebug") { 46 | initWith(getByName("debug")) 47 | // Just to use without checkjni 48 | isJniDebuggable = false 49 | } 50 | } 51 | } 52 | 53 | // Print deprecation warnings like Kotlin 54 | tasks.withType(JavaCompile::class).configureEach { 55 | options.isDeprecation = true 56 | } 57 | 58 | dependencies { 59 | implementation("androidx.preference:preference:1.2.1") 60 | implementation("androidx.room:room-runtime:2.6.1") 61 | annotationProcessor("androidx.room:room-compiler:2.6.1") 62 | implementation("org.greenrobot:greendao:3.3.0") 63 | implementation("org.greenrobot:essentials:3.1.0") 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/TestType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp; 18 | 19 | /** 20 | * Created by Markus on 01.10.2016. 21 | */ 22 | public class TestType { 23 | public static final String CRUD = "Basic operations (CRUD)"; 24 | public static final String CRUD_SCALARS = "Basic operations (CRUD) - scalars"; 25 | public static final String CRUD_INDEXED = "Basic operations (CRUD) - indexed"; 26 | public static final String QUERY_STRING = "Query by string"; 27 | public static final String QUERY_STRING_INDEXED = "Query by string - indexed"; 28 | public static final String QUERY_INTEGER = "Query by integer"; 29 | public static final String QUERY_INTEGER_INDEXED = "Query by integer - indexed"; 30 | public static final String QUERY_ID = "Query by ID"; 31 | public static final String QUERY_ID_RANDOM = "Query by ID - random"; 32 | 33 | public static TestType[] ALL = { 34 | new TestType(CRUD, "crud"), 35 | new TestType(CRUD_SCALARS, "crud-scalars"), 36 | new TestType(CRUD_INDEXED, "crud-indexed"), 37 | new TestType(QUERY_STRING, "query-string"), 38 | new TestType(QUERY_STRING_INDEXED, "query-string-indexed"), 39 | new TestType(QUERY_INTEGER, "query-integer"), 40 | new TestType(QUERY_INTEGER_INDEXED, "query-integer-indexed"), 41 | new TestType(QUERY_ID, "query-id"), 42 | new TestType(QUERY_ID_RANDOM, "query-id-random"), 43 | }; 44 | 45 | public final String name; 46 | public final String nameShort; 47 | 48 | public TestType(String name, String nameShort) { 49 | this.name = name; 50 | this.nameShort = nameShort; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return name; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/room/SimpleEntity.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.performanceapp.room; 2 | 3 | import androidx.room.Entity; 4 | import androidx.room.PrimaryKey; 5 | 6 | @Entity 7 | public class SimpleEntity { 8 | 9 | @PrimaryKey 10 | long id; 11 | boolean simpleBoolean; 12 | byte simpleByte; 13 | short simpleShort; 14 | int simpleInt; 15 | long simpleLong; 16 | float simpleFloat; 17 | double simpleDouble; 18 | 19 | String simpleString; 20 | 21 | byte[] simpleByteArray; 22 | 23 | public long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(long id) { 28 | this.id = id; 29 | } 30 | 31 | public boolean getSimpleBoolean() { 32 | return simpleBoolean; 33 | } 34 | 35 | public void setSimpleBoolean(boolean simpleBoolean) { 36 | this.simpleBoolean = simpleBoolean; 37 | } 38 | 39 | public byte getSimpleByte() { 40 | return simpleByte; 41 | } 42 | 43 | public void setSimpleByte(byte simpleByte) { 44 | this.simpleByte = simpleByte; 45 | } 46 | 47 | public short getSimpleShort() { 48 | return simpleShort; 49 | } 50 | 51 | public void setSimpleShort(short simpleShort) { 52 | this.simpleShort = simpleShort; 53 | } 54 | 55 | public int getSimpleInt() { 56 | return simpleInt; 57 | } 58 | 59 | public void setSimpleInt(int simpleInt) { 60 | this.simpleInt = simpleInt; 61 | } 62 | 63 | public long getSimpleLong() { 64 | return simpleLong; 65 | } 66 | 67 | public void setSimpleLong(long simpleLong) { 68 | this.simpleLong = simpleLong; 69 | } 70 | 71 | public float getSimpleFloat() { 72 | return simpleFloat; 73 | } 74 | 75 | public void setSimpleFloat(float simpleFloat) { 76 | this.simpleFloat = simpleFloat; 77 | } 78 | 79 | public double getSimpleDouble() { 80 | return simpleDouble; 81 | } 82 | 83 | public void setSimpleDouble(double simpleDouble) { 84 | this.simpleDouble = simpleDouble; 85 | } 86 | 87 | public String getSimpleString() { 88 | return simpleString; 89 | } 90 | 91 | public void setSimpleString(String simpleString) { 92 | this.simpleString = simpleString; 93 | } 94 | 95 | public byte[] getSimpleByteArray() { 96 | return simpleByteArray; 97 | } 98 | 99 | public void setSimpleByteArray(byte[] simpleByteArray) { 100 | this.simpleByteArray = simpleByteArray; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/greendao/DaoSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.greendao; 18 | 19 | import org.greenrobot.greendao.AbstractDao; 20 | import org.greenrobot.greendao.AbstractDaoSession; 21 | import org.greenrobot.greendao.database.Database; 22 | import org.greenrobot.greendao.identityscope.IdentityScopeType; 23 | import org.greenrobot.greendao.internal.DaoConfig; 24 | 25 | import java.util.Map; 26 | 27 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 28 | 29 | /** 30 | * {@inheritDoc} 31 | * 32 | * @see org.greenrobot.greendao.AbstractDaoSession 33 | */ 34 | public class DaoSession extends AbstractDaoSession { 35 | 36 | private final DaoConfig simpleEntityDaoConfig; 37 | private final DaoConfig simpleEntityIndexedDaoConfig; 38 | 39 | private final SimpleEntityDao simpleEntityDao; 40 | private final SimpleEntityIndexedDao simpleEntityIndexedDao; 41 | 42 | public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> 43 | daoConfigMap) { 44 | super(db); 45 | 46 | simpleEntityDaoConfig = daoConfigMap.get(SimpleEntityDao.class).clone(); 47 | simpleEntityDaoConfig.initIdentityScope(type); 48 | 49 | simpleEntityIndexedDaoConfig = daoConfigMap.get(SimpleEntityIndexedDao.class).clone(); 50 | simpleEntityIndexedDaoConfig.initIdentityScope(type); 51 | 52 | simpleEntityDao = new SimpleEntityDao(simpleEntityDaoConfig, this); 53 | simpleEntityIndexedDao = new SimpleEntityIndexedDao(simpleEntityIndexedDaoConfig, this); 54 | 55 | registerDao(SimpleEntity.class, simpleEntityDao); 56 | registerDao(SimpleEntityIndexed.class, simpleEntityIndexedDao); 57 | } 58 | 59 | public void clear() { 60 | simpleEntityDaoConfig.clearIdentityScope(); 61 | simpleEntityIndexedDaoConfig.clearIdentityScope(); 62 | } 63 | 64 | public SimpleEntityDao getSimpleEntityDao() { 65 | return simpleEntityDao; 66 | } 67 | 68 | public SimpleEntityIndexedDao getSimpleEntityIndexedDao() { 69 | return simpleEntityIndexedDao; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /greenDAO-generator/src/io/objectbox/performanceapp/generator/TestDaoGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.objectbox.performanceapp.generator; 17 | 18 | import org.greenrobot.greendao.generator.DaoGenerator; 19 | import org.greenrobot.greendao.generator.Entity; 20 | import org.greenrobot.greendao.generator.Property.PropertyBuilder; 21 | import org.greenrobot.greendao.generator.Schema; 22 | 23 | /** 24 | * Generates test entities for test project DaoTest. 25 | * 26 | * @author Markus 27 | */ 28 | public class TestDaoGenerator { 29 | 30 | public static void main(String[] args) throws Exception { 31 | TestDaoGenerator testDaoGenerator = new TestDaoGenerator(); 32 | testDaoGenerator.generate(); 33 | } 34 | 35 | private final Schema schema; 36 | 37 | public TestDaoGenerator() { 38 | schema = new Schema(1, "io.objectbox.performanceapp.greendao"); 39 | createSimple("SimpleEntity", false); 40 | createSimple("SimpleEntityIndexed", true); 41 | } 42 | 43 | public void generate() throws Exception { 44 | DaoGenerator daoGenerator = new DaoGenerator(); 45 | String src = "../app/src/main/java/"; 46 | daoGenerator.generateAll(schema, src); 47 | } 48 | 49 | protected void createSimple(String name, boolean indexed) { 50 | Entity notNull = schema.addEntity(name); 51 | notNull.addIdProperty().notNull(); 52 | notNull.addBooleanProperty("simpleBoolean").notNull(); 53 | notNull.addByteProperty("simpleByte").notNull(); 54 | notNull.addShortProperty("simpleShort").notNull(); 55 | PropertyBuilder simpleInt = notNull.addIntProperty("simpleInt").notNull(); 56 | if (indexed) { 57 | simpleInt.index(); 58 | } 59 | notNull.addLongProperty("simpleLong").notNull(); 60 | notNull.addFloatProperty("simpleFloat").notNull(); 61 | notNull.addDoubleProperty("simpleDouble").notNull(); 62 | PropertyBuilder simpleString = notNull.addStringProperty("simpleString"); 63 | if(indexed) { 64 | simpleString.index(); 65 | } 66 | notNull.addByteArrayProperty("simpleByteArray"); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/room/SimpleEntityIndexed.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.performanceapp.room; 2 | 3 | import androidx.room.Entity; 4 | import androidx.room.Index; 5 | import androidx.room.PrimaryKey; 6 | 7 | @Entity(indices = {@Index("simpleInt"), @Index("simpleString")}) 8 | public class SimpleEntityIndexed { 9 | 10 | @PrimaryKey 11 | private long id; 12 | private boolean simpleBoolean; 13 | private byte simpleByte; 14 | private short simpleShort; 15 | // index 16 | private int simpleInt; 17 | private long simpleLong; 18 | private float simpleFloat; 19 | private double simpleDouble; 20 | 21 | // index 22 | private String simpleString; 23 | 24 | private byte[] simpleByteArray; 25 | 26 | public long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(long id) { 31 | this.id = id; 32 | } 33 | 34 | public boolean getSimpleBoolean() { 35 | return simpleBoolean; 36 | } 37 | 38 | public void setSimpleBoolean(boolean simpleBoolean) { 39 | this.simpleBoolean = simpleBoolean; 40 | } 41 | 42 | public byte getSimpleByte() { 43 | return simpleByte; 44 | } 45 | 46 | public void setSimpleByte(byte simpleByte) { 47 | this.simpleByte = simpleByte; 48 | } 49 | 50 | public short getSimpleShort() { 51 | return simpleShort; 52 | } 53 | 54 | public void setSimpleShort(short simpleShort) { 55 | this.simpleShort = simpleShort; 56 | } 57 | 58 | public int getSimpleInt() { 59 | return simpleInt; 60 | } 61 | 62 | public void setSimpleInt(int simpleInt) { 63 | this.simpleInt = simpleInt; 64 | } 65 | 66 | public long getSimpleLong() { 67 | return simpleLong; 68 | } 69 | 70 | public void setSimpleLong(long simpleLong) { 71 | this.simpleLong = simpleLong; 72 | } 73 | 74 | public float getSimpleFloat() { 75 | return simpleFloat; 76 | } 77 | 78 | public void setSimpleFloat(float simpleFloat) { 79 | this.simpleFloat = simpleFloat; 80 | } 81 | 82 | public double getSimpleDouble() { 83 | return simpleDouble; 84 | } 85 | 86 | public void setSimpleDouble(double simpleDouble) { 87 | this.simpleDouble = simpleDouble; 88 | } 89 | 90 | public String getSimpleString() { 91 | return simpleString; 92 | } 93 | 94 | public void setSimpleString(String simpleString) { 95 | this.simpleString = simpleString; 96 | } 97 | 98 | public byte[] getSimpleByteArray() { 99 | return simpleByteArray; 100 | } 101 | 102 | public void setSimpleByteArray(byte[] simpleByteArray) { 103 | this.simpleByteArray = simpleByteArray; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/PerfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp; 18 | 19 | import android.content.Context; 20 | import androidx.annotation.CallSuper; 21 | 22 | import java.util.Random; 23 | 24 | public abstract class PerfTest { 25 | 26 | protected Random random; 27 | protected Context context; 28 | protected PerfTestRunner testRunner; 29 | protected int numberEntities; 30 | protected Benchmark benchmark; 31 | 32 | @CallSuper 33 | public void setUp(Context context, PerfTestRunner testRunner) { 34 | random = new Random(); 35 | this.context = context.getApplicationContext(); 36 | this.testRunner = testRunner; 37 | } 38 | 39 | public void tearDown() { 40 | } 41 | 42 | protected void log(String text) { 43 | testRunner.log(text); 44 | } 45 | 46 | public abstract String name(); 47 | 48 | public abstract void run(TestType type); 49 | 50 | public void setNumberEntities(int numberEntities) { 51 | this.numberEntities = numberEntities; 52 | } 53 | 54 | public void setBenchmark(Benchmark benchmark) { 55 | this.benchmark = benchmark; 56 | } 57 | 58 | protected void startBenchmark(String name) { 59 | benchmark.start(name); 60 | } 61 | 62 | protected void stopBenchmark() { 63 | log(benchmark.stop()); 64 | } 65 | 66 | /** 67 | * Convenience for {@link #startBenchmark(String)} followed by {@link #stopBenchmark()}. 68 | */ 69 | protected void benchmark(String name, Runnable runnable) { 70 | startBenchmark(name); 71 | runnable.run(); 72 | stopBenchmark(); 73 | } 74 | 75 | public String randomString() { 76 | return RandomValues.createRandomString(random, 0, 100); 77 | } 78 | 79 | public byte[] randomBytes() { 80 | int length = random.nextInt(100); 81 | byte[] bytes = new byte[length]; 82 | random.nextBytes(bytes); 83 | return bytes; 84 | } 85 | 86 | public void allTestsComplete() { 87 | } 88 | 89 | protected void assertEntityCount(long size) { 90 | if (size != numberEntities) { 91 | throw new IllegalStateException("Expected " + numberEntities + " but actual number is " + size); 92 | } 93 | } 94 | 95 | protected void assertGreaterOrEqualToNumberOfEntities(long count) { 96 | if (count < numberEntities) { 97 | throw new IllegalStateException("Expected at least " + numberEntities + " but actual number is " + count); 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/realm/SimpleEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.realm; 18 | 19 | import io.realm.RealmObject; 20 | import io.realm.annotations.PrimaryKey; 21 | 22 | public class SimpleEntity extends RealmObject { 23 | 24 | @PrimaryKey 25 | private long id; 26 | private boolean simpleBoolean; 27 | private byte simpleByte; 28 | private short simpleShort; 29 | private int simpleInt; 30 | private long simpleLong; 31 | private float simpleFloat; 32 | private double simpleDouble; 33 | 34 | private String simpleString; 35 | 36 | private byte[] simpleByteArray; 37 | 38 | public SimpleEntity() { 39 | } 40 | 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | public boolean getSimpleBoolean() { 50 | return simpleBoolean; 51 | } 52 | 53 | public void setSimpleBoolean(boolean simpleBoolean) { 54 | this.simpleBoolean = simpleBoolean; 55 | } 56 | 57 | public byte getSimpleByte() { 58 | return simpleByte; 59 | } 60 | 61 | public void setSimpleByte(byte simpleByte) { 62 | this.simpleByte = simpleByte; 63 | } 64 | 65 | public short getSimpleShort() { 66 | return simpleShort; 67 | } 68 | 69 | public void setSimpleShort(short simpleShort) { 70 | this.simpleShort = simpleShort; 71 | } 72 | 73 | public int getSimpleInt() { 74 | return simpleInt; 75 | } 76 | 77 | public void setSimpleInt(int simpleInt) { 78 | this.simpleInt = simpleInt; 79 | } 80 | 81 | public long getSimpleLong() { 82 | return simpleLong; 83 | } 84 | 85 | public void setSimpleLong(long simpleLong) { 86 | this.simpleLong = simpleLong; 87 | } 88 | 89 | public float getSimpleFloat() { 90 | return simpleFloat; 91 | } 92 | 93 | public void setSimpleFloat(float simpleFloat) { 94 | this.simpleFloat = simpleFloat; 95 | } 96 | 97 | public double getSimpleDouble() { 98 | return simpleDouble; 99 | } 100 | 101 | public void setSimpleDouble(double simpleDouble) { 102 | this.simpleDouble = simpleDouble; 103 | } 104 | 105 | public String getSimpleString() { 106 | return simpleString; 107 | } 108 | 109 | public void setSimpleString(String simpleString) { 110 | this.simpleString = simpleString; 111 | } 112 | 113 | 114 | public byte[] getSimpleByteArray() { 115 | return simpleByteArray; 116 | } 117 | 118 | public void setSimpleByteArray(byte[] simpleByteArray) { 119 | this.simpleByteArray = simpleByteArray; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/RandomValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp; 18 | 19 | import java.util.Random; 20 | 21 | /** 22 | * Helper class to generate a pre-determined set of random values (strings/ints) . 23 | */ 24 | public class RandomValues { 25 | 26 | // Fixed seed so we generate the same set of strings every time. 27 | public static final long SEED = -2662502316022774L; 28 | private static final int MIN_LENGTH = 5; 29 | private static final int MAX_LENGTH = 500; 30 | 31 | // limit to a fixed set of chars 32 | private static final char[] CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 33 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 34 | 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 35 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 36 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; 37 | 38 | /** 39 | * Creates the same random sequence of strings. 40 | */ 41 | public static String[] createFixedRandomStrings(int count) { 42 | return createFixedRandomStrings(count, MIN_LENGTH, MAX_LENGTH); 43 | } 44 | 45 | public static String[] createFixedRandomStrings(int count, int minLength, int maxLength) { 46 | String[] strings = new String[count]; 47 | Random random = new Random(SEED); 48 | for (int i = 0; i < count; i++) { 49 | strings[i] = createRandomString(random, minLength, maxLength); 50 | } 51 | return strings; 52 | } 53 | 54 | public static String createRandomString(Random random, int minLength, int maxLength) { 55 | int length = minLength + random.nextInt(maxLength - minLength); 56 | return createRandomString(random, length); 57 | } 58 | 59 | public static String createRandomString(Random random, int length) { 60 | char[] chars = new char[length + 4]; 61 | for (int i = 0; i < length; ) { 62 | int intVal = random.nextInt(); 63 | chars[i++] = CHARS[((intVal & 0xff) % CHARS.length)]; 64 | chars[i++] = CHARS[(((intVal >> 8) & 0xff) % CHARS.length)]; 65 | chars[i++] = CHARS[(((intVal >> 16) & 0xff) % CHARS.length)]; 66 | chars[i++] = CHARS[(((intVal >> 24) & 0xff) % CHARS.length)]; 67 | } 68 | return new String(chars, 0, length); 69 | } 70 | 71 | /** 72 | * Creates the same random sequence of indexes. To be used to select strings by {@link 73 | * #createFixedRandomStrings(int)}. 74 | */ 75 | public static int[] createFixedRandomInts(int count, int maxInt) { 76 | int[] ints = new int[count]; 77 | Random random = new Random(SEED); 78 | for (int i = 0; i < count; i++) { 79 | ints[i] = random.nextInt(maxInt + 1); 80 | } 81 | return ints; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/objectbox/SimpleEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.objectbox; 18 | 19 | import io.objectbox.annotation.Entity; 20 | import io.objectbox.annotation.Id; 21 | 22 | @Entity 23 | public class SimpleEntity { 24 | 25 | @Id 26 | long id; 27 | boolean simpleBoolean; 28 | byte simpleByte; 29 | short simpleShort; 30 | int simpleInt; 31 | long simpleLong; 32 | float simpleFloat; 33 | double simpleDouble; 34 | 35 | String simpleString; 36 | 37 | byte[] simpleByteArray; 38 | 39 | public SimpleEntity() { 40 | } 41 | 42 | public SimpleEntity(long id) { 43 | this.id = id; 44 | } 45 | 46 | public SimpleEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) { 47 | this.id = id; 48 | this.simpleBoolean = simpleBoolean; 49 | this.simpleByte = simpleByte; 50 | this.simpleShort = simpleShort; 51 | this.simpleInt = simpleInt; 52 | this.simpleLong = simpleLong; 53 | this.simpleFloat = simpleFloat; 54 | this.simpleDouble = simpleDouble; 55 | this.simpleString = simpleString; 56 | this.simpleByteArray = simpleByteArray; 57 | } 58 | 59 | public long getId() { 60 | return id; 61 | } 62 | 63 | public void setId(long id) { 64 | this.id = id; 65 | } 66 | 67 | public boolean getSimpleBoolean() { 68 | return simpleBoolean; 69 | } 70 | 71 | public void setSimpleBoolean(boolean simpleBoolean) { 72 | this.simpleBoolean = simpleBoolean; 73 | } 74 | 75 | public byte getSimpleByte() { 76 | return simpleByte; 77 | } 78 | 79 | public void setSimpleByte(byte simpleByte) { 80 | this.simpleByte = simpleByte; 81 | } 82 | 83 | public short getSimpleShort() { 84 | return simpleShort; 85 | } 86 | 87 | public void setSimpleShort(short simpleShort) { 88 | this.simpleShort = simpleShort; 89 | } 90 | 91 | public int getSimpleInt() { 92 | return simpleInt; 93 | } 94 | 95 | public void setSimpleInt(int simpleInt) { 96 | this.simpleInt = simpleInt; 97 | } 98 | 99 | public long getSimpleLong() { 100 | return simpleLong; 101 | } 102 | 103 | public void setSimpleLong(long simpleLong) { 104 | this.simpleLong = simpleLong; 105 | } 106 | 107 | public float getSimpleFloat() { 108 | return simpleFloat; 109 | } 110 | 111 | public void setSimpleFloat(float simpleFloat) { 112 | this.simpleFloat = simpleFloat; 113 | } 114 | 115 | public double getSimpleDouble() { 116 | return simpleDouble; 117 | } 118 | 119 | public void setSimpleDouble(double simpleDouble) { 120 | this.simpleDouble = simpleDouble; 121 | } 122 | 123 | public String getSimpleString() { 124 | return simpleString; 125 | } 126 | 127 | public void setSimpleString(String simpleString) { 128 | this.simpleString = simpleString; 129 | } 130 | 131 | public byte[] getSimpleByteArray() { 132 | return simpleByteArray; 133 | } 134 | 135 | public void setSimpleByteArray(byte[] simpleByteArray) { 136 | this.simpleByteArray = simpleByteArray; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /app/objectbox-models/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:2066508037409008861", 8 | "lastPropertyId": "10:8979168811650087844", 9 | "name": "SimpleEntity", 10 | "properties": [ 11 | { 12 | "id": "1:8357181620038296370", 13 | "name": "id", 14 | "type": 6, 15 | "flags": 1 16 | }, 17 | { 18 | "id": "2:8014957599658721377", 19 | "name": "simpleBoolean", 20 | "type": 1 21 | }, 22 | { 23 | "id": "3:486615229902264705", 24 | "name": "simpleByte", 25 | "type": 2 26 | }, 27 | { 28 | "id": "4:6601224481371519086", 29 | "name": "simpleShort", 30 | "type": 3 31 | }, 32 | { 33 | "id": "5:2118306784392599510", 34 | "name": "simpleInt", 35 | "type": 5 36 | }, 37 | { 38 | "id": "6:5812772956445341632", 39 | "name": "simpleLong", 40 | "type": 6 41 | }, 42 | { 43 | "id": "7:1065418842978193908", 44 | "name": "simpleFloat", 45 | "type": 7 46 | }, 47 | { 48 | "id": "8:7220777031930057031", 49 | "name": "simpleDouble", 50 | "type": 8 51 | }, 52 | { 53 | "id": "9:6669079511137612739", 54 | "name": "simpleString", 55 | "type": 9 56 | }, 57 | { 58 | "id": "10:8979168811650087844", 59 | "name": "simpleByteArray", 60 | "type": 23 61 | } 62 | ], 63 | "relations": [] 64 | }, 65 | { 66 | "id": "2:1960446593108937414", 67 | "lastPropertyId": "10:7622112042154959206", 68 | "name": "SimpleEntityIndexed", 69 | "properties": [ 70 | { 71 | "id": "1:3687894186713655139", 72 | "name": "id", 73 | "type": 6, 74 | "flags": 1 75 | }, 76 | { 77 | "id": "2:744491936175748739", 78 | "name": "simpleBoolean", 79 | "type": 1 80 | }, 81 | { 82 | "id": "3:930101374761292306", 83 | "name": "simpleByte", 84 | "type": 2 85 | }, 86 | { 87 | "id": "4:5019932040401094666", 88 | "name": "simpleShort", 89 | "type": 3 90 | }, 91 | { 92 | "id": "5:9036275660773544260", 93 | "name": "simpleInt", 94 | "indexId": "1:7769255088226738365", 95 | "type": 5, 96 | "flags": 8 97 | }, 98 | { 99 | "id": "6:5133250005110876084", 100 | "name": "simpleLong", 101 | "type": 6 102 | }, 103 | { 104 | "id": "7:7794332651287140849", 105 | "name": "simpleFloat", 106 | "type": 7 107 | }, 108 | { 109 | "id": "8:2875693831440918677", 110 | "name": "simpleDouble", 111 | "type": 8 112 | }, 113 | { 114 | "id": "9:7453429302134663068", 115 | "name": "simpleString", 116 | "indexId": "2:2825443978184014074", 117 | "type": 9, 118 | "flags": 2048 119 | }, 120 | { 121 | "id": "10:7622112042154959206", 122 | "name": "simpleByteArray", 123 | "type": 23 124 | } 125 | ], 126 | "relations": [] 127 | } 128 | ], 129 | "lastEntityId": "2:1960446593108937414", 130 | "lastIndexId": "2:2825443978184014074", 131 | "lastRelationId": "0:0", 132 | "lastSequenceId": "0:0", 133 | "modelVersion": 5, 134 | "modelVersionParserMinimum": 5, 135 | "retiredEntityUids": [], 136 | "retiredIndexUids": [], 137 | "retiredPropertyUids": [], 138 | "retiredRelationUids": [], 139 | "version": 1 140 | } -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/objectbox/SimpleEntityIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.objectbox; 18 | 19 | import io.objectbox.annotation.Entity; 20 | import io.objectbox.annotation.Id; 21 | import io.objectbox.annotation.Index; 22 | 23 | @Entity 24 | public class SimpleEntityIndexed { 25 | 26 | @Id 27 | private long id; 28 | private boolean simpleBoolean; 29 | private byte simpleByte; 30 | private short simpleShort; 31 | @Index 32 | private int simpleInt; 33 | private long simpleLong; 34 | private float simpleFloat; 35 | private double simpleDouble; 36 | 37 | @Index 38 | private String simpleString; 39 | 40 | private byte[] simpleByteArray; 41 | 42 | public SimpleEntityIndexed() { 43 | } 44 | 45 | public SimpleEntityIndexed(long id) { 46 | this.id = id; 47 | } 48 | 49 | public SimpleEntityIndexed(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) { 50 | this.id = id; 51 | this.simpleBoolean = simpleBoolean; 52 | this.simpleByte = simpleByte; 53 | this.simpleShort = simpleShort; 54 | this.simpleInt = simpleInt; 55 | this.simpleLong = simpleLong; 56 | this.simpleFloat = simpleFloat; 57 | this.simpleDouble = simpleDouble; 58 | this.simpleString = simpleString; 59 | this.simpleByteArray = simpleByteArray; 60 | } 61 | 62 | public long getId() { 63 | return id; 64 | } 65 | 66 | public void setId(long id) { 67 | this.id = id; 68 | } 69 | 70 | public boolean getSimpleBoolean() { 71 | return simpleBoolean; 72 | } 73 | 74 | public void setSimpleBoolean(boolean simpleBoolean) { 75 | this.simpleBoolean = simpleBoolean; 76 | } 77 | 78 | public byte getSimpleByte() { 79 | return simpleByte; 80 | } 81 | 82 | public void setSimpleByte(byte simpleByte) { 83 | this.simpleByte = simpleByte; 84 | } 85 | 86 | public short getSimpleShort() { 87 | return simpleShort; 88 | } 89 | 90 | public void setSimpleShort(short simpleShort) { 91 | this.simpleShort = simpleShort; 92 | } 93 | 94 | public int getSimpleInt() { 95 | return simpleInt; 96 | } 97 | 98 | public void setSimpleInt(int simpleInt) { 99 | this.simpleInt = simpleInt; 100 | } 101 | 102 | public long getSimpleLong() { 103 | return simpleLong; 104 | } 105 | 106 | public void setSimpleLong(long simpleLong) { 107 | this.simpleLong = simpleLong; 108 | } 109 | 110 | public float getSimpleFloat() { 111 | return simpleFloat; 112 | } 113 | 114 | public void setSimpleFloat(float simpleFloat) { 115 | this.simpleFloat = simpleFloat; 116 | } 117 | 118 | public double getSimpleDouble() { 119 | return simpleDouble; 120 | } 121 | 122 | public void setSimpleDouble(double simpleDouble) { 123 | this.simpleDouble = simpleDouble; 124 | } 125 | 126 | public String getSimpleString() { 127 | return simpleString; 128 | } 129 | 130 | public void setSimpleString(String simpleString) { 131 | this.simpleString = simpleString; 132 | } 133 | 134 | public byte[] getSimpleByteArray() { 135 | return simpleByteArray; 136 | } 137 | 138 | public void setSimpleByteArray(byte[] simpleByteArray) { 139 | this.simpleByteArray = simpleByteArray; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/realm/SimpleEntityIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.realm; 18 | 19 | import io.realm.RealmObject; 20 | import io.realm.annotations.Index; 21 | import io.realm.annotations.PrimaryKey; 22 | 23 | public class SimpleEntityIndexed extends RealmObject { 24 | 25 | @PrimaryKey 26 | private long id; 27 | private boolean simpleBoolean; 28 | private byte simpleByte; 29 | private short simpleShort; 30 | 31 | @Index 32 | private int simpleInt; 33 | private long simpleLong; 34 | private float simpleFloat; 35 | private double simpleDouble; 36 | 37 | @Index 38 | private String simpleString; 39 | 40 | private byte[] simpleByteArray; 41 | 42 | public SimpleEntityIndexed() { 43 | } 44 | 45 | public SimpleEntityIndexed(long id) { 46 | this.id = id; 47 | } 48 | 49 | public SimpleEntityIndexed(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) { 50 | this.id = id; 51 | this.simpleBoolean = simpleBoolean; 52 | this.simpleByte = simpleByte; 53 | this.simpleShort = simpleShort; 54 | this.simpleInt = simpleInt; 55 | this.simpleLong = simpleLong; 56 | this.simpleFloat = simpleFloat; 57 | this.simpleDouble = simpleDouble; 58 | this.simpleString = simpleString; 59 | this.simpleByteArray = simpleByteArray; 60 | } 61 | 62 | public long getId() { 63 | return id; 64 | } 65 | 66 | public void setId(long id) { 67 | this.id = id; 68 | } 69 | 70 | public boolean getSimpleBoolean() { 71 | return simpleBoolean; 72 | } 73 | 74 | public void setSimpleBoolean(boolean simpleBoolean) { 75 | this.simpleBoolean = simpleBoolean; 76 | } 77 | 78 | public byte getSimpleByte() { 79 | return simpleByte; 80 | } 81 | 82 | public void setSimpleByte(byte simpleByte) { 83 | this.simpleByte = simpleByte; 84 | } 85 | 86 | public short getSimpleShort() { 87 | return simpleShort; 88 | } 89 | 90 | public void setSimpleShort(short simpleShort) { 91 | this.simpleShort = simpleShort; 92 | } 93 | 94 | public int getSimpleInt() { 95 | return simpleInt; 96 | } 97 | 98 | public void setSimpleInt(int simpleInt) { 99 | this.simpleInt = simpleInt; 100 | } 101 | 102 | public long getSimpleLong() { 103 | return simpleLong; 104 | } 105 | 106 | public void setSimpleLong(long simpleLong) { 107 | this.simpleLong = simpleLong; 108 | } 109 | 110 | public float getSimpleFloat() { 111 | return simpleFloat; 112 | } 113 | 114 | public void setSimpleFloat(float simpleFloat) { 115 | this.simpleFloat = simpleFloat; 116 | } 117 | 118 | public double getSimpleDouble() { 119 | return simpleDouble; 120 | } 121 | 122 | public void setSimpleDouble(double simpleDouble) { 123 | this.simpleDouble = simpleDouble; 124 | } 125 | 126 | public String getSimpleString() { 127 | return simpleString; 128 | } 129 | 130 | public void setSimpleString(String simpleString) { 131 | this.simpleString = simpleString; 132 | } 133 | 134 | public byte[] getSimpleByteArray() { 135 | return simpleByteArray; 136 | } 137 | 138 | public void setSimpleByteArray(byte[] simpleByteArray) { 139 | this.simpleByteArray = simpleByteArray; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/greendao/SimpleEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.greendao; 18 | 19 | import org.greenrobot.greendao.annotation.*; 20 | 21 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. 22 | 23 | /** 24 | * Entity mapped to table "SIMPLE_ENTITY". 25 | */ 26 | @Entity 27 | public class SimpleEntity { 28 | 29 | @Id 30 | private long id; 31 | private boolean simpleBoolean; 32 | private byte simpleByte; 33 | private short simpleShort; 34 | private int simpleInt; 35 | private long simpleLong; 36 | private float simpleFloat; 37 | private double simpleDouble; 38 | private String simpleString; 39 | private byte[] simpleByteArray; 40 | 41 | @Generated 42 | public SimpleEntity() { 43 | } 44 | 45 | public SimpleEntity(long id) { 46 | this.id = id; 47 | } 48 | 49 | @Generated 50 | public SimpleEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) { 51 | this.id = id; 52 | this.simpleBoolean = simpleBoolean; 53 | this.simpleByte = simpleByte; 54 | this.simpleShort = simpleShort; 55 | this.simpleInt = simpleInt; 56 | this.simpleLong = simpleLong; 57 | this.simpleFloat = simpleFloat; 58 | this.simpleDouble = simpleDouble; 59 | this.simpleString = simpleString; 60 | this.simpleByteArray = simpleByteArray; 61 | } 62 | 63 | public long getId() { 64 | return id; 65 | } 66 | 67 | public void setId(long id) { 68 | this.id = id; 69 | } 70 | 71 | public boolean getSimpleBoolean() { 72 | return simpleBoolean; 73 | } 74 | 75 | public void setSimpleBoolean(boolean simpleBoolean) { 76 | this.simpleBoolean = simpleBoolean; 77 | } 78 | 79 | public byte getSimpleByte() { 80 | return simpleByte; 81 | } 82 | 83 | public void setSimpleByte(byte simpleByte) { 84 | this.simpleByte = simpleByte; 85 | } 86 | 87 | public short getSimpleShort() { 88 | return simpleShort; 89 | } 90 | 91 | public void setSimpleShort(short simpleShort) { 92 | this.simpleShort = simpleShort; 93 | } 94 | 95 | public int getSimpleInt() { 96 | return simpleInt; 97 | } 98 | 99 | public void setSimpleInt(int simpleInt) { 100 | this.simpleInt = simpleInt; 101 | } 102 | 103 | public long getSimpleLong() { 104 | return simpleLong; 105 | } 106 | 107 | public void setSimpleLong(long simpleLong) { 108 | this.simpleLong = simpleLong; 109 | } 110 | 111 | public float getSimpleFloat() { 112 | return simpleFloat; 113 | } 114 | 115 | public void setSimpleFloat(float simpleFloat) { 116 | this.simpleFloat = simpleFloat; 117 | } 118 | 119 | public double getSimpleDouble() { 120 | return simpleDouble; 121 | } 122 | 123 | public void setSimpleDouble(double simpleDouble) { 124 | this.simpleDouble = simpleDouble; 125 | } 126 | 127 | public String getSimpleString() { 128 | return simpleString; 129 | } 130 | 131 | public void setSimpleString(String simpleString) { 132 | this.simpleString = simpleString; 133 | } 134 | 135 | public byte[] getSimpleByteArray() { 136 | return simpleByteArray; 137 | } 138 | 139 | public void setSimpleByteArray(byte[] simpleByteArray) { 140 | this.simpleByteArray = simpleByteArray; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/greendao/SimpleEntityIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.greendao; 18 | 19 | import org.greenrobot.greendao.annotation.*; 20 | 21 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. 22 | 23 | /** 24 | * Entity mapped to table "SIMPLE_ENTITY_INDEXED". 25 | */ 26 | @Entity 27 | public class SimpleEntityIndexed { 28 | 29 | @Id 30 | private long id; 31 | private boolean simpleBoolean; 32 | private byte simpleByte; 33 | private short simpleShort; 34 | 35 | @Index 36 | private int simpleInt; 37 | private long simpleLong; 38 | private float simpleFloat; 39 | private double simpleDouble; 40 | 41 | @Index 42 | private String simpleString; 43 | private byte[] simpleByteArray; 44 | 45 | @Generated 46 | public SimpleEntityIndexed() { 47 | } 48 | 49 | public SimpleEntityIndexed(long id) { 50 | this.id = id; 51 | } 52 | 53 | @Generated 54 | public SimpleEntityIndexed(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) { 55 | this.id = id; 56 | this.simpleBoolean = simpleBoolean; 57 | this.simpleByte = simpleByte; 58 | this.simpleShort = simpleShort; 59 | this.simpleInt = simpleInt; 60 | this.simpleLong = simpleLong; 61 | this.simpleFloat = simpleFloat; 62 | this.simpleDouble = simpleDouble; 63 | this.simpleString = simpleString; 64 | this.simpleByteArray = simpleByteArray; 65 | } 66 | 67 | public long getId() { 68 | return id; 69 | } 70 | 71 | public void setId(long id) { 72 | this.id = id; 73 | } 74 | 75 | public boolean getSimpleBoolean() { 76 | return simpleBoolean; 77 | } 78 | 79 | public void setSimpleBoolean(boolean simpleBoolean) { 80 | this.simpleBoolean = simpleBoolean; 81 | } 82 | 83 | public byte getSimpleByte() { 84 | return simpleByte; 85 | } 86 | 87 | public void setSimpleByte(byte simpleByte) { 88 | this.simpleByte = simpleByte; 89 | } 90 | 91 | public short getSimpleShort() { 92 | return simpleShort; 93 | } 94 | 95 | public void setSimpleShort(short simpleShort) { 96 | this.simpleShort = simpleShort; 97 | } 98 | 99 | public int getSimpleInt() { 100 | return simpleInt; 101 | } 102 | 103 | public void setSimpleInt(int simpleInt) { 104 | this.simpleInt = simpleInt; 105 | } 106 | 107 | public long getSimpleLong() { 108 | return simpleLong; 109 | } 110 | 111 | public void setSimpleLong(long simpleLong) { 112 | this.simpleLong = simpleLong; 113 | } 114 | 115 | public float getSimpleFloat() { 116 | return simpleFloat; 117 | } 118 | 119 | public void setSimpleFloat(float simpleFloat) { 120 | this.simpleFloat = simpleFloat; 121 | } 122 | 123 | public double getSimpleDouble() { 124 | return simpleDouble; 125 | } 126 | 127 | public void setSimpleDouble(double simpleDouble) { 128 | this.simpleDouble = simpleDouble; 129 | } 130 | 131 | public String getSimpleString() { 132 | return simpleString; 133 | } 134 | 135 | public void setSimpleString(String simpleString) { 136 | this.simpleString = simpleString; 137 | } 138 | 139 | public byte[] getSimpleByteArray() { 140 | return simpleByteArray; 141 | } 142 | 143 | public void setSimpleByteArray(byte[] simpleByteArray) { 144 | this.simpleByteArray = simpleByteArray; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /app/src/main/java/io/objectbox/performanceapp/greendao/DaoMaster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.performanceapp.greendao; 18 | 19 | import android.content.Context; 20 | import android.database.sqlite.SQLiteDatabase; 21 | import android.database.sqlite.SQLiteDatabase.CursorFactory; 22 | import android.util.Log; 23 | 24 | import org.greenrobot.greendao.AbstractDaoMaster; 25 | import org.greenrobot.greendao.database.StandardDatabase; 26 | import org.greenrobot.greendao.database.Database; 27 | import org.greenrobot.greendao.database.DatabaseOpenHelper; 28 | import org.greenrobot.greendao.identityscope.IdentityScopeType; 29 | 30 | 31 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 32 | /** 33 | * Master of DAO (schema version 1): knows all DAOs. 34 | */ 35 | public class DaoMaster extends AbstractDaoMaster { 36 | public static final int SCHEMA_VERSION = 1; 37 | 38 | /** Creates underlying database table using DAOs. */ 39 | public static void createAllTables(Database db, boolean ifNotExists) { 40 | SimpleEntityDao.createTable(db, ifNotExists); 41 | SimpleEntityIndexedDao.createTable(db, ifNotExists); 42 | } 43 | 44 | /** Drops underlying database table using DAOs. */ 45 | public static void dropAllTables(Database db, boolean ifExists) { 46 | SimpleEntityDao.dropTable(db, ifExists); 47 | SimpleEntityIndexedDao.dropTable(db, ifExists); 48 | } 49 | 50 | /** 51 | * WARNING: Drops all table on Upgrade! Use only during development. 52 | * Convenience method using a {@link DevOpenHelper}. 53 | */ 54 | public static DaoSession newDevSession(Context context, String name) { 55 | Database db = new DevOpenHelper(context, name).getWritableDb(); 56 | DaoMaster daoMaster = new DaoMaster(db); 57 | return daoMaster.newSession(); 58 | } 59 | 60 | public DaoMaster(SQLiteDatabase db) { 61 | this(new StandardDatabase(db)); 62 | } 63 | 64 | public DaoMaster(Database db) { 65 | super(db, SCHEMA_VERSION); 66 | registerDaoClass(SimpleEntityDao.class); 67 | registerDaoClass(SimpleEntityIndexedDao.class); 68 | } 69 | 70 | public DaoSession newSession() { 71 | return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); 72 | } 73 | 74 | public DaoSession newSession(IdentityScopeType type) { 75 | return new DaoSession(db, type, daoConfigMap); 76 | } 77 | 78 | /** 79 | * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - 80 | */ 81 | public static abstract class OpenHelper extends DatabaseOpenHelper { 82 | public OpenHelper(Context context, String name) { 83 | super(context, name, SCHEMA_VERSION); 84 | } 85 | 86 | public OpenHelper(Context context, String name, CursorFactory factory) { 87 | super(context, name, factory, SCHEMA_VERSION); 88 | } 89 | 90 | @Override 91 | public void onCreate(Database db) { 92 | Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); 93 | createAllTables(db, false); 94 | } 95 | } 96 | 97 | /** WARNING: Drops all table on Upgrade! Use only during development. */ 98 | public static class DevOpenHelper extends OpenHelper { 99 | public DevOpenHelper(Context context, String name) { 100 | super(context, name); 101 | } 102 | 103 | public DevOpenHelper(Context context, String name, CursorFactory factory) { 104 | super(context, name, factory); 105 | } 106 | 107 | @Override 108 | public void onUpgrade(Database db, int oldVersion, int newVersion) { 109 | Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); 110 | dropAllTables(db, true); 111 | onCreate(db); 112 | } 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 36 | 37 | 45 | 46 | 56 | 57 | 66 | 67 | 75 | 76 | 77 | 86 | 87 | 88 | 98 | 99 | 100 | 112 | 113 |