Unique properties not enforced, duplicate values possible
jansorg opened this issue · 4 comments
jansorg commented
I've noticed that properties with unique = true
are not enforcing the uniqueness. See the program below which demonstrates this.
The program should fail to create an entity with a duplicate value of the unique property. It should also fail to create an empty property of the xdRequiredStringProp
, I think.
I'm using these version:
ext.xodus_version = '1.2.3358'
ext.xodus_dnq_version = '1.1.363'
Let me know if I misunderstood the API.
package myPackage
import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.XdEntity
import kotlinx.dnq.XdModel
import kotlinx.dnq.XdNaturalEntityType
import kotlinx.dnq.query.toList
import kotlinx.dnq.store.container.StaticStoreContainer
import kotlinx.dnq.xdRequiredStringProp
import java.io.File
class TestEntity(entity: Entity) : XdEntity(entity) {
companion object : XdNaturalEntityType<TestEntity>()
var uniqueName by xdRequiredStringProp(unique = true)
}
fun main(args: Array<String>) {
XdModel.registerNode(TestEntity)
val dir = File("test_entity_store")
if (dir.exists()) {
dir.deleteRecursively()
}
val store = StaticStoreContainer.init(dir, "db")
store.transactional {
TestEntity.new {
uniqueName = "value"
}
}
// expected that this transaction fails
store.transactional {
TestEntity.new {
uniqueName = "value"
}
}
// expected that this transaction fails due to the empty string (treated as null as described by xdRequiredStringProp)
store.transactional {
TestEntity.new {
uniqueName = ""
}
}
val names = store.transactional(readonly = true){
TestEntity.all().toList().map { it.uniqueName }
}
// prints "value, value, "
println(names)
}
lehvolk commented
You forget to call initMetaData(XdModel.hierarchy, store)
before operating with entities.