Dynamic Properties
triplem opened this issue · 1 comments
triplem commented
I would like to store Metadata from external sources in Xodus by using dnq. Me is pretty new to both, so I do appreciate any feedback.
Since the Data is from external sources, I do know some of the fields I need to store, but not all. Therefore I want to store those additional properties as a Map on the entity. Is this possible using dnq?
I was thinking along the lines of a link to a generic entity, but then I am unable to use dnq to fetch this entity using dnq.
lehvolk commented
You can declare XdEntity with known properties/links and delegate setting/getting unknown properties to entity
field:
class XdMetaModel(entity: Entity) : XdEntity(entity) {
companion object : XdNaturalEntityType() {
fun findBy(unknownPropertyName: String, value: String?) : XdQuery<XdMetaModel>{
return XdMetaModel.all().query(PropertyEqual(unknownPropertyName, value))
}
}
var knownField by xdStringProp()
var knownLink by xdLink0_1(XdMetaModel)
fun getProperty(name: String, value: String?): String? {
entity.getProperty(name) as String?
}
fun addProperty(name: String, value: String?) {
entity.setProperty(name, value)
}
}
As you can see finding by unknown properties/links requires using low-level api with PropertyEqual
and LinkEqual
classes.