Skip to content

Commit

Permalink
[RKOTLIN-1082] Remove RealmObjectId (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb authored May 21, 2024
1 parent b875d7f commit 5c7c2a0
Show file tree
Hide file tree
Showing 58 changed files with 175 additions and 1,608 deletions.
1 change: 1 addition & 0 deletions .github/actions/run-android-device-farm-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ runs:
test_spec_file: test_spec-${{ inputs.app-id }}.yaml
test_spec_type: APPIUM_PYTHON_TEST_SPEC
remote_src: true
timeout: 3600
test_spec: |
version: 0.1
phases:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This release will bump the Realm file format 24. Opening a file with an older fo
### Breaking changes
* Removed property `RealmLog.level`. Log levels can be set with `RealmLog.setLevel`. (Issue [#1691](https://github.com/realm/realm-kotlin/issues/1691) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1038))
* Removed `LogConfiguration`. Log levels and custom loggers can be set with `RealmLog`. (Issue [#1691](https://github.com/realm/realm-kotlin/issues/1691) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1038))
* Removed deprecated `io.realm.kotlin.types.ObjectId`. Use `org.mongodb.kbson.BsonObjectId` or its type alias `org.mongodb.kbson.ObjectId` instead. (Issue [#1749](https://github.com/realm/realm-kotlin/issues/1749) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1082))

### Enhancements
* Support for RealmLists and RealmDictionaries in `RealmAny`. (Issue [#1434](https://github.com/realm/realm-kotlin/issues/1434))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package io.realm.kotlin.benchmarks

import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.RealmUUID
import io.realm.kotlin.types.annotations.PrimaryKey
import org.mongodb.kbson.ObjectId
import kotlin.reflect.KClass

val SCHEMAS = mapOf(
Expand Down Expand Up @@ -76,7 +76,7 @@ class WithPrimaryKey : RealmObject {
var floatField: Float = 3.14f
var doubleField: Double = 1.19840122
var timestampField: RealmInstant = RealmInstant.from(100, 1000)
var objectIdField: ObjectId = ObjectId.create()
var objectIdField: ObjectId = ObjectId()
var uuidField: RealmUUID = RealmUUID.random()
var objectField: WithPrimaryKey? = null
var objectListField: RealmList<Entity1> = realmListOf()
Expand All @@ -90,7 +90,7 @@ class Entity1 : RealmObject {
var floatField: Float = 3.14f
var doubleField: Double = 1.19840122
var timestampField: RealmInstant = RealmInstant.from(100, 1000)
var objectIdField: ObjectId = ObjectId.create()
var objectIdField: ObjectId = ObjectId()
var uuidField: RealmUUID = RealmUUID.random()
var objectField: Entity1? = null
var objectListField: RealmList<Entity1> = realmListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package io.realm.example.kmmsample

import io.realm.kotlin.ext.backlinks
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
import org.mongodb.kbson.ObjectId

// This class is included to make sure the compiler-plugin can handle various type, given the min/max
// version of Kotlin this project is compiled against.
Expand All @@ -43,7 +43,7 @@ class AllTypes : RealmObject {
var doubleField: Double = 0.0
var floatField: Float = 0.0.toFloat()
var realmInstantField: RealmInstant = RealmInstant.MIN
var objectIdField: ObjectId = ObjectId.create()
var objectIdField: ObjectId = ObjectId()
var objectField: AllTypes? = null

// Nullable types
Expand Down Expand Up @@ -81,7 +81,7 @@ class AllTypes : RealmObject {
var floatRealmListNullable: RealmList<Float?> = realmListOf(null)
var realmInstantRealmList: RealmList<RealmInstant> = realmListOf(RealmInstant.MIN)
var realmInstantRealmListNullable: RealmList<RealmInstant?> = realmListOf(null)
var objectIdRealmList: RealmList<ObjectId> = realmListOf(ObjectId.create())
var objectIdRealmList: RealmList<ObjectId> = realmListOf(ObjectId())
var objectIdRealmListNullable: RealmList<ObjectId?> = realmListOf(null)
var objectRealmList: RealmList<AllTypes> = realmListOf()

Expand Down
4 changes: 0 additions & 4 deletions packages/library-base/proguard-rules-consumer-common.pro
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
## Keep Companion classes and class.Companion member of all classes that can be used in our API to
# allow calling realmObjectCompanionOrThrow and realmObjectCompanionOrNull on the classes
-keep class io.realm.kotlin.types.ObjectId$Companion
-keepclassmembers class io.realm.kotlin.types.ObjectId {
io.realm.kotlin.types.ObjectId$Companion Companion;
}
-keep class io.realm.kotlin.types.RealmInstant$Companion
-keepclassmembers class io.realm.kotlin.types.RealmInstant {
io.realm.kotlin.types.RealmInstant$Companion Companion;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import io.realm.kotlin.internal.interop.RealmValue
import io.realm.kotlin.internal.interop.Timestamp
import io.realm.kotlin.internal.interop.ValueType
import io.realm.kotlin.types.BaseRealmObject
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmAny
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmObject
Expand Down Expand Up @@ -99,8 +98,7 @@ public inline fun realmValueToFloat(transport: RealmValue): Float = transport.ge
public inline fun realmValueToDouble(transport: RealmValue): Double = transport.getDouble()
public inline fun realmValueToObjectId(transport: RealmValue): BsonObjectId =
BsonObjectId(transport.getObjectIdBytes())
public inline fun realmValueToRealmObjectId(transport: RealmValue): ObjectId =
ObjectIdImpl(transport.getObjectIdBytes())

public inline fun realmValueToRealmUUID(transport: RealmValue): RealmUUID = RealmUUIDImpl(transport.getUUIDBytes())
@OptIn(ExperimentalUnsignedTypes::class)
public inline fun realmValueToDecimal128(transport: RealmValue): Decimal128 =
Expand Down Expand Up @@ -316,22 +314,7 @@ internal object ObjectIdConverter : PassThroughPublicConverter<BsonObjectId>() {
override inline fun MemTrackingAllocator.toRealmValue(value: BsonObjectId?): RealmValue =
objectIdTransport(value?.toByteArray())
}

// Top level methods to allow inlining from compiler plugin
public inline fun objectIdToRealmObjectId(value: BsonObjectId?): ObjectId? =
value?.let { ObjectIdImpl(it.toByteArray()) }

internal object RealmObjectIdConverter : PassThroughPublicConverter<ObjectId>() {
override inline fun fromRealmValue(realmValue: RealmValue): ObjectId? =
if (realmValue.isNull()) null else realmValueToRealmObjectId(realmValue)

override inline fun MemTrackingAllocator.toRealmValue(value: ObjectId?): RealmValue =
objectIdTransport(value?.let { it as ObjectIdImpl }?.bytes)
}

// Top level methods to allow inlining from compiler plugin
public inline fun realmObjectIdToObjectId(value: ObjectId?): BsonObjectId? =
value?.let { BsonObjectId((it as ObjectIdImpl).bytes) }

internal object RealmUUIDConverter : PassThroughPublicConverter<RealmUUID>() {
override inline fun fromRealmValue(realmValue: RealmValue): RealmUUID? =
Expand Down Expand Up @@ -365,8 +348,6 @@ internal val primitiveTypeConverters: Map<KClass<*>, RealmValueConverter<*>> =
RealmInstant::class to RealmInstantConverter,
RealmInstantImpl::class to RealmInstantConverter,
BsonObjectId::class to ObjectIdConverter,
ObjectId::class to RealmObjectIdConverter,
ObjectIdImpl::class to RealmObjectIdConverter,
RealmUUID::class to RealmUUIDConverter,
RealmUUIDImpl::class to RealmUUIDConverter,
ByteArray::class to ByteArrayConverter,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import io.realm.kotlin.schema.RealmStorageType
import io.realm.kotlin.types.BaseRealmObject
import io.realm.kotlin.types.EmbeddedRealmObject
import io.realm.kotlin.types.MutableRealmInt
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmAny
import io.realm.kotlin.types.RealmDictionary
import io.realm.kotlin.types.RealmInstant
Expand Down Expand Up @@ -212,11 +211,6 @@ internal object RealmObjectHelper {
key,
objectIdTransport(value.toByteArray())
)
is ObjectId -> setValueTransportByKey(
obj,
key,
objectIdTransport((value as ObjectIdImpl).bytes)
)
is RealmUUID -> setValueTransportByKey(obj, key, uuidTransport(value.bytes))
is RealmObjectInterop -> setValueTransportByKey(
obj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ package io.realm.kotlin.internal.schema

import io.realm.kotlin.dynamic.DynamicMutableRealmObject
import io.realm.kotlin.dynamic.DynamicRealmObject
import io.realm.kotlin.internal.ObjectIdImpl
import io.realm.kotlin.internal.RealmAnyImpl
import io.realm.kotlin.internal.RealmInstantImpl
import io.realm.kotlin.internal.RealmUUIDImpl
import io.realm.kotlin.internal.dynamic.DynamicUnmanagedRealmObject
import io.realm.kotlin.internal.interop.PropertyType
import io.realm.kotlin.schema.RealmStorageType
import io.realm.kotlin.types.BaseRealmObject
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmAny
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmUUID
import org.mongodb.kbson.BsonObjectId
import kotlin.reflect.KClass

internal object RealmStorageTypeImpl {
Expand All @@ -56,8 +53,6 @@ internal object RealmStorageTypeImpl {
}

internal fun <T : Any> KClass<T>.realmStorageType(): KClass<*> = when (this) {
ObjectIdImpl::class -> BsonObjectId::class
ObjectId::class -> BsonObjectId::class
RealmUUIDImpl::class -> RealmUUID::class
RealmInstantImpl::class -> RealmInstant::class
DynamicRealmObject::class,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.realm.kotlin.types.annotations

import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmUUID
import org.mongodb.kbson.BsonObjectId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.realm.kotlin.types.RealmUUID
* identify the object.
*
* This annotation applies to the following primitive types: String, Byte, Char,
* Short, Int, Long, [io.realm.kotlin.types.ObjectId], [org.mongodb.kbson.ObjectId] and [RealmUUID],
* Short, Int, Long, [org.mongodb.kbson.ObjectId] and [RealmUUID],
* as well as their nullable variants.
*
* It cannot be applied on a property that also has a [FullText] annotation.
Expand Down
Loading

0 comments on commit 5c7c2a0

Please sign in to comment.