Skip to content

Commit a1b984d

Browse files
authored
RealmAny datatype (#7398)
1 parent d9f0695 commit a1b984d

File tree

185 files changed

+10736
-5906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+10736
-5906
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
## 11.0.0 (YYYY-MM-DD)
22

3+
### Breaking Changes
4+
* Queries no longer do nullability checks on non-nullable fields, so using `null` as an argument will not throw an `IllegalArgumentException`.
5+
* String query filters `contains`, `beginsWith`, `endsWith`, and `like`, now throw a null pointer exception on null values.
6+
* The query builder no longer throw `IllegalStateException` but `IllegalArgumentException`.
7+
* The `distinct` query filter on unsupported fields no longer throws an exception when applied through when querying across relationships.
8+
* The `distinct` query filter no longer throws an exception when applied on non-existent fields.
9+
310
### Enhancements
411
* Added support for `java.util.UUID` as supported field in model classes.
512
* Added support for `java.util.UUID` as a primary key.
13+
* Added support for `RealmAny` as supported field in model classes. A `RealmAny` is used to represent a polymorphic Realm value or Realm Object, is indexable but cannot be used as a primary key. See [Javadoc for RealmAny](https://docs.mongodb.com/realm-sdks/java/latest/io/realm/RealmAny.html).
614
* Allow UTF8 encoded characters in property names in string-based queries ([#4467](https://github.com/realm/realm-core/issues/4467))
715
* The error message when the initial steps of opening a Realm file fails is now more descriptive.
816
* Make conversion of Decimal128 to/from string work for numbers with more than 19 significant digits. ([#4548](https://github.com/realm/realm-core/issues/4548))
@@ -11,6 +19,10 @@
1119
a backup, if a) an attempt is made to open a realm file with a "future" file format and b) a backup file exist
1220
that fits the current file format. ([#4166](https://github.com/realm/realm-core/pull/4166))
1321
* Remove type coercion on bool and ObjectId when doing queries.
22+
* Allow passing arguments into string-based query predicates.
23+
* Queries across relationships now support the `between` operator.
24+
* Queries on numerical fields (byte, short, int, long, float, double, decimal128) now accept any numerical value as an argument.
25+
* `isEmpty` query filter can now be applied on `RealmList` and `RealmObject` fields.
1426

1527
### Fixed
1628
* Fix assertion failures such as "!m_notifier_skip_version.version" or "m_notifier_sg->get_version() + 1 == new_version.version" when performing writes inside change notification callbacks. Previously refreshing the Realm by beginning a write transaction would skip delivering notifications, leaving things in an inconsistent state. Notifications are now delivered recursively when needed instead. ([Cocoa #7165](https://github.com/realm/realm-cocoa/issues/7165)).

dependencies.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REALM_CORE=10.3.3
44

55
# Version of MongoDB Realm used by integration tests
66
# See https://github.com/realm/ci/packages/147854 for available versions
7-
MONGODB_REALM_SERVER=2021-03-22
7+
MONGODB_REALM_SERVER=2021-03-29
88

99
# Common Android settings across projects
1010
GRADLE_BUILD_TOOLS=4.0.0

realm-annotations/src/main/java/io/realm/annotations/Required.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* annotation are never allowed to hold {@code null} values even if the datatype would otherwise allow it.
3636
* Realm will throw an exception if you attempt to store null values into a list marked {@code \@Required}.
3737
* <p>
38+
* This annotation cannot be used on a {@code RealmAny}, as the inner value of a RealmAny field is always nullable.
39+
* Realm will throw an exception if you attempt mark a {@code RealmAny} as {@code \@Required}.
40+
* <p>
3841
* Compiling will fail if the {@link Required} annotation is put an a {@code RealmList} containing references to other
3942
* Realm objects.
4043
*/

realm/kotlin-extensions/src/androidTest/kotlin/io/realm/CoroutinesTests.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import io.realm.entities.AllTypes
44
import io.realm.entities.Dog
55
import io.realm.entities.SimpleClass
66
import io.realm.kotlin.*
7-
import io.realm.log.RealmLog
87
import io.realm.rule.BlockingLooperThread
9-
import io.realm.rule.TestRealmConfigurationFactory
108
import kotlinx.coroutines.*
119
import kotlinx.coroutines.flow.*
1210
import kotlinx.coroutines.test.TestCoroutineDispatcher

realm/kotlin-extensions/src/androidTest/kotlin/io/realm/KotlinRealmModelTests.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import io.realm.entities.SimpleClass
77
import io.realm.kotlin.*
88
import io.realm.rule.RunInLooperThread
99
import io.realm.rule.RunTestInLooperThread
10-
import io.realm.rule.TestRealmConfigurationFactory
1110
import org.junit.*
1211
import org.junit.Assert.*
1312
import org.junit.runner.RunWith

realm/kotlin-extensions/src/androidTest/kotlin/io/realm/KotlinRealmQueryTests.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import io.realm.entities.AllPropTypesClass
66
import io.realm.kotlin.createObject
77
import io.realm.kotlin.oneOf
88
import io.realm.kotlin.where
9-
import io.realm.rule.TestRealmConfigurationFactory
109
import org.junit.After
1110
import org.junit.Assert.assertEquals
1211
import org.junit.Before

realm/kotlin-extensions/src/androidTest/kotlin/io/realm/KotlinRealmTests.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.realm.entities.PrimaryKeyClass
55
import io.realm.entities.SimpleClass
66
import io.realm.kotlin.createObject
77
import io.realm.kotlin.where
8-
import io.realm.rule.TestRealmConfigurationFactory
98
import org.junit.After
109
import org.junit.Before
1110
import org.junit.Rule

realm/realm-annotations-processor/src/main/java/io/realm/processor/ClassMetaData.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class ClassMetaData(env: ProcessingEnvironment, typeMirrors: TypeMirrors, privat
8181
typeMirrors.DATE_MIRROR,
8282
typeMirrors.DECIMAL128_MIRROR,
8383
typeMirrors.OBJECT_ID_MIRROR,
84-
typeMirrors.UUID_MIRROR
84+
typeMirrors.UUID_MIRROR,
85+
typeMirrors.MIXED_MIRROR
8586
)
8687
private val stringType = typeMirrors.STRING_MIRROR
8788

@@ -519,10 +520,11 @@ class ClassMetaData(env: ProcessingEnvironment, typeMirrors: TypeMirrors, privat
519520
val hasRequiredAnnotation = hasRequiredAnnotation(field)
520521
val listGenericType = (field.asType() as DeclaredType).typeArguments
521522
val containsRealmModelClasses = (listGenericType.isNotEmpty() && Utils.isRealmModel(listGenericType[0]))
523+
val containsRealmAny = (listGenericType.isNotEmpty() && Utils.isRealmAny(listGenericType[0]))
522524

523525
// @Required not allowed if the list contains Realm model classes
524-
if (hasRequiredAnnotation && containsRealmModelClasses) {
525-
Utils.error("@Required not allowed on RealmList's that contain other Realm model classes.")
526+
if (hasRequiredAnnotation && (containsRealmModelClasses || containsRealmAny)) {
527+
Utils.error("@Required not allowed on RealmList's that contain other Realm model classes or RealmAny.")
526528
return false
527529
}
528530

@@ -568,7 +570,7 @@ class ClassMetaData(env: ProcessingEnvironment, typeMirrors: TypeMirrors, privat
568570

569571
// Standard field that appears to be valid (more fine grained checks might fail later).
570572
fields.add(field)
571-
if (Utils.isRealmModel(field) || Utils.isRealmModelList(field)) {
573+
if (Utils.isRealmModel(field) || Utils.isRealmModelList(field) || Utils.isRealmAnyList(field) || Utils.isRealmAny(field)) {
572574
_objectReferenceFields.add(field)
573575
} else {
574576
basicTypeFields.add(field)
@@ -633,11 +635,11 @@ class ClassMetaData(env: ProcessingEnvironment, typeMirrors: TypeMirrors, privat
633635
}
634636

635637
// The field has the @Index annotation. It's only valid for column types:
636-
// STRING, DATE, INTEGER, BOOLEAN, RealmMutableInteger, OBJECT_ID and UUID
638+
// STRING, DATE, INTEGER, BOOLEAN, RealmMutableInteger, OBJECT_ID, UUID and MIXED
637639
private fun categorizeIndexField(element: Element, fieldElement: RealmFieldElement): Boolean {
638640
var indexable = false
639641

640-
if (Utils.isMutableRealmInteger(fieldElement)) {
642+
if (Utils.isMutableRealmInteger(fieldElement) || Utils.isRealmAny(fieldElement)) {
641643
indexable = true
642644
} else {
643645
when (Constants.JAVA_TO_REALM_TYPES[fieldElement.asType().toString()]) {
@@ -680,6 +682,11 @@ class ClassMetaData(env: ProcessingEnvironment, typeMirrors: TypeMirrors, privat
680682
}
681683
}
682684

685+
if (Utils.isRealmAny(field)) {
686+
Utils.error(String.format(Locale.US, "RealmAny field \"${field}\" cannot be @Required or @NotNull."))
687+
return false
688+
}
689+
683690
// Should never get here - user should remove @Required
684691
if (nullableFields.contains(field)) {
685692
Utils.error(String.format(Locale.US,

realm/realm-annotations-processor/src/main/java/io/realm/processor/Constants.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ object Constants {
6666
"byte[]" to RealmFieldType.BINARY_LIST,
6767
"org.bson.types.Decimal128" to RealmFieldType.DECIMAL128_LIST,
6868
"org.bson.types.ObjectId" to RealmFieldType.OBJECT_ID_LIST,
69-
"java.util.UUID" to RealmFieldType.UUID_LIST
69+
"java.util.UUID" to RealmFieldType.UUID_LIST,
70+
"io.realm.RealmAny" to RealmFieldType.MIXED_LIST
7071
)
7172

7273
/**
@@ -85,6 +86,7 @@ object Constants {
8586
DATE("DATE", "Date"),
8687
BINARY("BINARY", "BinaryByteArray"),
8788
REALM_INTEGER("INTEGER", "Long"),
89+
MIXED("MIXED", "RealmAny"),
8890
OBJECT("OBJECT", "Object"),
8991
LIST("LIST", "List"),
9092
DECIMAL128("DECIMAL128", "Decimal128"),
@@ -102,7 +104,8 @@ object Constants {
102104
DOUBLE_LIST("DOUBLE_LIST", "List"),
103105
DECIMAL128_LIST("DECIMAL128_LIST", "List"),
104106
OBJECT_ID_LIST("OBJECT_ID_LIST", "List"),
105-
UUID_LIST("UUID_LIST", "List");
107+
UUID_LIST("UUID_LIST", "List"),
108+
MIXED_LIST("MIXED_LIST", "List");
106109

107110
/**
108111
* The name of the enum, used in the Java bindings, used to represent the corresponding type.

realm/realm-annotations-processor/src/main/java/io/realm/processor/ModuleMetaData.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,11 @@
1616

1717
package io.realm.processor
1818

19-
import java.util.ArrayList
20-
import java.util.HashMap
21-
import java.util.HashSet
22-
import java.util.LinkedHashMap
23-
import java.util.LinkedHashSet
24-
25-
import javax.lang.model.element.AnnotationMirror
26-
import javax.lang.model.element.AnnotationValue
27-
import javax.lang.model.element.Element
28-
import javax.lang.model.element.ElementKind
29-
import javax.lang.model.element.TypeElement
30-
3119
import io.realm.annotations.RealmModule
3220
import io.realm.annotations.RealmNamingPolicy
3321
import io.realm.processor.nameconverter.NameConverter
22+
import java.util.*
23+
import javax.lang.model.element.*
3424

3525
/**
3626
* Utility class for holding metadata for the Realm modules.

0 commit comments

Comments
 (0)