@@ -19,6 +19,7 @@ package com.kgurgul.flipper
19
19
import io.realm.RealmConfiguration
20
20
import io.realm.RealmFieldType
21
21
import io.realm.internal.OsList
22
+ import io.realm.internal.OsResults
22
23
import io.realm.internal.OsSharedRealm
23
24
import io.realm.internal.Row
24
25
import java.text.SimpleDateFormat
@@ -27,15 +28,15 @@ import java.util.*
27
28
internal object RealmHelper {
28
29
29
30
private fun getSharedRealm (realmConfiguration : RealmConfiguration ): OsSharedRealm {
30
- return OsSharedRealm .getInstance(realmConfiguration)
31
+ return OsSharedRealm .getInstance(realmConfiguration, OsSharedRealm . VersionID . LIVE )
31
32
}
32
33
33
34
fun getTableNames (realmConfiguration : RealmConfiguration ): List <String > {
34
35
return getSharedRealm(realmConfiguration)
35
36
.use { sharedRealm ->
36
37
val tableNames = mutableListOf<String >()
37
38
for (i in 0 until sharedRealm.size()) {
38
- tableNames.add(sharedRealm.getTableName( i.toInt()) )
39
+ tableNames.add(sharedRealm.tablesNames[ i.toInt()] )
39
40
}
40
41
tableNames
41
42
}
@@ -49,12 +50,13 @@ internal object RealmHelper {
49
50
.use { sharedRealm ->
50
51
val columnNames = mutableListOf<RealmColumnInfo >()
51
52
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)
53
55
columnNames.add(
54
56
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 )
58
60
)
59
61
)
60
62
}
@@ -72,11 +74,12 @@ internal object RealmHelper {
72
74
.use { sharedRealm ->
73
75
val valueList = mutableListOf<List <Any >>()
74
76
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())
77
80
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 ))
80
83
}
81
84
valueList.add(rowValues)
82
85
if (valueList.size == count) {
@@ -90,80 +93,73 @@ internal object RealmHelper {
90
93
fun getRowsCount (realmConfiguration : RealmConfiguration , tableName : String ): Long {
91
94
return getSharedRealm(realmConfiguration)
92
95
.use { sharedRealm ->
93
- sharedRealm.getTable(tableName).size()
96
+ OsResults
97
+ .createFromQuery(sharedRealm, sharedRealm.getTable(tableName).where())
98
+ .size()
94
99
}
95
100
}
96
101
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)) {
99
105
RealmFieldType .INTEGER -> {
100
- if (row.isNull(index )) {
106
+ if (row.isNull(columnKey )) {
101
107
NULL
102
108
} else {
103
- row.getLong(index ).toString()
109
+ row.getLong(columnKey ).toString()
104
110
}
105
111
}
106
112
RealmFieldType .BOOLEAN -> {
107
- if (row.isNull(index )) {
113
+ if (row.isNull(columnKey )) {
108
114
NULL
109
115
} else {
110
- row.getBoolean(index )
116
+ row.getBoolean(columnKey )
111
117
}
112
118
}
113
119
RealmFieldType .STRING -> {
114
- if (row.isNull(index )) {
120
+ if (row.isNull(columnKey )) {
115
121
NULL
116
122
} else {
117
- row.getString(index )
123
+ row.getString(columnKey )
118
124
}
119
125
}
120
126
RealmFieldType .BINARY -> {
121
- if (row.isNull(index )) {
127
+ if (row.isNull(columnKey )) {
122
128
NULL
123
129
} else {
124
- row.getBinaryByteArray(index ).toString()
130
+ row.getBinaryByteArray(columnKey ).toString()
125
131
}
126
132
}
127
133
RealmFieldType .DATE -> {
128
- if (row.isNull(index )) {
134
+ if (row.isNull(columnKey )) {
129
135
NULL
130
136
} else {
131
- formatDate(row.getDate(index ))
137
+ formatDate(row.getDate(columnKey ))
132
138
}
133
139
}
134
140
RealmFieldType .FLOAT -> {
135
- if (row.isNull(index )) {
141
+ if (row.isNull(columnKey )) {
136
142
NULL
137
143
} 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()
144
145
}
145
146
}
146
147
RealmFieldType .DOUBLE -> {
147
- if (row.isNull(index )) {
148
+ if (row.isNull(columnKey )) {
148
149
NULL
149
150
} 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()
156
152
}
157
153
}
158
154
RealmFieldType .OBJECT -> {
159
- if (row.isNullLink(index )) {
155
+ if (row.isNullLink(columnKey )) {
160
156
NULL
161
157
} else {
162
- row.getLink(index ).toString()
158
+ row.getLink(columnKey ).toString()
163
159
}
164
160
}
165
161
RealmFieldType .LIST -> {
166
- formatList(row.getModelList(index ))
162
+ formatList(row.getModelList(columnKey ))
167
163
}
168
164
RealmFieldType .INTEGER_LIST ,
169
165
RealmFieldType .FLOAT_LIST ,
@@ -172,11 +168,11 @@ internal object RealmHelper {
172
168
RealmFieldType .BINARY_LIST ,
173
169
RealmFieldType .DATE_LIST ,
174
170
RealmFieldType .STRING_LIST -> {
175
- if (row.isNullLink(index )) {
171
+ if (row.isNullLink(columnKey )) {
176
172
NULL
177
173
} 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)
180
176
}
181
177
}
182
178
else -> " [FLIPPER_UNKNOWN_VALUE]"
@@ -193,7 +189,7 @@ internal object RealmHelper {
193
189
val size = osList.size()
194
190
sb.append(" {" )
195
191
for (i in 0 until size) {
196
- sb.append(osList.getUncheckedRow(i).index )
192
+ sb.append(osList.getUncheckedRow(i).objectKey )
197
193
sb.append(' ,' )
198
194
}
199
195
if (size > 0 ) {
0 commit comments