Skip to content

Commit 84bac76

Browse files
committed
Merge branch 'master' into cm/bug/local-install
2 parents e88532e + 06f87a2 commit 84bac76

24 files changed

Lines changed: 278 additions & 100 deletions

changelog.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
0.84.2
2+
* Fixed a bug making it impossible to read Realms created by iOS if a class contained primary keys (#1703).
3+
* Added Realm.isEmpty().
24
* Fixed bug making it impossible to convert a field to being required during a migration.
35

46
0.84.1
@@ -7,7 +9,7 @@
79
* Updated ProGuard configuration. See documentation https://realm.io/docs/java/latest/#proguard for more details.
810
* Updated Kotlin example to use 1.0.0-beta.
911
* Fixed warnings reported by `lint -Xlint:all` (#1644).
10-
* Fixed a bug where simultaneous opening and closing a Realm on different threads might result in a NullPointerException (#1646).
12+
* Fixed a bug where simultaneous opening and closing a Realm on diffesrent threads might result in a NullPointerException (#1646).
1113
* Fixed a bug which made it possible to externally modify the encryption key in a RealmConfiguration (#1678).
1214

1315
0.84.0

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-XX:MaxPermSize=512m

realm/realm-jni/src/io_realm_internal_Group.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,20 @@ JNIEXPORT jboolean JNICALL Java_io_realm_internal_Group_nativeEquals(
289289
} CATCH_STD()
290290
return false;
291291
}
292+
293+
JNIEXPORT jboolean JNICALL Java_io_realm_internal_Group_nativeIsEmpty(
294+
JNIEnv*, jobject, jlong nativeGroupPtr)
295+
{
296+
Group* grp = G(nativeGroupPtr);
297+
const string table_prefix(TABLE_PREFIX);
298+
const size_t table_prefix_length = table_prefix.length();
299+
300+
for (size_t i = 0; i < grp->size(); ++i) {
301+
ConstTableRef table = grp->get_table(i);
302+
const string table_name = table->get_name();
303+
if (table_name.compare(0, table_prefix_length, table_prefix) == 0 && !table->is_empty()) {
304+
return false;
305+
}
306+
}
307+
return true;
308+
}

realm/realm-jni/src/io_realm_internal_Group.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

realm/realm-jni/src/io_realm_internal_Util.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ using std::string;
2929

3030
// used by logging
3131
int trace_level = 0;
32-
const char *log_tag = "REALM";
32+
const char* log_tag = "REALM";
33+
34+
const char* const TABLE_PREFIX = "class_";
3335

3436
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*)
3537
{
@@ -73,6 +75,12 @@ JNIEXPORT jlong JNICALL Java_io_realm_internal_Util_nativeGetMemUsage(JNIEnv*, j
7375
return GetMemUsage();
7476
}
7577

78+
JNIEXPORT jstring JNICALL Java_io_realm_internal_Util_nativeGetTablePrefix(
79+
JNIEnv* env, jclass)
80+
{
81+
return to_jstring(env, string(TABLE_PREFIX));
82+
}
83+
7684
// -------------------------- Testcases for exception handling
7785

7886
JNIEXPORT jstring JNICALL Java_io_realm_internal_Util_nativeTestcase(

realm/realm-jni/src/io_realm_internal_Util.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

realm/realm-jni/src/io_realm_internal_table.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ JNIEXPORT jlong JNICALL Java_io_realm_internal_Table_nativeSetPrimaryKey(
15881588
try {
15891589
Table* table = TBL(nativeTablePtr);
15901590
Table* pk_table = TBL(nativePrivateKeyTablePtr);
1591-
const char* table_name = table->get_name().data();
1591+
const char* table_name = table->get_name().substr(6).data(); // Remove "class_" prefix
15921592
size_t row_index = pk_table->find_first_string(io_realm_internal_Table_PRIMARY_KEY_CLASS_COLUMN_INDEX, table_name);
15931593

15941594
if (columnName == NULL || env->GetStringLength(columnName) == 0) {
@@ -1627,35 +1627,57 @@ JNIEXPORT jlong JNICALL Java_io_realm_internal_Table_nativeSetPrimaryKey(
16271627
return 0;
16281628
}
16291629

1630-
// Fixes interop issue with Cocoa Realm where the Primary Key table had different types.
1630+
// 1) Fixes interop issue with Cocoa Realm where the Primary Key table had different types.
16311631
// This affects:
16321632
// - All Realms created by Cocoa and used by Realm-android up to 0.80.1
16331633
// - All Realms created by Realm-Android 0.80.1 and below
16341634
// See https://github.com/realm/realm-java/issues/1059
1635-
// This methods converts the old (wrong) table format (string, integer) to the right (string,string) format.
1635+
//
1636+
// 2) Fix interop issue with Cocoa Realm where primary key tables on Cocoa doesn't have the "class_" prefix.
1637+
// This affects:
1638+
// - All Realms created by Cocoa and used by Realm-android up to 0.84.1
1639+
// - All Realms created by Realm-Android 0.84.1 and below
1640+
// See https://github.com/realm/realm-java/issues/1703
1641+
1642+
// This methods converts the old (wrong) table format (string, integer) to the right (string,string) format and strips
1643+
// any class names in the col[0] of their "class_" prefix
16361644
JNIEXPORT void JNICALL Java_io_realm_internal_Table_nativeMigratePrimaryKeyTableIfNeeded
16371645
(JNIEnv*, jobject, jlong groupNativePtr, jlong privateKeyTableNativePtr)
16381646
{
1647+
const size_t CLASS_COLUMN_INDEX = io_realm_internal_Table_PRIMARY_KEY_CLASS_COLUMN_INDEX;
1648+
const size_t FIELD_COLUMN_INDEX = io_realm_internal_Table_PRIMARY_KEY_FIELD_COLUMN_INDEX;
1649+
16391650
Group* group = G(groupNativePtr);
16401651
Table* pk_table = TBL(privateKeyTableNativePtr);
1641-
if (pk_table->get_column_type(io_realm_internal_Table_PRIMARY_KEY_FIELD_COLUMN_INDEX) == type_Int) {
1652+
1653+
// Fix wrong types (string, int) -> (string, string)
1654+
if (pk_table->get_column_type(FIELD_COLUMN_INDEX) == type_Int) {
16421655
StringData tmp_col_name = StringData("tmp_field_name");
16431656
size_t tmp_col_ndx = pk_table->add_column(DataType(type_String), tmp_col_name);
16441657

16451658
// Create tmp string column with field name instead of column index
16461659
size_t number_of_rows = pk_table->size();
16471660
for (size_t row_ndx = 0; row_ndx < number_of_rows; row_ndx++) {
1648-
StringData table_name = pk_table->get_string(io_realm_internal_Table_PRIMARY_KEY_CLASS_COLUMN_INDEX, row_ndx);
1649-
size_t col_ndx = static_cast<size_t>(pk_table->get_int(io_realm_internal_Table_PRIMARY_KEY_FIELD_COLUMN_INDEX, row_ndx));
1661+
StringData table_name = pk_table->get_string(CLASS_COLUMN_INDEX, row_ndx);
1662+
size_t col_ndx = static_cast<size_t>(pk_table->get_int(FIELD_COLUMN_INDEX, row_ndx));
16501663
StringData col_name = group->get_table(table_name)->get_column_name(col_ndx);
16511664
pk_table->set_string(tmp_col_ndx, row_ndx, col_name);
16521665
}
16531666

16541667
// Delete old int column, and rename tmp column to same name
16551668
// The column index for the renamed column will then be the same as the deleted old column
1656-
pk_table->remove_column(io_realm_internal_Table_PRIMARY_KEY_FIELD_COLUMN_INDEX);
1669+
pk_table->remove_column(FIELD_COLUMN_INDEX);
16571670
pk_table->rename_column(pk_table->get_column_index(tmp_col_name), StringData("pk_property"));
16581671
}
1672+
1673+
// If needed remove "class_" prefix from class names
1674+
size_t number_of_rows = pk_table->size();
1675+
for (size_t row_ndx = 0; row_ndx < number_of_rows; row_ndx++) {
1676+
StringData table_name = pk_table->get_string(CLASS_COLUMN_INDEX, row_ndx);
1677+
if (table_name.begins_with("class_")) {
1678+
pk_table->set_string(CLASS_COLUMN_INDEX, row_ndx, table_name.substr(6));
1679+
}
1680+
}
16591681
}
16601682

16611683
JNIEXPORT jboolean JNICALL Java_io_realm_internal_Table_nativeHasSameSchema

realm/realm-jni/src/util.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jclass GetClass(JNIEnv* env, const char* classStr);
136136

137137
// Debug trace
138138
extern int trace_level;
139-
extern const char *log_tag;
139+
extern const char* log_tag;
140140

141141
#if TRACE
142142
#if defined(ANDROID)
@@ -433,7 +433,7 @@ inline bool ColIsNullable(JNIEnv* env, T* pTable, jlong columnIndex)
433433
}
434434

435435
TR_ERR("Expected nullable column type")
436-
ThrowException(env, IllegalArgument, "This filed is not nullable.");
436+
ThrowException(env, IllegalArgument, "This field is not nullable.");
437437
return false;
438438
}
439439

@@ -584,4 +584,6 @@ inline jobject NewFloat(JNIEnv* env, float value)
584584
return env->NewObject(java_lang_float, java_lang_float_init, value);
585585
}
586586

587+
extern const char* const TABLE_PREFIX;
588+
587589
#endif // REALM_JAVA_UTIL_HPP

realm/realm-library/src/androidTest/assets/ios/0.90.4-alltypes-default.realm renamed to realm/realm-library/src/androidTest/assets/0841_annotationtypes.realm

4 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)