Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latests next-major core and remove set support in RealmAny #1587

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This release will bump the Realm file format from version 23 to 24. Opening a fi
* Minimum R8: 8.0.34.

### Internal
* Support for RealmLists, RealmSets and RealmDictionaries in `RealmAny`. This is only supported in the local database, Device Sync support will come in a future release. (Issue [#1434](https://github.com/realm/realm-kotlin/issues/1434))
* Updated to Realm Core 14.0.0-beta, commit 4926641c6cf2948fa494624ee802bb8cbc21387f.


## 1.12.1-SNAPSHOT (YYYY-MM-DD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ expect enum class ValueType {
RLM_TYPE_LINK,
RLM_TYPE_UUID,
RLM_TYPE_LIST,
RLM_TYPE_SET,
RLM_TYPE_DICTIONARY,
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ expect object RealmInterop {
isDefault: Boolean
)
fun realm_set_embedded(obj: RealmObjectPointer, key: PropertyKey): RealmObjectPointer
fun realm_set_set(obj: RealmObjectPointer, key: PropertyKey): RealmSetPointer
fun realm_set_list(obj: RealmObjectPointer, key: PropertyKey): RealmListPointer
fun realm_set_dictionary(obj: RealmObjectPointer, key: PropertyKey): RealmMapPointer
fun realm_object_add_int(obj: RealmObjectPointer, key: PropertyKey, value: Long)
Expand All @@ -303,17 +302,14 @@ expect object RealmInterop {
fun realm_get_backlinks(obj: RealmObjectPointer, sourceClassKey: ClassKey, sourcePropertyKey: PropertyKey): RealmResultsPointer
fun realm_list_size(list: RealmListPointer): Long
fun MemAllocator.realm_list_get(list: RealmListPointer, index: Long): RealmValue
fun realm_list_get_set(list: RealmListPointer, index: Long): RealmSetPointer
fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer
fun realm_list_get_dictionary(list: RealmListPointer, index: Long): RealmMapPointer
fun realm_list_add(list: RealmListPointer, index: Long, transport: RealmValue)
fun realm_list_insert_embedded(list: RealmListPointer, index: Long): RealmObjectPointer
// Returns the element previously at the specified position
fun realm_list_set(list: RealmListPointer, index: Long, inputTransport: RealmValue)
fun realm_list_insert_set(list: RealmListPointer, index: Long): RealmSetPointer
fun realm_list_insert_list(list: RealmListPointer, index: Long): RealmListPointer
fun realm_list_insert_dictionary(list: RealmListPointer, index: Long): RealmMapPointer
fun realm_list_set_set(list: RealmListPointer, index: Long): RealmSetPointer
fun realm_list_set_list(list: RealmListPointer, index: Long): RealmListPointer
fun realm_list_set_dictionary(list: RealmListPointer, index: Long): RealmMapPointer

Expand Down Expand Up @@ -347,10 +343,6 @@ expect object RealmInterop {
dictionary: RealmMapPointer,
mapKey: RealmValue
): RealmValue
fun realm_dictionary_find_set(
dictionary: RealmMapPointer,
mapKey: RealmValue
): RealmSetPointer
fun realm_dictionary_find_list(
dictionary: RealmMapPointer,
mapKey: RealmValue
Expand Down Expand Up @@ -385,7 +377,6 @@ expect object RealmInterop {
dictionary: RealmMapPointer,
mapKey: RealmValue
): RealmValue
fun realm_dictionary_insert_set(dictionary: RealmMapPointer, mapKey: RealmValue): RealmSetPointer
fun realm_dictionary_insert_list(dictionary: RealmMapPointer, mapKey: RealmValue): RealmListPointer
fun realm_dictionary_insert_dictionary(dictionary: RealmMapPointer, mapKey: RealmValue): RealmMapPointer
fun realm_dictionary_get_keys(dictionary: RealmMapPointer): RealmResultsPointer
Expand Down Expand Up @@ -452,7 +443,6 @@ expect object RealmInterop {

// FIXME OPTIMIZE Get many
fun MemAllocator.realm_results_get(results: RealmResultsPointer, index: Long): RealmValue
fun realm_results_get_set(results: RealmResultsPointer, index: Long): RealmSetPointer
fun realm_results_get_list(results: RealmResultsPointer, index: Long): RealmListPointer
fun realm_results_get_dictionary(results: RealmResultsPointer, index: Long): RealmMapPointer
fun realm_results_delete_all(results: RealmResultsPointer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ actual object RealmInterop {
return LongPointerWrapper(realmc.realm_set_embedded(obj.cptr(), key.key))
}

actual fun realm_set_set(obj: RealmObjectPointer, key: PropertyKey): RealmSetPointer {
realmc.realm_set_set(obj.cptr(), key.key)
return realm_get_set(obj, key)
}
actual fun realm_set_list(obj: RealmObjectPointer, key: PropertyKey): RealmListPointer {
realmc.realm_set_list(obj.cptr(), key.key)
return realm_get_list(obj, key)
Expand Down Expand Up @@ -565,8 +561,6 @@ actual object RealmInterop {
realmc.realm_list_get(list.cptr(), index, struct)
return RealmValue(struct)
}
actual fun realm_list_get_set(list: RealmListPointer, index: Long): RealmSetPointer =
LongPointerWrapper(realmc.realm_list_get_set(list.cptr(), index))
actual fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer =
LongPointerWrapper(realmc.realm_list_get_list(list.cptr(), index))

Expand All @@ -580,18 +574,12 @@ actual object RealmInterop {
actual fun realm_list_insert_embedded(list: RealmListPointer, index: Long): RealmObjectPointer {
return LongPointerWrapper(realmc.realm_list_insert_embedded(list.cptr(), index))
}
actual fun realm_list_insert_set(list: RealmListPointer, index: Long): RealmSetPointer {
return LongPointerWrapper(realmc.realm_list_insert_set(list.cptr(), index))
}
actual fun realm_list_insert_list(list: RealmListPointer, index: Long): RealmListPointer {
return LongPointerWrapper(realmc.realm_list_insert_list(list.cptr(), index))
}
actual fun realm_list_insert_dictionary(list: RealmListPointer, index: Long): RealmMapPointer {
return LongPointerWrapper(realmc.realm_list_insert_dictionary(list.cptr(), index))
}
actual fun realm_list_set_set(list: RealmListPointer, index: Long): RealmSetPointer {
return LongPointerWrapper(realmc.realm_list_set_set(list.cptr(), index))
}
actual fun realm_list_set_list(list: RealmListPointer, index: Long): RealmListPointer {
return LongPointerWrapper(realmc.realm_list_set_list(list.cptr(), index))
}
Expand Down Expand Up @@ -754,12 +742,6 @@ actual object RealmInterop {
realmc.realm_dictionary_find(dictionary.cptr(), mapKey.value, struct, found)
return RealmValue(struct)
}
actual fun realm_dictionary_find_set(
dictionary: RealmMapPointer,
mapKey: RealmValue
): RealmSetPointer {
return LongPointerWrapper(realmc.realm_dictionary_get_set(dictionary.cptr(), mapKey.value))
}

actual fun realm_dictionary_find_list(
dictionary: RealmMapPointer,
Expand Down Expand Up @@ -841,9 +823,6 @@ actual object RealmInterop {
}
)
}
actual fun realm_dictionary_insert_set(dictionary: RealmMapPointer, mapKey: RealmValue): RealmSetPointer {
return LongPointerWrapper(realmc.realm_dictionary_insert_set(dictionary.cptr(), mapKey.value))
}

actual fun realm_dictionary_insert_list(dictionary: RealmMapPointer, mapKey: RealmValue): RealmListPointer {
return LongPointerWrapper(realmc.realm_dictionary_insert_list(dictionary.cptr(), mapKey.value))
Expand Down Expand Up @@ -1907,9 +1886,6 @@ actual object RealmInterop {
return RealmValue(value)
}

actual fun realm_results_get_set(results: RealmResultsPointer, index: Long): RealmSetPointer =
LongPointerWrapper(realmc.realm_results_get_set(results.cptr(), index))

actual fun realm_results_get_list(results: RealmResultsPointer, index: Long): RealmListPointer =
LongPointerWrapper(realmc.realm_results_get_list(results.cptr(), index))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,6 @@ actual object RealmInterop {
return CPointerWrapper(realm_wrapper.realm_set_embedded(obj.cptr(), key.key))
}

actual fun realm_set_set(obj: RealmObjectPointer, key: PropertyKey): RealmSetPointer {
checkedBooleanResult(realm_wrapper.realm_set_set(obj.cptr(), key.key))
return realm_get_set(obj, key)
}
actual fun realm_set_list(obj: RealmObjectPointer, key: PropertyKey): RealmListPointer {
checkedBooleanResult(realm_wrapper.realm_set_list(obj.cptr(), key.key))
return realm_get_list(obj, key)
Expand Down Expand Up @@ -1029,8 +1025,6 @@ actual object RealmInterop {
return RealmValue(struct)
}

actual fun realm_list_get_set(list: RealmListPointer, index: Long): RealmSetPointer =
CPointerWrapper(realm_wrapper.realm_list_get_set(list.cptr(), index.toULong()))
actual fun realm_list_get_list(list: RealmListPointer, index: Long): RealmListPointer =
CPointerWrapper(realm_wrapper.realm_list_get_list(list.cptr(), index.toULong()))

Expand All @@ -1046,18 +1040,12 @@ actual object RealmInterop {
)
)
}
actual fun realm_list_insert_set(list: RealmListPointer, index: Long): RealmSetPointer {
return CPointerWrapper(realm_wrapper.realm_list_insert_set(list.cptr(), index.toULong()))
}
actual fun realm_list_insert_list(list: RealmListPointer, index: Long): RealmListPointer {
return CPointerWrapper(realm_wrapper.realm_list_insert_list(list.cptr(), index.toULong()))
}
actual fun realm_list_insert_dictionary(list: RealmListPointer, index: Long): RealmMapPointer {
return CPointerWrapper(realm_wrapper.realm_list_insert_dictionary(list.cptr(), index.toULong()))
}
actual fun realm_list_set_set(list: RealmListPointer, index: Long): RealmSetPointer {
return CPointerWrapper(realm_wrapper.realm_list_set_set(list.cptr(), index.toULong()))
}
actual fun realm_list_set_list(list: RealmListPointer, index: Long): RealmListPointer {
return CPointerWrapper(realm_wrapper.realm_list_set_list(list.cptr(), index.toULong()))
}
Expand Down Expand Up @@ -1279,13 +1267,6 @@ actual object RealmInterop {
}
}

actual fun realm_dictionary_find_set(
dictionary: RealmMapPointer,
mapKey: RealmValue
): RealmSetPointer {
return CPointerWrapper(realm_wrapper.realm_dictionary_get_set(dictionary.cptr(), mapKey.value.readValue()))
}

actual fun realm_dictionary_find_list(
dictionary: RealmMapPointer,
mapKey: RealmValue
Expand Down Expand Up @@ -1420,10 +1401,6 @@ actual object RealmInterop {
return RealmValue(outputStruct)
}

actual fun realm_dictionary_insert_set(dictionary: RealmMapPointer, mapKey: RealmValue): RealmSetPointer {
return CPointerWrapper(realm_wrapper.realm_dictionary_insert_set(dictionary.cptr(), mapKey.value.readValue()))
}

actual fun realm_dictionary_insert_list(dictionary: RealmMapPointer, mapKey: RealmValue): RealmListPointer {
return CPointerWrapper(realm_wrapper.realm_dictionary_insert_list(dictionary.cptr(), mapKey.value.readValue()))
}
Expand Down Expand Up @@ -1687,9 +1664,6 @@ actual object RealmInterop {
return RealmValue(value)
}

actual fun realm_results_get_set(results: RealmResultsPointer, index: Long): RealmSetPointer =
CPointerWrapper(realm_wrapper.realm_results_get_set(results.cptr(), index.toULong()))

actual fun realm_results_get_list(results: RealmResultsPointer, index: Long): RealmListPointer =
CPointerWrapper(realm_wrapper.realm_results_get_list(results.cptr(), index.toULong()))

Expand Down
2 changes: 1 addition & 1 deletion packages/external/core
Submodule core updated 383 files
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public fun realmAnyOf(value: Any?): RealmAny? {
is RealmUUID -> RealmAny.create(value)
is RealmObject -> RealmAny.create(value)
is DynamicRealmObject -> RealmAny.create(value)
is Set<*> -> RealmAny.create(value.map { realmAnyOf(it) }.toRealmSet())
is List<*> -> RealmAny.create(value.map { realmAnyOf(it) }.toRealmList())
is Map<*, *> -> RealmAny.create(
value.map { (mapKey, mapValue) ->
Expand All @@ -61,15 +60,6 @@ public fun realmAnyOf(value: Any?): RealmAny? {
}
}

/**
* Create a [RealmAny] containing a [RealmSet] of all arguments wrapped as [RealmAny]s.
* @param values elements of the set.
*
* See [RealmAny.create] for [RealmSet] constraints and examples of usage.
*/
public fun realmAnySetOf(vararg values: Any?): RealmAny =
RealmAny.create(values.map { realmAnyOf(it) }.toRealmSet())

/**
* Create a [RealmAny] containing a [RealmList] of all arguments wrapped as [RealmAny]s.
* @param values elements of the set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.realm.kotlin.internal.interop.RealmQueryArgument
import io.realm.kotlin.internal.interop.RealmQueryArgumentList
import io.realm.kotlin.internal.interop.RealmQueryListArgument
import io.realm.kotlin.internal.interop.RealmQuerySingleArgument
import io.realm.kotlin.internal.interop.RealmSetPointer
import io.realm.kotlin.internal.interop.RealmValue
import io.realm.kotlin.internal.interop.Timestamp
import io.realm.kotlin.internal.interop.ValueType
Expand Down Expand Up @@ -115,7 +114,6 @@ internal inline fun realmValueToRealmAny(
owner: RealmReference,
issueDynamicObject: Boolean,
issueDynamicMutableObject: Boolean,
getSetFunction: () -> RealmSetPointer = { error("Cannot handled embedded sets") },
getListFunction: () -> RealmListPointer = { error("Cannot handled embedded lists") },
getDictionaryFunction: () -> RealmMapPointer = { error("Cannot handled embedded dictionaries") },
): RealmAny? {
Expand Down Expand Up @@ -151,11 +149,6 @@ internal inline fun realmValueToRealmAny(
RealmAny.create(realmObject!! as RealmObject, clazz as KClass<out RealmObject>)
}
}
ValueType.RLM_TYPE_SET -> {
val nativePointer = getSetFunction()
val operator = realmAnySetOperator(mediator, owner, nativePointer, issueDynamicObject, issueDynamicMutableObject)
return RealmAny.create(ManagedRealmSet(parent, nativePointer, operator))
}
ValueType.RLM_TYPE_LIST -> {
val nativePointer = getListFunction()
val operator = realmAnyListOperator(mediator, owner, nativePointer, issueDynamicObject, issueDynamicMutableObject)
Expand All @@ -176,7 +169,6 @@ internal fun <T> MemTrackingAllocator.realmAnyHandler(
value: RealmAny?,
primitiveValueAsRealmValueHandler: (RealmValue) -> T = { throw IllegalArgumentException("Operation not support for primitive values") },
referenceAsRealmAnyHandler: (RealmAny) -> T = { throw IllegalArgumentException("Operation not support for objects") },
setAsRealmAnyHandler: (RealmAny) -> T = { throw IllegalArgumentException("Operation not support for sets") },
listAsRealmAnyHandler: (RealmAny) -> T = { throw IllegalArgumentException("Operation not support for lists") },
dictionaryAsRealmAnyHandler: (RealmAny) -> T = { throw IllegalArgumentException("Operation not support for dictionaries") },
): T {
Expand All @@ -200,10 +192,6 @@ internal fun <T> MemTrackingAllocator.realmAnyHandler(
referenceAsRealmAnyHandler(value)
}

io.realm.kotlin.types.RealmAny.Type.SET -> {
setAsRealmAnyHandler(value)
}

io.realm.kotlin.types.RealmAny.Type.LIST -> {
listAsRealmAnyHandler(value)
}
Expand Down Expand Up @@ -508,7 +496,6 @@ internal inline fun MemTrackingAllocator.realmAnyToRealmValueWithoutImport(value
val objRef = realmObjectToRealmReferenceOrError(value.asRealmObject())
realmObjectTransport(objRef)
}
RealmAny.Type.SET,
RealmAny.Type.LIST,
RealmAny.Type.DICTIONARY ->
throw IllegalArgumentException("Cannot pass unmanaged collections as input argument")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.realm.kotlin.types.RealmDictionary
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.RealmSet
import io.realm.kotlin.types.RealmUUID
import org.mongodb.kbson.BsonObjectId
import org.mongodb.kbson.Decimal128
Expand Down Expand Up @@ -93,8 +92,6 @@ internal class RealmAnyImpl<T : Any> constructor(
return clazz.cast(getValue)
}

override fun asSet(): RealmSet<RealmAny?> = getValue(RealmAny.Type.SET) as RealmSet<RealmAny?>

override fun asList(): RealmList<RealmAny?> =
getValue(RealmAny.Type.LIST) as RealmList<RealmAny?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ internal class RealmAnyListOperator(
transport, null, mediator, realmReference,
issueDynamicObject,
issueDynamicMutableObject,
{ RealmInterop.realm_list_get_set(nativePointer, index.toLong()) },
{ RealmInterop.realm_list_get_list(nativePointer, index.toLong()) },
{ RealmInterop.realm_list_get_dictionary(nativePointer, index.toLong()) }
)
Expand Down Expand Up @@ -369,16 +368,6 @@ internal class RealmAnyListOperator(
realmObjectToRealmReferenceWithImport(obj, mediator, realmReference, updatePolicy, cache)
RealmInterop.realm_list_add(nativePointer, index.toLong(), realmObjectTransport(objRef))
},
setAsRealmAnyHandler = { realmValue ->
val nativePointer = RealmInterop.realm_list_insert_set(nativePointer, index.toLong())
val operator = realmAnySetOperator(
mediator,
realmReference,
nativePointer,
issueDynamicObject, issueDynamicMutableObject
)
operator.addAll(realmValue.asSet(), updatePolicy, cache)
},
listAsRealmAnyHandler = { realmValue ->
val nativePointer = RealmInterop.realm_list_insert_list(nativePointer, index.toLong())
val operator = realmAnyListOperator(
Expand Down Expand Up @@ -418,18 +407,6 @@ internal class RealmAnyListOperator(
realmObjectToRealmReferenceWithImport(realmValue.asRealmObject(), mediator, realmReference, updatePolicy, cache)
RealmInterop.realm_list_set(nativePointer, index.toLong(), realmObjectTransport(objRef))
},
setAsRealmAnyHandler = { realmValue ->
// Have to clear existing elements for core to know if we are updating with a new collection
RealmInterop.realm_list_set(nativePointer, index.toLong(), nullTransport())
val nativePointer = RealmInterop.realm_list_set_set(nativePointer, index.toLong())
val operator = realmAnySetOperator(
mediator,
realmReference,
nativePointer,
issueDynamicObject, issueDynamicMutableObject
)
operator.addAll(realmValue.asSet(), updatePolicy, cache)
},
listAsRealmAnyHandler = { realmValue ->
// Have to clear existing elements for core to know if we are updating with a new collection
RealmInterop.realm_list_set(nativePointer, index.toLong(), nullTransport())
Expand Down
Loading