Skip to content

Commit 4cbfa49

Browse files
committed
New driver for Realm 7+
1 parent 303a19d commit 4cbfa49

File tree

7 files changed

+62
-72
lines changed

7 files changed

+62
-72
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[ ![Download](https://api.bintray.com/packages/kamgurgul/flipper/flipper-realm-android/images/download.svg?version=1.0.0) ](https://bintray.com/kamgurgul/flipper/flipper-realm-android/1.0.0/link)
22

3-
Android Realm driver for [Flipper](https://github.com/facebook/flipper). Driver was
4-
tested with [Realm](https://github.com/realm/realm-java) versions 5.4.+ and 6.+.
3+
Android Realm driver for [Flipper](https://github.com/facebook/flipper).
4+
5+
Because of breaking changes between [Realm](https://github.com/realm/realm-java) versions driver is split into two versions:
6+
* **2.+** for **Realm 7.+**
7+
* **1.+** for **Realm 5.+** and **Realm 6.+**
58

69
Download
710
========
@@ -16,6 +19,11 @@ allprojects {
1619
}
1720
```
1821
* Dependency:
22+
Realm version >= 7 (not published yet):
23+
```kotlin
24+
implementation "com.kgurgul.flipper:flipper-realm-android:2.0.0"
25+
```
26+
Realm version < 7:
1927
```kotlin
2028
implementation "com.kgurgul.flipper:flipper-realm-android:1.0.0"
2129
```

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616

1717
buildscript {
18-
ext.kotlin_version = '1.3.60'
19-
ext.realm_version = '6.0.1'
20-
ext.flipper_version = '0.28.0'
18+
ext.kotlin_version = '1.3.72'
19+
ext.realm_version = '7.0.0'
20+
ext.flipper_version = '0.37.0'
2121
repositories {
2222
google()
2323
jcenter()
2424

2525
}
2626
dependencies {
27-
classpath 'com.android.tools.build:gradle:3.5.2'
27+
classpath 'com.android.tools.build:gradle:3.6.3'
2828
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2929
classpath "io.realm:realm-gradle-plugin:$realm_version"
3030
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'

flipper-realm-android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ apply plugin: 'maven-publish'
2121
apply plugin: 'com.jfrog.bintray'
2222

2323
def packageName = 'com.kgurgul.flipper'
24-
def pluginVersion = '1.0.0'
24+
def pluginVersion = '2.0.0'
2525

2626
Properties properties = new Properties()
2727
if (project.rootProject.file('local.properties').canRead()) {

flipper-realm-android/src/main/java/com/kgurgul/flipper/RealmHelper.kt

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.kgurgul.flipper
1919
import io.realm.RealmConfiguration
2020
import io.realm.RealmFieldType
2121
import io.realm.internal.OsList
22+
import io.realm.internal.OsResults
2223
import io.realm.internal.OsSharedRealm
2324
import io.realm.internal.Row
2425
import java.text.SimpleDateFormat
@@ -27,15 +28,15 @@ import java.util.*
2728
internal object RealmHelper {
2829

2930
private fun getSharedRealm(realmConfiguration: RealmConfiguration): OsSharedRealm {
30-
return OsSharedRealm.getInstance(realmConfiguration)
31+
return OsSharedRealm.getInstance(realmConfiguration, OsSharedRealm.VersionID.LIVE)
3132
}
3233

3334
fun getTableNames(realmConfiguration: RealmConfiguration): List<String> {
3435
return getSharedRealm(realmConfiguration)
3536
.use { sharedRealm ->
3637
val tableNames = mutableListOf<String>()
3738
for (i in 0 until sharedRealm.size()) {
38-
tableNames.add(sharedRealm.getTableName(i.toInt()))
39+
tableNames.add(sharedRealm.tablesNames[i.toInt()])
3940
}
4041
tableNames
4142
}
@@ -49,12 +50,13 @@ internal object RealmHelper {
4950
.use { sharedRealm ->
5051
val columnNames = mutableListOf<RealmColumnInfo>()
5152
val table = sharedRealm.getTable(tableName)
52-
for (i in 0 until table.columnCount) {
53+
for (columnName in table.columnNames) {
54+
val columnKey = table.getColumnKey(columnName)
5355
columnNames.add(
5456
RealmColumnInfo(
55-
table.getColumnName(i),
56-
table.getColumnType(i).name,
57-
table.isColumnNullable(i)
57+
columnName,
58+
table.getColumnType(columnKey).name,
59+
table.isColumnNullable(columnKey)
5860
)
5961
)
6062
}
@@ -72,11 +74,12 @@ internal object RealmHelper {
7274
.use { sharedRealm ->
7375
val valueList = mutableListOf<List<Any>>()
7476
val table = sharedRealm.getTable(tableName)
75-
for (i in start until table.size()) {
76-
val rawCheckedRow = table.getUncheckedRow(i)
77+
val osResults = OsResults.createFromQuery(sharedRealm, table.where())
78+
for (i in start until osResults.size()) {
79+
val uncheckedRow = osResults.getUncheckedRow(i.toInt())
7780
val rowValues = mutableListOf<Any>()
78-
for (j in 0 until rawCheckedRow.columnCount) {
79-
rowValues.add(getRowData(rawCheckedRow, j))
81+
for (columnName in uncheckedRow.columnNames) {
82+
rowValues.add(getRowData(uncheckedRow, columnName))
8083
}
8184
valueList.add(rowValues)
8285
if (valueList.size == count) {
@@ -90,80 +93,73 @@ internal object RealmHelper {
9093
fun getRowsCount(realmConfiguration: RealmConfiguration, tableName: String): Long {
9194
return getSharedRealm(realmConfiguration)
9295
.use { sharedRealm ->
93-
sharedRealm.getTable(tableName).size()
96+
OsResults
97+
.createFromQuery(sharedRealm, sharedRealm.getTable(tableName).where())
98+
.size()
9499
}
95100
}
96101

97-
private fun getRowData(row: Row, index: Long): Any {
98-
return when (row.getColumnType(index)) {
102+
private fun getRowData(row: Row, columnName: String): Any {
103+
val columnKey = row.getColumnKey(columnName)
104+
return when (row.getColumnType(columnKey)) {
99105
RealmFieldType.INTEGER -> {
100-
if (row.isNull(index)) {
106+
if (row.isNull(columnKey)) {
101107
NULL
102108
} else {
103-
row.getLong(index).toString()
109+
row.getLong(columnKey).toString()
104110
}
105111
}
106112
RealmFieldType.BOOLEAN -> {
107-
if (row.isNull(index)) {
113+
if (row.isNull(columnKey)) {
108114
NULL
109115
} else {
110-
row.getBoolean(index)
116+
row.getBoolean(columnKey)
111117
}
112118
}
113119
RealmFieldType.STRING -> {
114-
if (row.isNull(index)) {
120+
if (row.isNull(columnKey)) {
115121
NULL
116122
} else {
117-
row.getString(index)
123+
row.getString(columnKey)
118124
}
119125
}
120126
RealmFieldType.BINARY -> {
121-
if (row.isNull(index)) {
127+
if (row.isNull(columnKey)) {
122128
NULL
123129
} else {
124-
row.getBinaryByteArray(index).toString()
130+
row.getBinaryByteArray(columnKey).toString()
125131
}
126132
}
127133
RealmFieldType.DATE -> {
128-
if (row.isNull(index)) {
134+
if (row.isNull(columnKey)) {
129135
NULL
130136
} else {
131-
formatDate(row.getDate(index))
137+
formatDate(row.getDate(columnKey))
132138
}
133139
}
134140
RealmFieldType.FLOAT -> {
135-
if (row.isNull(index)) {
141+
if (row.isNull(columnKey)) {
136142
NULL
137143
} else {
138-
when (val aFloat = row.getFloat(index)) {
139-
Float.NaN -> "NaN"
140-
Float.POSITIVE_INFINITY -> "Infinity"
141-
Float.NEGATIVE_INFINITY -> "-Infinity"
142-
else -> aFloat.toString()
143-
}
144+
row.getFloat(columnKey).toString()
144145
}
145146
}
146147
RealmFieldType.DOUBLE -> {
147-
if (row.isNull(index)) {
148+
if (row.isNull(columnKey)) {
148149
NULL
149150
} else {
150-
when (val aDouble = row.getDouble(index)) {
151-
Double.NaN -> "NaN"
152-
Double.POSITIVE_INFINITY -> "Infinity"
153-
Double.NEGATIVE_INFINITY -> "-Infinity"
154-
else -> aDouble.toString()
155-
}
151+
row.getDouble(columnKey).toString()
156152
}
157153
}
158154
RealmFieldType.OBJECT -> {
159-
if (row.isNullLink(index)) {
155+
if (row.isNullLink(columnKey)) {
160156
NULL
161157
} else {
162-
row.getLink(index).toString()
158+
row.getLink(columnKey).toString()
163159
}
164160
}
165161
RealmFieldType.LIST -> {
166-
formatList(row.getModelList(index))
162+
formatList(row.getModelList(columnKey))
167163
}
168164
RealmFieldType.INTEGER_LIST,
169165
RealmFieldType.FLOAT_LIST,
@@ -172,11 +168,11 @@ internal object RealmHelper {
172168
RealmFieldType.BINARY_LIST,
173169
RealmFieldType.DATE_LIST,
174170
RealmFieldType.STRING_LIST -> {
175-
if (row.isNullLink(index)) {
171+
if (row.isNullLink(columnKey)) {
176172
NULL
177173
} else {
178-
val columnType = row.getColumnType(index)
179-
formatValueList(row.getValueList(index, columnType), columnType)
174+
val columnType = row.getColumnType(columnKey)
175+
formatValueList(row.getValueList(columnKey, columnType), columnType)
180176
}
181177
}
182178
else -> "[FLIPPER_UNKNOWN_VALUE]"
@@ -193,7 +189,7 @@ internal object RealmHelper {
193189
val size = osList.size()
194190
sb.append("{")
195191
for (i in 0 until size) {
196-
sb.append(osList.getUncheckedRow(i).index)
192+
sb.append(osList.getUncheckedRow(i).objectKey)
197193
sb.append(',')
198194
}
199195
if (size > 0) {
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
1-
#
2-
# Copyright 2019 KG Soft
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-
#Sat Nov 16 17:32:03 CET 2019
1+
#Wed May 27 15:43:27 CEST 2020
172
distributionBase=GRADLE_USER_HOME
183
distributionPath=wrapper/dists
194
zipStoreBase=GRADLE_USER_HOME
205
zipStorePath=wrapper/dists
21-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

sample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ dependencies {
4343
implementation fileTree(dir: 'libs', include: ['*.jar'])
4444
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4545
implementation 'androidx.appcompat:appcompat:1.1.0'
46-
implementation 'androidx.core:core-ktx:1.1.0'
46+
implementation 'androidx.core:core-ktx:1.2.0'
4747
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4848

49-
debugImplementation 'com.facebook.flipper:flipper:0.28.0'
50-
debugImplementation 'com.facebook.soloader:soloader:0.8.0'
49+
debugImplementation "com.facebook.flipper:flipper:$flipper_version"
50+
debugImplementation 'com.facebook.soloader:soloader:0.8.2'
5151

5252
releaseImplementation 'com.facebook.flipper:flipper-noop:0.28.0'
5353

sample/src/main/java/com/kgurgul/flipper/realm/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class App : Application() {
3333
override fun onCreate() {
3434
super.onCreate()
3535

36+
SoLoader.init(this, false)
37+
3638
Realm.init(this)
3739
val realmConfiguration = RealmConfiguration.Builder()
3840
.name("testRealm")
@@ -41,7 +43,6 @@ class App : Application() {
4143
.build()
4244
Realm.setDefaultConfiguration(realmConfiguration)
4345

44-
SoLoader.init(this, false)
4546
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {
4647
val client = AndroidFlipperClient.getInstance(this)
4748
client.addPlugin(InspectorFlipperPlugin(this, DescriptorMapping.withDefaults()))

0 commit comments

Comments
 (0)