Version 1.1.3
- Add check on references
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user