Hello,
I wanted to tap a bit into the deeper stuff like PropertyBridges. I think I understand the concepts but am stuck at some point with the Binder Java-API.
How to use the field name in the entity that uses the Property with the Annotation as index field name? Like the default behavior in ValueBridge. I’m confused: Why cant i type context.bridgedElement().name()
?
My use case would be Enums with an additional (e.g.) priority Value, e.g.:
enum AnimalType implements Prioritized {
DOG(prio: 1),
CAT(prio: 2),
HORSE(prio: 3),
...
}
@Entity
public class Pet {
@PropertyBinding(...)
AnimalType type;
}
Now i want an index like:
pet.type = "DOG"
pet.type.sort = 1
pet.type = "CAT"
pet.type.sort = 2
I know i can use the good and great getter+@Indexingdependcy+@GenericField) in my entity. But what i have many dozens of differrent enums like this and i want a more general solution without having to write getters all over the place. Seems to me like PropertyBinder is the answer.
public class EnumTypeBinder implements PropertyBinder {
public static final String SORT_APPENDIX = "sort";
@Override
public void bind(TypeBindingContext context) {
context.dependencies().useRootOnly();
context.bridgedElement().property("???").name();
context.indexSchemaElement()
.objectField("<property name>")
//...
.toReference();
//
}
I’m confused: Why cant i type context.bridgedElement().name()
?