Skip to content

Commit

Permalink
Experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Jul 10, 2024
1 parent 17e92c2 commit 4ace62d
Show file tree
Hide file tree
Showing 24 changed files with 840 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ expect object RealmInterop {
fun realm_config_set_automatic_backlink_handling(config: RealmConfigurationPointer, enabled: Boolean)
fun realm_config_set_data_initialization_function(config: RealmConfigurationPointer, callback: DataInitializationCallback)
fun realm_config_set_in_memory(config: RealmConfigurationPointer, inMemory: Boolean)
fun realm_config_set_relaxed_schema(config: RealmConfigurationPointer, relaxedSchema: Boolean)
fun realm_schema_validate(schema: RealmSchemaPointer, mode: SchemaValidationMode): Boolean

fun realm_create_scheduler(): RealmSchedulerPointer
Expand Down Expand Up @@ -299,12 +300,21 @@ expect object RealmInterop {
fun realm_get_col_key(realm: RealmPointer, classKey: ClassKey, col: String): PropertyKey

fun MemAllocator.realm_get_value(obj: RealmObjectPointer, key: PropertyKey): RealmValue
fun MemAllocator.realm_get_value_by_name(obj: RealmObjectPointer, name: String): RealmValue
fun realm_set_value(
obj: RealmObjectPointer,
key: PropertyKey,
value: RealmValue,
isDefault: Boolean
)
fun realm_set_value_by_name(
obj: RealmObjectPointer,
name: String,
value: RealmValue,
)
fun realm_has_property(obj: RealmObjectPointer, name: String): Boolean
fun realm_get_additional_properties(obj: RealmObjectPointer): List<String>
fun realm_erase_property(obj: RealmObjectPointer, key: String): Boolean
fun realm_set_embedded(obj: RealmObjectPointer, key: PropertyKey): RealmObjectPointer
fun realm_set_list(obj: RealmObjectPointer, key: PropertyKey): RealmListPointer
fun realm_set_dictionary(obj: RealmObjectPointer, key: PropertyKey): RealmMapPointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ actual object RealmInterop {
realmc.realm_config_set_in_memory(config.cptr(), inMemory)
}

actual fun realm_config_set_relaxed_schema(config: RealmConfigurationPointer, relaxedSchema: Boolean) {
realmc.realm_config_set_flexible_schema(config.cptr(), relaxedSchema)
}

actual fun realm_create_scheduler(): RealmSchedulerPointer =
LongPointerWrapper(realmc.realm_create_generic_scheduler())

Expand Down Expand Up @@ -489,6 +493,15 @@ actual object RealmInterop {
return RealmValue(struct)
}

actual fun MemAllocator.realm_get_value_by_name(
obj: RealmObjectPointer,
name: String,
): RealmValue {
val struct = allocRealmValueT()
realmc.realm_get_value_by_name((obj as LongPointerWrapper).ptr, name, struct)
return RealmValue(struct)
}

actual fun realm_set_value(
obj: RealmObjectPointer,
key: PropertyKey,
Expand All @@ -498,6 +511,29 @@ actual object RealmInterop {
realmc.realm_set_value(obj.cptr(), key.key, value.value, isDefault)
}

actual fun realm_set_value_by_name(
obj: RealmObjectPointer,
name: String,
value: RealmValue,
) {
realmc.realm_set_value_by_name(obj.cptr(), name, value.value)
}

actual fun realm_has_property(obj: RealmObjectPointer, name: String): Boolean {
val found = BooleanArray(1)
realmc.realm_has_property(obj.cptr(), name, found)
return found[0]
}

actual fun realm_get_additional_properties(obj: RealmObjectPointer): List<String> {
@Suppress("UNCHECKED_CAST")
val properties = realmc.realm_get_additional_properties_helper(obj.cptr()) as Array<String>

Check failure on line 530 in packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

View workflow job for this annotation

GitHub Actions / static-analysis / ktlint

Unnecessary long whitespace (no-multi-spaces)
return properties.asList()
}
actual fun realm_erase_property(obj: RealmObjectPointer, key: String): Boolean {
return realmc.realm_erase_property(obj.cptr(), key)
}

actual fun realm_set_embedded(obj: RealmObjectPointer, key: PropertyKey): RealmObjectPointer {
return LongPointerWrapper(realmc.realm_set_embedded(obj.cptr(), key.key))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/external/core
Submodule core updated 241 files
2 changes: 1 addition & 1 deletion packages/jni-swig-stub/realm.i
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ import static io.realm.kotlin.internal.interop.realm_errno_e.*;
bool* erased, bool* out_erased, bool* did_refresh, bool* did_run,
bool* found, bool* out_collection_was_cleared, bool* did_compact,
bool* collection_was_cleared, bool* out_collection_was_deleted,
bool* out_was_deleted};
bool* out_was_deleted, bool* out_has_property };

// uint64_t output parameter for realm_get_num_versions
%apply int64_t* OUTPUT { uint64_t* out_versions_count };
Expand Down
22 changes: 22 additions & 0 deletions packages/jni-swig-stub/src/main/jni/realm_api_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,3 +1403,25 @@ jobjectArray realm_get_log_category_names() {

return array;
}

jobjectArray realm_get_additional_properties_helper(realm_object_t* obj) {
JNIEnv* env = get_env(true);

size_t count = 0;
realm_get_additional_properties(obj, nullptr, 0xffffff, &count);

const char** properties = new const char*[count];
realm_get_additional_properties(obj, properties, count, &count);
// FIXME Guard count != count

auto array = env->NewObjectArray(count, JavaClassGlobalDef::java_lang_string(), nullptr);

for(size_t i = 0; i < count; i++) {
jstring string = env->NewStringUTF(properties[i]);
env->SetObjectArrayElement(array, i, string);
}

delete[] properties;

return array;
}
1 change: 1 addition & 0 deletions packages/jni-swig-stub/src/main/jni/realm_api_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,6 @@ bool realm_sync_websocket_message(int64_t observer_ptr, jbyteArray data, size_t
void realm_sync_websocket_closed(int64_t observer_ptr, bool was_clean, int error_code, const char* reason);

jobjectArray realm_get_log_category_names();
jobjectArray realm_get_additional_properties_helper(realm_object_t* obj);

#endif //TEST_REALM_API_HELPERS_H
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface BaseRealm : Versioned {
* @return the schema of the realm.
*/
public fun schema(): RealmSchema
// public fun schema(fullSchema: Boolean = false): RealmSchema

/**
* Returns the schema version of the realm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public interface Configuration {
*/
public val initialRealmFileConfiguration: InitialRealmFileConfiguration?

// FIXME DOCS
public val relaxedSchema: Boolean

/**
* Base class for configuration builders that holds properties available to both
* [RealmConfiguration] and [SyncConfiguration].
Expand Down Expand Up @@ -209,6 +212,7 @@ public interface Configuration {
protected var initialDataCallback: InitialDataCallback? = null
protected var inMemory: Boolean = false
protected var initialRealmFileConfiguration: InitialRealmFileConfiguration? = null
protected var relaxedSchema: Boolean = false

/**
* Sets the filename of the realm file.
Expand Down Expand Up @@ -399,6 +403,12 @@ public interface Configuration {
return this as S
}

// FIXME Docs
public fun relaxedSchema(relaxedSchema: Boolean): S {
this.relaxedSchema = relaxedSchema
return this as S
}

protected fun validateEncryptionKey(encryptionKey: ByteArray): ByteArray {
if (encryptionKey.size != Realm.ENCRYPTION_KEY_LENGTH) {
throw IllegalArgumentException("The provided key must be ${Realm.ENCRYPTION_KEY_LENGTH} bytes. The provided key was ${encryptionKey.size} bytes.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public interface RealmConfiguration : Configuration {
initialDataCallback,
inMemory,
initialRealmFileConfiguration,
relaxedSchema,
realmLogger
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public open class ConfigurationImpl(
override val isFlexibleSyncConfiguration: Boolean,
inMemory: Boolean,
initialRealmFileConfiguration: InitialRealmFileConfiguration?,
relaxedSchema: Boolean,
override val logger: ContextLogger
) : InternalConfiguration {

Expand Down Expand Up @@ -96,6 +97,7 @@ public open class ConfigurationImpl(
final override val initialDataCallback: InitialDataCallback?
final override val inMemory: Boolean
final override val initialRealmFileConfiguration: InitialRealmFileConfiguration?
final override val relaxedSchema: Boolean

override fun createNativeConfiguration(): RealmConfigurationPointer {
val nativeConfig: RealmConfigurationPointer = RealmInterop.realm_config_new()
Expand Down Expand Up @@ -141,6 +143,7 @@ public open class ConfigurationImpl(
this.initialDataCallback = initialDataCallback
this.inMemory = inMemory
this.initialRealmFileConfiguration = initialRealmFileConfiguration
this.relaxedSchema = relaxedSchema

// We need to freeze `compactOnLaunchCallback` reference on initial thread for Kotlin Native
val compactCallback = compactOnLaunchCallback?.let { callback ->
Expand Down Expand Up @@ -225,6 +228,8 @@ public open class ConfigurationImpl(

RealmInterop.realm_config_set_in_memory(nativeConfig, inMemory)

RealmInterop.realm_config_set_relaxed_schema(nativeConfig, relaxedSchema)

nativeConfig
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class RealmConfigurationImpl(
initialDataCallback: InitialDataCallback?,
inMemory: Boolean,
initialRealmFileConfiguration: InitialRealmFileConfiguration?,
relaxedSchema: Boolean,
logger: ContextLogger
) : ConfigurationImpl(
directory,
Expand All @@ -66,6 +67,7 @@ internal class RealmConfigurationImpl(
false,
inMemory,
initialRealmFileConfiguration,
relaxedSchema,
logger
),
RealmConfiguration
Loading

0 comments on commit 4ace62d

Please sign in to comment.