E
- The described classpublic class EntityClass<E> extends Object
entity class
.Modifier and Type | Class and Description |
---|---|
private static class |
EntityClass.EntityId
Helper object to use as key in the state map, if we have a
GeneratedIdProperty . |
Modifier and Type | Field and Description |
---|---|
private AccessStyle |
accessStyle
The type of access that is used for the properties (field access or bean property access).
|
private List<Property<? super E,?>> |
additionalProperties
Properties of this entity, excluding the
idProperty or properties from joinedParentClass . |
private List<Property<? super E,?>> |
allProperties
All properties of this entity, including
idProperty and properties from joinedParentClass . |
private List<List<SingularProperty<E,?>>> |
allUniqueProperties
All available sets of properties that make up an additional unique identifier for the entities.
|
private Map<String,javax.persistence.AssociationOverride> |
associationOverrides
All association overriddes of this class and the parent classes.
|
private Map<String,javax.persistence.AttributeOverride> |
attributeOverrides
All attribute overriddes of this class and the parent classes.
|
private List<Consumer<EntityClass<E>>> |
builtListeners
The list of listeners that are informed when this class has finished to build all properties.
|
private GeneratorContext |
context
The current context.
|
private ColumnExpression |
discriminator
The SQL expression that is used for the disciminator column of this class.
|
private GeneratorColumn |
discriminatorColumn
The column for
discriminator . |
private Class<E> |
entityClass
The represented class.
|
private Constructor<E> |
entityConstructor
The JPA constructor.
|
private String |
entityName
The entity name.
|
private Map<Object,GenerationState> |
entityStates
The states of written entities.
|
private EntityClass<? super E> |
hierarchyRoot
The description of the entity class that is the root of the current inheritance hierarchy.
|
private Property<? super E,?> |
idProperty
The property that contains the id for the entity.
|
private javax.persistence.InheritanceType |
inheritanceType
The inheritance type of this class.
|
private EntityClass<? super E> |
joinedParentClass
The description of the next entity class that has
InheritanceType.JOINED , if any. |
private Class<? super E> |
parentEntityClass
Only used during
build() to find the joinedParentClass even if that one references our class. |
private GeneratorColumn |
primaryKeyJoinColumn
The column that contains the id of this entity if
joinedParentClass is not null . |
private Map<String,Property<? super E,?>> |
properties
Mapping from the name of all persistent properties to their description.
|
private GeneratorTable |
table
The main table of the entity.
|
private List<SingularProperty<E,?>> |
uniqueProperties
The properties that make up an additional unique identifier for the entity.
|
private UniquePropertyQuality |
uniquePropertiesQuality
Indicates the quality of
uniqueProperties . |
Constructor and Description |
---|
EntityClass(GeneratorContext context,
Class<E> entityClass)
Creates a new description of an entity class.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
build()
Reads the metadata from
entityClass and fills all other properties. |
private void |
buildDiscriminator() |
private ColumnExpression |
buildDiscriminator(EntityClass<?> c,
javax.persistence.DiscriminatorColumn column) |
private void |
buildGenerators(Class<?> c)
Fills the generators of the
context . |
private void |
buildIdProperty(Class<? super E> c)
Fills the
idProperty . |
private void |
buildInheritance()
Determine the inheritance type and discriminator properties.
|
private void |
buildOverrides(Class<? super E> inspectedClass) |
private void |
buildPrimaryKeyJoinColumn() |
private void |
buildProperties(Class<? super E> c,
Class<? super E> stopClass)
Fills the
properties . |
(package private) <X> Property<X,?> |
buildProperty(GeneratorTable propertyTable,
AttributeAccessor attribute,
Map<String,javax.persistence.AttributeOverride> surroundingAttributeOverrides,
Map<String,javax.persistence.AssociationOverride> surroundingAssociationOverrides)
Builds the property for the given attribute.
|
private void |
buildUniqueProperties(javax.persistence.UniqueConstraint[] uniqueConstraints) |
private void |
buildUniqueProperty(SingularProperty<E,?> property) |
void |
createPostInsertStatements(E entity,
StatementsWriter writer)
Marks an entity as written and creates any pending update / insert statements.
|
private void |
findHierarchyRoot(Class<? super E> inspectedClass) |
private boolean |
findIdProperty(Iterable<AttributeAccessor> declaredAttributes) |
private SingularProperty<E,?> |
findPropertyByColumnName(String columnName) |
AccessStyle |
getAccessStyle()
The type of access that is used for the properties (field access or bean property access).
|
(package private) static Map<String,javax.persistence.AssociationOverride> |
getAccociationOverrides(Map<String,javax.persistence.AssociationOverride> surroundingOverrides,
String prefix,
AnnotatedElement element)
Finds all association overrides that are attached to the given field, method or class, by taking the already
defined overrides into account.
|
List<Property<? super E,?>> |
getAdditionalProperties()
Properties of this entity, excluding the
idProperty or properties from joinedParentClass . |
List<Property<? super E,?>> |
getAllProperties()
All properties of this entity, including
idProperty and properties from joinedParentClass . |
List<List<SingularProperty<E,?>>> |
getAllUniqueProperties()
All available sets of properties that make up an additional unique identifier for the entities.
|
Map<String,javax.persistence.AssociationOverride> |
getAssociationOverrides()
All association overriddes of this class and the parent classes.
|
Map<String,javax.persistence.AttributeOverride> |
getAttributeOverrides()
All attribute overriddes of this class and the parent classes.
|
(package private) static Map<String,javax.persistence.AttributeOverride> |
getAttributeOverrides(Map<String,javax.persistence.AttributeOverride> surroundingOverrides,
String prefix,
AnnotatedElement element)
Finds all
AttributeOverrides that are attached to the given field, method or class, by taking the already
defined overrides into account. |
private static javax.persistence.Column |
getColumnAnnotation(AttributeAccessor attribute,
Map<String,javax.persistence.AttributeOverride> overrides) |
GeneratorContext |
getContext()
The current context.
|
ColumnExpression |
getDiscriminator()
The SQL expression that is used for the disciminator column of this class.
|
GeneratorColumn |
getDiscriminatorColumn()
The column for
discriminator . |
Class<E> |
getEntityClass()
The represented class.
|
String |
getEntityName()
The entity name.
|
ColumnExpression |
getEntityReference(E entity,
String idField,
boolean whereExpression)
Creates an expression that references the id of an entity of this class.
|
Map<Object,GenerationState> |
getEntityStates()
The states of written entities.
|
private ColumnExpression |
getGeneratedIdReference(E entity,
boolean whereExpression) |
EntityClass<? super E> |
getHierarchyRoot()
The description of the entity class that is the root of the current inheritance hierarchy.
|
(package private) GeneratorColumn |
getIdColumn(AttributeAccessor attribute)
Resolves the column for the
id property of this entity class. |
Property<? super E,?> |
getIdProperty()
The property that contains the id for the entity.
|
javax.persistence.InheritanceType |
getInheritanceType()
The inheritance type of this class.
|
EntityClass<? super E> |
getJoinedParentClass()
The description of the next entity class that has
InheritanceType.JOINED , if any. |
Class<? super E> |
getParentEntityClass()
Only used during
build() to find the joinedParentClass even if that one references our class. |
GeneratorColumn |
getPrimaryKeyJoinColumn()
The column that contains the id of this entity if
joinedParentClass is not null . |
Map<String,Property<? super E,?>> |
getProperties()
Mapping from the name of all persistent properties to their description.
|
private Object |
getStateId(E entity)
Finds the id for the given entity, for look up in the
entityStates . |
GeneratorTable |
getTable()
The main table of the entity.
|
List<SingularProperty<E,?>> |
getUniqueProperties()
The properties that make up an additional unique identifier for the entity.
|
UniquePropertyQuality |
getUniquePropertiesQuality()
Indicates the quality of
uniqueProperties . |
private void |
inspectUniqueConstraint(javax.persistence.UniqueConstraint constraint) |
private boolean |
isBetterUniquePropertyQuality(UniquePropertyQuality foundQuality) |
boolean |
isNew(E entity)
Indicates that the given entity needs to be written.
|
void |
markExistingEntity(E entity)
Marks a entity reference, where we don't know the ID in the database.
|
<V> void |
markPendingUpdates(E pendingEntity,
V entityToUpdate,
Property<V,?> propertyToUpdate,
Object... arguments)
Marks an update that is necessary when an entity is written (in the future).
|
E |
newInstance()
Creates a new entity of the represented
class . |
void |
onPropertiesAvailable(Consumer<EntityClass<E>> listener)
Registers a listener that is called as soon as all properties of this class are built.
|
String |
toString() |
private final GeneratorContext context
@Nonnull private final Constructor<E> entityConstructor
@Nonnull private GeneratorTable table
private AccessStyle accessStyle
private javax.persistence.InheritanceType inheritanceType
null
if no subclass is known and no inhertance is indicated (using one of the inheritance annotations).private Class<? super E> parentEntityClass
build()
to find the joinedParentClass even if that one references our class.private EntityClass<? super E> joinedParentClass
InheritanceType.JOINED
, if any.private EntityClass<? super E> hierarchyRoot
private ColumnExpression discriminator
null
if no discriminator is usedprivate GeneratorColumn discriminatorColumn
discriminator
.
null
if this class does not belong to a table that contains a discriminator columnprivate GeneratorColumn primaryKeyJoinColumn
joinedParentClass
is not null
.@Nullable private Property<? super E,?> idProperty
joinedParentClass
exists, this property is the id property of the parent class.@Nullable private List<SingularProperty<E,?>> uniqueProperties
GeneratorContext.getUniquePropertyQuality()
and
GeneratorContext.getMaxUniqueProperties()
this might be null
, even if there is a set of
available unique properties
, if the quality is not enough.private UniquePropertyQuality uniquePropertiesQuality
uniqueProperties
.private final List<List<SingularProperty<E,?>>> allUniqueProperties
private final Map<String,Property<? super E,?>> properties
private final List<Property<? super E,?>> allProperties
idProperty
and properties from joinedParentClass
.private final List<Property<? super E,?>> additionalProperties
idProperty
or properties from joinedParentClass
.private final Map<Object,GenerationState> entityStates
private final Map<String,javax.persistence.AttributeOverride> attributeOverrides
private final Map<String,javax.persistence.AssociationOverride> associationOverrides
private List<Consumer<EntityClass<E>>> builtListeners
EntityClass(GeneratorContext context, Class<E> entityClass)
context
- the current contextentityClass
- the represented classstatic Map<String,javax.persistence.AssociationOverride> getAccociationOverrides(Map<String,javax.persistence.AssociationOverride> surroundingOverrides, String prefix, AnnotatedElement element)
surroundingOverrides
- the overrides already defined for the surrounding elementprefix
- the prefix of the element, for lookup in surroundingOverrides
element
- the annotated elementAssociationOverrides
nor AssociationOverride
are givenstatic Map<String,javax.persistence.AttributeOverride> getAttributeOverrides(Map<String,javax.persistence.AttributeOverride> surroundingOverrides, String prefix, AnnotatedElement element)
AttributeOverrides
that are attached to the given field, method or class, by taking the already
defined overrides into account.surroundingOverrides
- the overrides already defined for the surrounding elementprefix
- the prefix of the element, for lookup in surroundingOverrides
element
- the annotated elementAttributeOverrides
nor AttributeOverride
are givenprivate static javax.persistence.Column getColumnAnnotation(AttributeAccessor attribute, Map<String,javax.persistence.AttributeOverride> overrides)
void build()
entityClass
and fills all other properties.
Not done in the constructor to prevent endless loops (when we reference an entity class that references us).private void buildDiscriminator()
private ColumnExpression buildDiscriminator(EntityClass<?> c, javax.persistence.DiscriminatorColumn column)
private void buildGenerators(Class<?> c)
context
.c
- the currently inspected classprivate void buildIdProperty(Class<? super E> c)
idProperty
.c
- the currently inspected classprivate void buildInheritance()
private void buildPrimaryKeyJoinColumn()
private void buildProperties(Class<? super E> c, Class<? super E> stopClass)
properties
.c
- the currently inspected classstopClass
- the class in the hierarchy to stop inspecting<X> Property<X,?> buildProperty(GeneratorTable propertyTable, AttributeAccessor attribute, Map<String,javax.persistence.AttributeOverride> surroundingAttributeOverrides, Map<String,javax.persistence.AssociationOverride> surroundingAssociationOverrides)
propertyTable
- the table of the new property (if it is not a collection property)attribute
- the attribute to inspectsurroundingAttributeOverrides
- the overrides defined for the surrounding elementsurroundingAssociationOverrides
- the overrides defined for the surrounding elementnull
if not persistentprivate void buildUniqueProperties(javax.persistence.UniqueConstraint[] uniqueConstraints)
private void buildUniqueProperty(SingularProperty<E,?> property)
public void createPostInsertStatements(E entity, StatementsWriter writer) throws IOException
entity
- the entity that exists now in the databasewriter
- the target of the new statementsIOException
- if the writer throws oneprivate boolean findIdProperty(Iterable<AttributeAccessor> declaredAttributes)
private SingularProperty<E,?> findPropertyByColumnName(String columnName)
public ColumnExpression getEntityReference(E entity, String idField, boolean whereExpression)
entity
- the entityidField
- the field that contains the id, only interesting if the id is an EmbeddedProperty
whereExpression
- indicates that the reference is used in a "where" statementunique properties
or the
id
of the entityprivate ColumnExpression getGeneratedIdReference(E entity, boolean whereExpression)
GeneratorColumn getIdColumn(AttributeAccessor attribute)
id property
of this entity class.attribute
- the referencing attribute (for evaluating annotations)IllegalStateException
- if the id property is not singular and no MapsId is givenprivate Object getStateId(E entity)
entityStates
.entity
- the entityprivate void inspectUniqueConstraint(javax.persistence.UniqueConstraint constraint)
private boolean isBetterUniquePropertyQuality(UniquePropertyQuality foundQuality)
public boolean isNew(E entity)
entity
- the entity to checktrue
if the entity was neither written, nor exists in the databasepublic void markExistingEntity(E entity)
entity
- the entity to markpublic <V> void markPendingUpdates(E pendingEntity, V entityToUpdate, Property<V,?> propertyToUpdate, Object... arguments)
pendingEntity
- the entity that needs to be written, before the update can take placeentityToUpdate
- the entity to updatepropertyToUpdate
- the property of the entity to updatearguments
- additional argumentspublic E newInstance()
class
.public void onPropertiesAvailable(Consumer<EntityClass<E>> listener)
listener
- called as soon as all properties are available@Generated(value="lombok") public GeneratorContext getContext()
@Nonnull @Generated(value="lombok") public Class<E> getEntityClass()
@Nonnull @Generated(value="lombok") public String getEntityName()
@Nonnull @Generated(value="lombok") public GeneratorTable getTable()
@Generated(value="lombok") public AccessStyle getAccessStyle()
@Generated(value="lombok") public javax.persistence.InheritanceType getInheritanceType()
null
if no subclass is known and no inhertance is indicated (using one of the inheritance annotations).@Generated(value="lombok") public Class<? super E> getParentEntityClass()
build()
to find the joinedParentClass even if that one references our class.@Generated(value="lombok") public EntityClass<? super E> getJoinedParentClass()
InheritanceType.JOINED
, if any.@Generated(value="lombok") public EntityClass<? super E> getHierarchyRoot()
@Generated(value="lombok") public ColumnExpression getDiscriminator()
null
if no discriminator is used@Generated(value="lombok") public GeneratorColumn getDiscriminatorColumn()
discriminator
.
null
if this class does not belong to a table that contains a discriminator column@Generated(value="lombok") public GeneratorColumn getPrimaryKeyJoinColumn()
joinedParentClass
is not null
.@Nullable @Generated(value="lombok") public Property<? super E,?> getIdProperty()
joinedParentClass
exists, this property is the id property of the parent class.@Nullable @Generated(value="lombok") public List<SingularProperty<E,?>> getUniqueProperties()
GeneratorContext.getUniquePropertyQuality()
and
GeneratorContext.getMaxUniqueProperties()
this might be null
, even if there is a set of
available unique properties
, if the quality is not enough.@Generated(value="lombok") public UniquePropertyQuality getUniquePropertiesQuality()
uniqueProperties
.@Generated(value="lombok") public List<List<SingularProperty<E,?>>> getAllUniqueProperties()
@Generated(value="lombok") public Map<String,Property<? super E,?>> getProperties()
@Generated(value="lombok") public List<Property<? super E,?>> getAllProperties()
idProperty
and properties from joinedParentClass
.@Generated(value="lombok") public List<Property<? super E,?>> getAdditionalProperties()
idProperty
or properties from joinedParentClass
.@Generated(value="lombok") public Map<Object,GenerationState> getEntityStates()
@Generated(value="lombok") public Map<String,javax.persistence.AttributeOverride> getAttributeOverrides()
@Generated(value="lombok") public Map<String,javax.persistence.AssociationOverride> getAssociationOverrides()
Copyright © 2022 fastnate.org. All rights reserved.