public class EntityDescriptor extends Object
Modifier and Type | Field and Description |
---|---|
protected List<Consumer<Object>> |
afterDeleteHandlers
A list of all additional handlers to be executed once an entity was successfully deleted
|
protected List<Consumer<Object>> |
afterSaveHandlers
A list of all additional handlers to be executed once an entity is was saved
|
protected List<Consumer<Object>> |
beforeDeleteHandlers
A list of all additional handlers to be executed once an entity is about to be deleted
|
protected sirius.kernel.commons.PriorityCollector<Consumer<Object>> |
beforeSaveHandlerCollector
Collects handlers which are executed before entity is saved, need to be in order (some checks might depend on others),
BeforeSave permits to specify a property which is used to here to sort the handlers. |
protected List<Consumer<Object>> |
cascadeDeleteHandlers
A list of all additional handlers to be executed once an entity was deleted
|
protected Map<String,String> |
columnAliases |
protected Set<Class<? extends Composite>> |
composites
Contains a set of all composites contained within this entity.
|
protected static List<PropertyFactory> |
factories
Contains all known property factories.
|
protected com.typesafe.config.Config |
legacyInfo |
protected BaseMapper<?,?,?> |
mapper |
protected Set<Class<? extends Mixable>> |
mixins
Contains a set of all mixins available for this entity.
|
protected Map<String,Property> |
properties
Contains all properties (defined via fields, composites or mixins)
|
protected List<Consumer<Object>> |
sortedBeforeSaveHandlers
A list of all additional handlers to be executed once an entity is about to be saved
|
protected Class<?> |
type
Contains the entity class
|
protected List<BiConsumer<Object,Consumer<String>>> |
validateHandlers
A list of all handlers to be executed once an entity is validated
|
protected boolean |
versioned |
Modifier | Constructor and Description |
---|---|
protected |
EntityDescriptor(Class<?> type)
Creates a new entity for the given reference instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addBeforeDeleteHandler(Consumer<Object> handler)
Adds a before delete handler for entities managed by this descriptor.
|
void |
addCascadeDeleteHandler(Consumer<Object> handler)
Adds a cascade handler for entities managed by this descriptor.
|
void |
addComposite(Class<? extends Composite> composite)
Used to add a class to the list of contained composites within the described entity.
|
static void |
addFields(EntityDescriptor descriptor,
AccessPath accessPath,
Class<?> clazz,
Consumer<Property> propertyConsumer) |
void |
addValidationHandler(BiConsumer<Object,Consumer<String>> handler)
Adds a validation handler
|
void |
afterDelete(BaseEntity<?> entity)
Invokes all afterDeleteHandlers.
|
void |
afterSave(Object entity)
Executes all afterSaveHandlers once an entity was saved to the database.
|
void |
beforeDelete(Object entity)
Invokes all beforeDeleteHandlers and then all cascadeDeleteHandlers for the given entity.
|
void |
beforeSave(Object entity)
Executes all beforedSaveHandlers known to the descriptor.
|
boolean |
equals(Object obj) |
Property |
findProperty(String property)
Returns the property for the given name.
|
String |
getLabel()
Returns the "end user friendly" name of the entity.
|
com.typesafe.config.Config |
getLegacyInfo()
Provides access to the "legacy" block in the system config which is stored for this entity type.
|
BaseMapper<?,?,?> |
getMapper()
Returns the
mapper in charge of managing entities of this type. |
Collection<Class<? extends Mixable>> |
getMixins()
Returns all mixins known for the describes entity.
|
String |
getPluralLabel()
Returns the "end user friendly" plural of the entity.
|
Collection<Property> |
getProperties()
Returns all properties known by this descriptor.
|
Property |
getProperty(Mapping column)
Returns the property for the given column.
|
Property |
getProperty(String property)
Returns the property for the given name.
|
String |
getRealm()
Returns the realm of entities of this type.
|
Object |
getReferenceInstance()
Each descriptor keeps a single instance of the entity as reference to determine default values etc.
|
String |
getRelationName()
Returns the technical simple name to use.
|
Class<?> |
getType()
Returns the entity class managed by this descriptor.
|
boolean |
hasComposite(Class<? extends Composite> composite)
Determines if a composite of the given type is present within this entity.
|
int |
hashCode() |
boolean |
hasValidationWarnings(Object entity)
Determines if the given entity has validation warnings.
|
protected void |
initialize()
Loads all properties from the fields being present in the target type.
|
boolean |
isChanged(BaseEntity<?> entity,
Property property)
Determines if the value for the property was changed since it was last fetched from the database.
|
boolean |
isFetched(BaseEntity<?> entity,
Property property)
Determines if a value was fetched in the given entity for the given property.
|
boolean |
isVersioned()
Determines if the underlying entity uses optimistic locking.
|
protected void |
link()
Links all properties to setup foreign keys and delete constraints.
|
Object |
make(Class<? extends BaseMapper<?,?,?>> mapperType,
String alias,
sirius.kernel.commons.ValueSupplier<String> supplier)
Creates an entity from the given result row.
|
String |
rewritePropertyName(String basicPropertyName)
Applies legacy renaming rules to determine the effective property name based on the name generated by the
property.
|
String |
toString() |
List<String> |
validate(Object entity)
Executes all validation handlers on the given entity.
|
protected final Class<?> type
protected final Map<String,Property> properties
protected final Set<Class<? extends Composite>> composites
protected final Set<Class<? extends Mixable>> mixins
protected final List<Consumer<Object>> cascadeDeleteHandlers
protected final List<Consumer<Object>> beforeDeleteHandlers
protected final List<Consumer<Object>> afterDeleteHandlers
protected List<Consumer<Object>> sortedBeforeSaveHandlers
protected sirius.kernel.commons.PriorityCollector<Consumer<Object>> beforeSaveHandlerCollector
BeforeSave
permits to specify a property which is used to here to sort the handlers.
sortedBeforeSaveHandlers will be filled when first accessed and provide a properly sorted listprotected final List<Consumer<Object>> afterSaveHandlers
protected final List<BiConsumer<Object,Consumer<String>>> validateHandlers
protected static List<PropertyFactory> factories
protected com.typesafe.config.Config legacyInfo
protected boolean versioned
protected BaseMapper<?,?,?> mapper
protected EntityDescriptor(Class<?> type)
type
- the type from which the descriptor is filledpublic String getRelationName()
This is e.g. used to determine table names or collection names in the datasource.
public String getRealm()
Depending on the mapper and database, this can control the effective target database or storage settings used for this entity.
public String getLabel()
This is determined by calling NLS.get() with the full class name or as fallback the simple class name as lower case, prepended with "Model.". Therefore the property keys for "org.acme.model.Customer" would be the class name and "Model.customer". The fallback key will be the same which is tried for a property named "customer" and can therefore be reused.
public String getPluralLabel()
The i18n keys tried are the same as for getLabel()
with ".plural" appended.
protected void link()
public Collection<Property> getProperties()
These are either properties declared by the type (class) of the entity and its superclasses or once defined
by Composite
s and Mixin
s.
public boolean isFetched(BaseEntity<?> entity, Property property)
As queries might select only certain fields, not all properties are filled for an entity.
entity
- the entity to checkproperty
- the property to check forpublic boolean isChanged(BaseEntity<?> entity, Property property)
entity
- the entity to checkproperty
- the property to check forpublic final void beforeSave(Object entity)
entity
- the entity to perform the handlers onpublic void afterSave(Object entity)
entity
- the entity which was savedpublic List<String> validate(Object entity)
entity
- the entity to validatepublic boolean hasValidationWarnings(Object entity)
entity
- the entity to checkpublic void beforeDelete(Object entity)
entity
- the entity which is about to be deletedpublic void addCascadeDeleteHandler(Consumer<Object> handler)
handler
- the handler to addpublic void addBeforeDeleteHandler(Consumer<Object> handler)
handler
- the handler to addpublic void addValidationHandler(BiConsumer<Object,Consumer<String>> handler)
handler
- the handler to addpublic void afterDelete(BaseEntity<?> entity)
entity
- the entity which was deletedprotected void initialize()
public static void addFields(EntityDescriptor descriptor, AccessPath accessPath, Class<?> clazz, Consumer<Property> propertyConsumer)
public Object make(Class<? extends BaseMapper<?,?,?>> mapperType, String alias, sirius.kernel.commons.ValueSupplier<String> supplier) throws Exception
mapperType
- the mapper which is currently activealias
- the field alias used to generate unique column namessupplier
- used to provide values for a given column nameException
- in case of an error while building the entitypublic String rewritePropertyName(String basicPropertyName)
basicPropertyName
- the generic property name generated by the propertypublic Class<?> getType()
public Property getProperty(Mapping column)
column
- the name of the property given as column@Nonnull public Property getProperty(String property)
If the property does not exits, an error will be thrown.
property
- the name of the property@Nullable public Property findProperty(String property)
If the property does not exist, null is returned.
property
- the name of the property or null if no property with the given name exists.public Object getReferenceInstance()
public BaseMapper<?,?,?> getMapper()
mapper
in charge of managing entities of this type.public void addComposite(Class<? extends Composite> composite)
This is used by CompositePropertyFactory
to notify the descriptor that a
composite is present.
composite
- the type of composite which is present within this entitypublic boolean hasComposite(Class<? extends Composite> composite)
composite
- the composite type to check forpublic Collection<Class<? extends Mixable>> getMixins()
public com.typesafe.config.Config getLegacyInfo()
public boolean isVersioned()
Copyright © 2018. All rights reserved.