commonMain.io.realm.kotlin.internal.dynamic.DynamicMutableRealmObjectImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of library-base-jvm Show documentation
Show all versions of library-base-jvm Show documentation
Library code for Realm Kotlin. This artifact is not supposed to be consumed directly, but through 'io.realm.kotlin:gradle-plugin:1.11.1' instead.
/*
* Copyright 2022 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.realm.kotlin.internal.dynamic
import io.realm.kotlin.dynamic.DynamicMutableRealmObject
import io.realm.kotlin.internal.RealmObjectHelper
import io.realm.kotlin.types.RealmDictionary
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmSet
import kotlin.reflect.KClass
internal class DynamicMutableRealmObjectImpl : DynamicMutableRealmObject, DynamicRealmObjectImpl() {
override fun getValue(propertyName: String, clazz: KClass): T {
// dynamicGetSingle checks nullability of property, so null pointer check raises appropriate NPE
return RealmObjectHelper.dynamicGet(
this.`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = false,
issueDynamicMutableObject = true
)!!
}
override fun getNullableValue(propertyName: String, clazz: KClass): T? {
return RealmObjectHelper.dynamicGet(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = true,
issueDynamicMutableObject = true
)
}
override fun getObject(propertyName: String): DynamicMutableRealmObject? {
return getNullableValue(propertyName, DynamicMutableRealmObject::class)
}
override fun getValueList(propertyName: String, clazz: KClass): RealmList {
return RealmObjectHelper.dynamicGetList(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = false,
issueDynamicMutableObject = true
).let {
@Suppress("unchecked_cast")
it as RealmList
}
}
override fun getNullableValueList(propertyName: String, clazz: KClass): RealmList {
return RealmObjectHelper.dynamicGetList(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = true,
issueDynamicMutableObject = true
)
}
override fun getObjectList(propertyName: String): RealmList {
return getValueList(propertyName, DynamicMutableRealmObject::class)
}
override fun getValueSet(propertyName: String, clazz: KClass): RealmSet {
return RealmObjectHelper.dynamicGetSet(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = false,
issueDynamicMutableObject = true
).let {
@Suppress("unchecked_cast")
it as RealmSet
}
}
override fun getNullableValueSet(propertyName: String, clazz: KClass): RealmSet {
return RealmObjectHelper.dynamicGetSet(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = true,
issueDynamicMutableObject = true
)
}
override fun getObjectSet(propertyName: String): RealmSet {
return getValueSet(propertyName, DynamicMutableRealmObject::class)
}
override fun getValueDictionary(
propertyName: String,
clazz: KClass,
): RealmDictionary {
return RealmObjectHelper.dynamicGetDictionary(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = false,
issueDynamicMutableObject = true
).let {
@Suppress("unchecked_cast")
it as RealmDictionary
}
}
override fun getNullableValueDictionary(
propertyName: String,
clazz: KClass
): RealmDictionary {
return RealmObjectHelper.dynamicGetDictionary(
`io_realm_kotlin_objectReference`!!,
propertyName,
clazz,
nullable = true,
issueDynamicMutableObject = true
)
}
override fun getObjectDictionary(propertyName: String): RealmDictionary {
return getNullableValueDictionary(propertyName, DynamicMutableRealmObject::class)
}
override fun set(propertyName: String, value: T): DynamicMutableRealmObject {
// `io_realm_kotlin_objectReference` is not null, as DynamicMutableRealmObject are always managed
val reference = this.io_realm_kotlin_objectReference!!
RealmObjectHelper.dynamicSetValue(reference, propertyName, value)
return this
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy