commonMain.io.realm.kotlin.internal.dynamic.DynamicRealmObjectImpl.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.DynamicRealmObject
import io.realm.kotlin.internal.RealmObjectHelper
import io.realm.kotlin.internal.RealmObjectInternal
import io.realm.kotlin.internal.RealmObjectReference
import io.realm.kotlin.query.RealmResults
import io.realm.kotlin.types.BaseRealmObject
import io.realm.kotlin.types.RealmDictionary
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmSet
import kotlin.reflect.KClass
public open class DynamicRealmObjectImpl : DynamicRealmObject, RealmObjectInternal {
override val type: String
get() = this.`io_realm_kotlin_objectReference`!!.className
// This should never be null after initialization of a dynamic object, but we currently cannot
// represent that in the type system as we one some code paths construct the Kotlin object
// before having the realm object reference
override var `io_realm_kotlin_objectReference`: RealmObjectReference? =
null
override fun getValue(propertyName: String, clazz: KClass): T {
// dynamicGetSingle checks nullability of property, so null pointer check raises appropriate NPE
return RealmObjectHelper.dynamicGet(
obj = this.`io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = false
)!!
}
override fun getNullableValue(propertyName: String, clazz: KClass): T? {
return RealmObjectHelper.dynamicGet(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = true
)
}
override fun getObject(propertyName: String): DynamicRealmObject? {
return getNullableValue(propertyName, DynamicRealmObject::class)
}
override fun getValueList(propertyName: String, clazz: KClass): RealmList {
return RealmObjectHelper.dynamicGetList(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = false
)
.let {
@Suppress("unchecked_cast")
it as RealmList
}
}
override fun getNullableValueList(
propertyName: String,
clazz: KClass,
): RealmList {
return RealmObjectHelper.dynamicGetList(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = true
)
}
override fun getObjectList(propertyName: String): RealmList {
return getValueList(propertyName, DynamicRealmObject::class)
}
override fun getValueSet(propertyName: String, clazz: KClass): RealmSet {
return RealmObjectHelper.dynamicGetSet(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = false
)
.let {
@Suppress("unchecked_cast")
it as RealmSet
}
}
override fun getNullableValueSet(
propertyName: String,
clazz: KClass,
): RealmSet {
return RealmObjectHelper.dynamicGetSet(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = true
)
}
override fun getObjectSet(propertyName: String): RealmSet {
return getValueSet(propertyName, DynamicRealmObject::class)
}
override fun getValueDictionary(
propertyName: String,
clazz: KClass,
): RealmDictionary {
return RealmObjectHelper.dynamicGetDictionary(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = false
)
.let {
@Suppress("unchecked_cast")
it as RealmDictionary
}
}
override fun getNullableValueDictionary(
propertyName: String,
clazz: KClass,
): RealmDictionary {
return RealmObjectHelper.dynamicGetDictionary(
obj = `io_realm_kotlin_objectReference`!!,
propertyName = propertyName,
clazz = clazz,
nullable = true
)
}
override fun getObjectDictionary(propertyName: String): RealmDictionary {
return getValueDictionary(propertyName, DynamicRealmObject::class)
}
override fun getBacklinks(propertyName: String): RealmResults {
return RealmObjectHelper.dynamicGetBacklinks(
`io_realm_kotlin_objectReference`!!,
propertyName
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy