Package org.fastnate.generator.context
Class PrimitiveProperty<E,T>
java.lang.Object
org.fastnate.generator.context.Property<E,T>
org.fastnate.generator.context.SingularProperty<E,T>
org.fastnate.generator.context.PrimitiveProperty<E,T>
- Type Parameters:
E- The type of the container classT- The type of the primitive
- Direct Known Subclasses:
GeneratedIdProperty,VersionProperty
Describes a singular primitive property of an
EntityClass.
A primitive property is not only a Java primitive, but it includes all properties that are of a type that is easily
mapped to an SQL expression using a ValueConverter.
This includes:
- Java primitive types (boolean, char, byte, short, int, long, float, double)
- Their wrapper types (
Boolean,Character,Byte,Short,Integer,Long,Float,Double) StringBigIntegerandBigDecimalDateand its subclasses (Date,TimeandTimestamp)Calendar- byte arrays (
byte[]andByte[]) - character array (
char[]andCharacter[]) - Enumerated types (
Enum) - User-defined serializable types
- Author:
- Tobias Liefke, Andreas Penski
-
Constructor Summary
ConstructorsConstructorDescriptionPrimitiveProperty(GeneratorContext context, GeneratorTable table, AttributeAccessor attribute, jakarta.persistence.Column columnMetadata) Instantiates a new primitive property.PrimitiveProperty(GeneratorContext context, GeneratorTable table, AttributeAccessor attribute, jakarta.persistence.Column columnMetadata, boolean autogenerated) Instantiates a new primitive property. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInsertExpression(TableStatement statement, E entity) Adds an expression according to the current value of the property for the given entity to an SQL insert statement.The column name in the table.The current context.The converter for any value.The default value.protected StringgetDefaultValue(AttributeAccessor attribute) Finds the default value from the given attribute.protected GeneratorDialectResolves the current dialect from the context.getExpression(E entity, boolean whereExpression) Creates the expression for the current value of the given entity in SQL.getPredicate(E entity) Creates an SQL predicate that references all entities that have the same value as the given entity.getTable()The table of the column.booleanIndicates if the property required.Methods inherited from class org.fastnate.generator.context.SingularProperty
isTableColumnMethods inherited from class org.fastnate.generator.context.Property
createPostInsertStatements, createPreInsertStatements, failIfRequired, findReferencedEntities, generatePendingStatements, getAttribute, getName, getType, getValue, isComposition, setValue, toString
-
Constructor Details
-
PrimitiveProperty
public PrimitiveProperty(GeneratorContext context, GeneratorTable table, AttributeAccessor attribute, jakarta.persistence.Column columnMetadata) Instantiates a new primitive property.- Parameters:
context- the current contexttable- the table that the column belongs toattribute- the attribute of the propertycolumnMetadata- the column metadata
-
PrimitiveProperty
public PrimitiveProperty(GeneratorContext context, GeneratorTable table, AttributeAccessor attribute, jakarta.persistence.Column columnMetadata, boolean autogenerated) Instantiates a new primitive property.- Parameters:
context- the current contexttable- the table that the column belongs toattribute- the attribute of the propertycolumnMetadata- the column metadataautogenerated-trueif the values of this property are not part of any insert statement because they are generated by the database
-
-
Method Details
-
addInsertExpression
Description copied from class:PropertyAdds an expression according to the current value of the property for the given entity to an SQL insert statement.- Overrides:
addInsertExpressionin classProperty<E,T> - Parameters:
statement- the created statemententity- the inspected entity
-
getDefaultValue
Finds the default value from the given attribute.- Parameters:
attribute- the current attribute of the property- Returns:
- the default value or
nullif none is set - See Also:
-
getDialect
Resolves the current dialect from the context.- Returns:
- the dialect of the current generation context
-
getExpression
Description copied from class:PropertyCreates the expression for the current value of the given entity in SQL.- Overrides:
getExpressionin classProperty<E,T> - Parameters:
entity- the entitywhereExpression- indicates that the expression is used in a "where" statement- Returns:
- the expression for the value of this property or
nullif no exists
-
getPredicate
Description copied from class:PropertyCreates an SQL predicate that references all entities that have the same value as the given entity. Used to reference entites by their (unique) properties or ids.- Overrides:
getPredicatein classProperty<E,T> - Parameters:
entity- the entity- Returns:
- the predicate for the value of that entity or
nullif no such expression is available
-
getContext
The current context. -
getTable
The table of the column. -
getColumn
The column name in the table.- Specified by:
getColumnin classSingularProperty<E,T> - Returns:
- the column name
-
isRequired
public boolean isRequired()Indicates if the property required.- Overrides:
isRequiredin classProperty<E,T> - Returns:
trueif the field is required
-
getConverter
The converter for any value. -
getDefaultValue
The default value.
-