Skip to content

Commit

Permalink
Update to latests next-major core and remove set support in RealmAny (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech authored Dec 11, 2023
1 parent 8026095 commit 53b90af
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 853 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This release will bump the Realm file format from version 23 to 24. Opening a fi
* Minimum R8: 8.0.34.

### Internal
* None
* Updated to Realm Core 14.0.0-beta, commit 4926641c6cf2948fa494624ee802bb8cbc21387f.


## 1.13.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 @@ -291,7 +291,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 @@ -305,17 +304,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 @@ -349,10 +345,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 @@ -387,7 +379,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 @@ -454,7 +445,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 @@ -500,10 +500,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 @@ -569,8 +565,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 @@ -584,18 +578,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 @@ -758,12 +746,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 @@ -845,9 +827,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 @@ -1927,9 +1906,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 @@ -966,10 +966,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 @@ -1031,8 +1027,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 @@ -1048,18 +1042,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 @@ -1281,13 +1269,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 @@ -1422,10 +1403,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 @@ -1689,9 +1666,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
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 @@ -348,7 +348,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 @@ -376,16 +375,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 @@ -425,18 +414,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

0 comments on commit 53b90af

Please sign in to comment.