Builder and query factory for a single persistent entity type, scoped to the current admin organisation. Obtained from KCriteriaBuilders by registered name or by entity class. Wraps the entity's Hibernate criteria construction, restricting every query, save and delete to rows owned by, or associated with, the caller's organisation. Also instantiates new entities for types that register an instantiator, and reads the entity's bean properties for generic property editing UIs.
Group: Builders
Properties
| Property | Returns | Description |
|---|---|---|
| associations | Map<String,Class> | The association names this builder can join by, mapped to the entity class of each associated property. |
| fields | Map<String,String> | The managed entity's bean properties, excluding any marked @Transient, mapped to their simple type name. Used to drive generic property editing UIs without hard-coding each entity's field list. |
| name | String | The name this builder is registered under, e.g. "product" or "profile" - the key used to look it up via KCriteriaBuilders.get(String) or getBuilder(String). |
Methods
getName() · instantiate() · save(T o) · build(Criteria fromCrit, String path, String alias, JoinType joinType) · build() · get(Long id) · getAssociations() · delete(T o) · typedValue(String fieldName, Object unparsedValue) · getFields()
getName()
Returns: String
The name this builder is registered under, e.g. "product" or "profile" - the key used to look it up via KCriteriaBuilders.get(String) or getBuilder(String).
instantiate()
Returns: Object
Creates a new, unsaved instance of the managed entity type using the registered instantiator, pre-populated with the current admin organisation. Throws a RuntimeException if this entity type does not register an instantiator.
save(T o)
Returns: void
Persists the given entity, checking it is an instance of this builder's managed class and, when a validator is registered, that its admin organisation matches the current organisation. Flushes the session and fires an indexed-item-updated event after saving.
| Parameter | Description |
|---|---|
o | the entity to save, must be an instance of this builder's managed class |
build(Criteria fromCrit, String path, String alias, JoinType joinType)
Returns: KCriteria
Builds a KCriteria by joining the managed entity onto an existing Hibernate Criteria at the given association path, then restricting the join to rows owned by the current admin organisation. For a left outer join, rows with a null organisation are also included.
| Parameter | Description |
|---|---|
fromCrit | the existing Criteria to join onto |
path | the association path, relative to fromCrit, to join through |
alias | the alias to assign to the joined entity |
joinType | the type of join to perform, e.g. inner or left outer |
build()
Returns: KCriteria
Builds a fresh KCriteria for the managed entity type, restricted to rows owned by the current admin organisation. Also joins in the required association, if this builder declares one.
get(Long id)
Returns: Object
Looks up a single entity of the managed type by its ID, scoped to the current admin organisation.
| Parameter | Description |
|---|---|
id | the entity's database ID |
getAssociations()
Returns: Map<String,Class>
The association names this builder can join by, mapped to the entity class of each associated property.
delete(T o)
Returns: void
Deletes the given entity, checking it is an instance of this builder's managed class, then flushes the session and fires an indexed-item-deleted event.
| Parameter | Description |
|---|---|
o | the entity to delete, must be an instance of this builder's managed class |
typedValue(String fieldName, Object unparsedValue)
Returns: Object
Coerces a raw, unparsed value into the correct Java type for the given field name, for the handful of fields where the generic bean property type is not sufficient. Currently only handles the "complete" field on ModuleStatus, converting it to a boolean; every other field is returned unchanged.
| Parameter | Description |
|---|---|
fieldName | the bean property name to coerce the value for |
unparsedValue | the raw value, typically a string from a form post |
getFields()
Returns: Map<String,String>
The managed entity's bean properties, excluding any marked @Transient, mapped to their simple type name. Used to drive generic property editing UIs without hard-coding each entity's field list.