Version 1.1.3

- Add check on references
This commit is contained in:
2024-12-05 20:13:41 +01:00
parent cbeda381cc
commit be16104216
3 changed files with 15 additions and 3 deletions

2
.idea/kotlinc.xml generated
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="2.0.0" />
<option name="version" value="2.0.21" />
</component>
</project>

View File

@@ -1,14 +1,14 @@
import org.gradle.model.internal.core.ModelNodes.withType
plugins {
kotlin("jvm") version "2.0.21"
kotlin("jvm") version "2.1.0"
`maven-publish`
signing
id("org.jetbrains.dokka") version "1.5.31"
}
group = "nl.astraeus"
version = "1.1.3-SNAPSHOT"
version = "1.1.3"
repositories {
mavenCentral()

View File

@@ -20,10 +20,16 @@ class Reference<S : Persistable>(
var id: Long = initialValue.id
operator fun getValue(thisRef: Persistable, property: KProperty<*>): S {
check(currentTransaction() != null) {
"No transaction available"
}
return currentTransaction()?.find(cls.kotlin, id) ?: throw IllegalStateException("Reference not found")
}
operator fun setValue(thisRef: Persistable, property: KProperty<*>, value: S) {
check(currentTransaction() != null) {
"No transaction available"
}
currentTransaction()?.store(value)
id = value.id
}
@@ -40,10 +46,16 @@ class NullableReference<S : Persistable>(
var id: Long? = initialValue?.id
operator fun getValue(thisRef: Persistable, property: KProperty<*>): S? {
check(currentTransaction() != null) {
"No transaction available"
}
return currentTransaction()?.find(cls.kotlin, id ?: 0L)
}
operator fun setValue(thisRef: Persistable, property: KProperty<*>, value: S?) {
check(currentTransaction() != null) {
"No transaction available"
}
if (value != null) {
// todo: only store if not already stored?
currentTransaction()?.store(value)