Module is.codion.framework.domain
Interface EntityDefinition
-
public interface EntityDefinition
Specifies an entity definition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
EntityDefinition.Builder
Builds a EntityDefinition
-
Field Summary
Fields Modifier and Type Field Description static PropertyValue<Boolean>
STRICT_FOREIGN_KEYS
Specifies whether it should be possible to define foreign keys referencing entities that have not been defined, this can be disabled in cases where entities have circular references.
Value type: Boolean
Default value: true
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Attribute<T>
attribute(String attributeName)
Returns the attribute with the given name, null if none is found.ColorProvider
backgroundColorProvider()
Returns the background color provider, never nullString
caption()
List<ColumnProperty<?>>
columnProperties()
List<ColumnProperty<?>>
columnProperties(List<Attribute<?>> attributes)
Returns theColumnProperty
s based on the given attributes<T> ColumnProperty<T>
columnProperty(Attribute<T> attribute)
Comparator<Entity>
comparator()
ConditionProvider
conditionProvider(ConditionType conditionType)
Returns theConditionProvider
associated with the given typeboolean
containsAttribute(Attribute<?> attribute)
MethodHandle
defaultMethodHandle(Method method)
Returns the MethodHandle for the given default method in theEntityType.entityClass()
.Collection<Attribute<?>>
defaultSelectAttributes()
Returns the attributes selected by default for this entity type.static EntityDefinition.Builder
definition(Property.Builder<?,?>... propertyBuilders)
Creates aEntityDefinition.Builder
instance based on the given property builders.static EntityDefinition.Builder
definition(List<Property.Builder<?,?>> propertyBuilders)
Creates aEntityDefinition.Builder
instance based on the given property builders.List<DenormalizedProperty<?>>
denormalizedProperties(Attribute<Entity> entityAttribute)
Retrieves the denormalized properties which values originate from the entity referenced by the given entity attribute<T> Collection<Attribute<?>>
derivedAttributes(Attribute<T> attribute)
Returns the attributes which values are derived from the value of the given attribute, an empty collection if no such derived attributes existString
description()
String
domainName()
Entity
entity()
Creates a newEntity
instance based on this definitionEntity
entity(Map<Attribute<?>,Object> values)
Creates a newEntity
instance based on this definitionEntity
entity(Map<Attribute<?>,Object> values, Map<Attribute<?>,Object> originalValues)
Creates a newEntity
instance based on this definitionColorProvider
foregroundColorProvider()
Returns the foreground color provider, never nullList<ForeignKeyProperty>
foreignKeyProperties()
<T> List<ForeignKeyProperty>
foreignKeyProperties(Attribute<T> columnAttribute)
ForeignKeyProperty
foreignKeyProperty(ForeignKey foreignKey)
Collection<ForeignKey>
foreignKeys()
List<ForeignKey>
foreignKeys(EntityType referencedEntityType)
Returns the foreign keys referencing entities of the given typeAttribute<?>
getterAttribute(Method method)
Returns the Attribute for the getter this method represents in theEntityType.entityClass()
, null if none exists.String
groupByClause()
boolean
hasDenormalizedProperties()
boolean
hasDenormalizedProperties(Attribute<Entity> entityAttribute)
boolean
hasDerivedAttributes()
<T> boolean
hasDerivedAttributes(Attribute<T> attribute)
Returns true if this entity contains attributes which values are derived from the value of the given attributeboolean
hasPrimaryKey()
boolean
isForeignKeyAttribute(Attribute<?> attribute)
boolean
isKeyGenerated()
Returns true if the value for the primary key of this entity is generated with aKeyGenerator
.boolean
isOptimisticLockingEnabled()
boolean
isReadOnly()
boolean
isSmallDataset()
boolean
isStaticData()
boolean
isUpdatable(ForeignKey foreignKey)
KeyGenerator
keyGenerator()
List<ColumnProperty<?>>
lazyLoadedBlobProperties()
OrderBy
orderBy()
<T> Key
primaryKey(T value)
Creates a newKey
instance based on this definition, initialised with the given valueList<Attribute<?>>
primaryKeyAttributes()
Returns a list containing all primary key attributes associated with this entity type.List<ColumnProperty<?>>
primaryKeyProperties()
Returns a list containing all primary key properties associated with this entity type.<T> ColumnProperty<T>
primaryKeyProperty(Attribute<T> attribute)
List<Property<?>>
properties()
List<Property<?>>
properties(Collection<Attribute<?>> attributes)
Returns theProperty
s based on the given attributes<T> Property<T>
property(Attribute<T> attribute)
EntityDefinition
referencedEntityDefinition(ForeignKey foreignKey)
Returns theEntityDefinition
of the entity referenced by the given foreign key property.Collection<Attribute<String>>
searchAttributes()
Returns the attributes to search by when searching for entities of this type by a string valueSelectQuery
selectQuery()
String
selectTableName()
int
serializationVersion()
Returns a serialization version indicator for the underlying entity.Attribute<?>
setterAttribute(Method method)
Returns the Attribute for the setter this method represents in theEntityType.entityClass()
, null if none exists.Function<Entity,String>
stringFactory()
String
tableName()
List<TransientProperty<?>>
transientProperties()
EntityType
type()
List<Property<?>>
updatableProperties()
EntityValidator
validator()
List<Property<?>>
visibleProperties()
List<ColumnProperty<?>>
writableColumnProperties(boolean includePrimaryKeyProperties, boolean includeNonUpdatable)
Retrieves the writable (non-read-only) column properties comprising this entity type
-
-
-
Field Detail
-
STRICT_FOREIGN_KEYS
static final PropertyValue<Boolean> STRICT_FOREIGN_KEYS
Specifies whether it should be possible to define foreign keys referencing entities that have not been defined, this can be disabled in cases where entities have circular references.
Value type: Boolean
Default value: true
-
-
Method Detail
-
type
EntityType type()
- Returns:
- the entity type
-
tableName
String tableName()
- Returns:
- the name of the underlying table, with schema prefix if applicable
-
conditionProvider
ConditionProvider conditionProvider(ConditionType conditionType)
Returns theConditionProvider
associated with the given type- Parameters:
conditionType
- the condition type- Returns:
- the condition provider associated with the given id
- Throws:
IllegalArgumentException
- in case no ConditionProvider is associated with the given conditionType
-
domainName
String domainName()
- Returns:
- the name of the domain this entity type belongs to
-
validator
EntityValidator validator()
- Returns:
- the validator for this entity type
-
caption
String caption()
- Returns:
- the caption to use when presenting entities of this type
-
description
String description()
- Returns:
- the entity description
-
isSmallDataset
boolean isSmallDataset()
- Returns:
- true if the underlying table is small enough for displaying the contents in a combo box
-
isStaticData
boolean isStaticData()
- Returns:
- true if the data in the underlying table can be regarded as static
-
isReadOnly
boolean isReadOnly()
- Returns:
- true if this entity type is read only
-
isOptimisticLockingEnabled
boolean isOptimisticLockingEnabled()
- Returns:
- true if optimistic locking should be used during updates
-
keyGenerator
KeyGenerator keyGenerator()
- Returns:
- the object responsible for generating primary key values for entities of this type
- See Also:
EntityDefinition.Builder.keyGenerator(KeyGenerator)
-
isKeyGenerated
boolean isKeyGenerated()
Returns true if the value for the primary key of this entity is generated with aKeyGenerator
.- Returns:
- true if the value for the primary key is generated
- See Also:
EntityDefinition.Builder.keyGenerator(KeyGenerator)
-
orderBy
OrderBy orderBy()
- Returns:
- the default order by clause to use when querying entities of this type
-
groupByClause
String groupByClause()
- Returns:
- the group by clause to use when querying entities of this type, without the "group by" keywords
-
selectTableName
String selectTableName()
- Returns:
- the name of the table to use when selecting entities of this type
-
selectQuery
SelectQuery selectQuery()
- Returns:
- the select query to use when selecting entities of this type, may be null
-
stringFactory
Function<Entity,String> stringFactory()
- Returns:
- the object responsible for providing toString values for this entity type
-
comparator
Comparator<Entity> comparator()
- Returns:
- the comparator used when comparing this entity type to other entities
-
hasPrimaryKey
boolean hasPrimaryKey()
- Returns:
- true if this entity has a defined primary key
-
hasDerivedAttributes
boolean hasDerivedAttributes()
- Returns:
- true if this entity contains any attribute which values are derived from other attribute
-
hasDerivedAttributes
<T> boolean hasDerivedAttributes(Attribute<T> attribute)
Returns true if this entity contains attributes which values are derived from the value of the given attribute- Type Parameters:
T
- the attribute type- Parameters:
attribute
- the attribute- Returns:
- true if any attribute values are derived from the given attribute
-
derivedAttributes
<T> Collection<Attribute<?>> derivedAttributes(Attribute<T> attribute)
Returns the attributes which values are derived from the value of the given attribute, an empty collection if no such derived attributes exist- Type Parameters:
T
- the attribute type- Parameters:
attribute
- the attribute- Returns:
- a collection containing the attributes which are derived from the given attribute
-
primaryKeyAttributes
List<Attribute<?>> primaryKeyAttributes()
Returns a list containing all primary key attributes associated with this entity type. If the entity has no primary key attributes defined, an empty list is returned.- Returns:
- the primary key attributes of this entity type, sorted by primary key column index
-
primaryKeyProperties
List<ColumnProperty<?>> primaryKeyProperties()
Returns a list containing all primary key properties associated with this entity type. If the entity has no primary key properties defined, an empty list is returned.- Returns:
- the primary key properties of this entity type, sorted by primary key column index
-
visibleProperties
List<Property<?>> visibleProperties()
- Returns:
- a list containing the visible properties for this entity type
-
columnProperties
List<ColumnProperty<?>> columnProperties()
- Returns:
- a list containing the column-based properties for this entity type
-
lazyLoadedBlobProperties
List<ColumnProperty<?>> lazyLoadedBlobProperties()
- Returns:
- a list containing all lazy loaded blob properties for this entity type
-
transientProperties
List<TransientProperty<?>> transientProperties()
- Returns:
- a list containing the non-column-based properties for this entity type
-
foreignKeyProperties
List<ForeignKeyProperty> foreignKeyProperties()
- Returns:
- a list containing the foreign key properties for this entity type
-
foreignKeys
Collection<ForeignKey> foreignKeys()
- Returns:
- all foreign keys for this entity type
-
referencedEntityDefinition
EntityDefinition referencedEntityDefinition(ForeignKey foreignKey)
Returns theEntityDefinition
of the entity referenced by the given foreign key property.- Parameters:
foreignKey
- the foreign key- Returns:
- the definition of the referenced entity
-
hasDenormalizedProperties
boolean hasDenormalizedProperties()
- Returns:
- true if this entity type has any denormalized properties
-
hasDenormalizedProperties
boolean hasDenormalizedProperties(Attribute<Entity> entityAttribute)
- Parameters:
entityAttribute
- the entity attribute- Returns:
- true if this entity type has any denormalized properties associated with the give entity attribute
-
denormalizedProperties
List<DenormalizedProperty<?>> denormalizedProperties(Attribute<Entity> entityAttribute)
Retrieves the denormalized properties which values originate from the entity referenced by the given entity attribute- Parameters:
entityAttribute
- the entity attribute- Returns:
- a list containing the denormalized properties which values originate from the entity referenced by the given foreign key property
-
containsAttribute
boolean containsAttribute(Attribute<?> attribute)
- Parameters:
attribute
- the attribute- Returns:
- true if this entity definition contains the given attribute
-
attribute
<T> Attribute<T> attribute(String attributeName)
Returns the attribute with the given name, null if none is found.- Type Parameters:
T
- the attribute type- Parameters:
attributeName
- the name of the attribute to fetch- Returns:
- the attribute with the given name, null if none is found
-
searchAttributes
Collection<Attribute<String>> searchAttributes()
Returns the attributes to search by when searching for entities of this type by a string value- Returns:
- the attributes to use when searching by string
- See Also:
ColumnProperty.Builder.searchProperty(boolean)
-
defaultSelectAttributes
Collection<Attribute<?>> defaultSelectAttributes()
Returns the attributes selected by default for this entity type. Contains the selectable column property attributes and foreign keys, excluding lazy loaded blob attributes.- Returns:
- the default select attributes
-
columnProperty
<T> ColumnProperty<T> columnProperty(Attribute<T> attribute)
- Type Parameters:
T
- the attribute type- Parameters:
attribute
- the attribute- Returns:
- the column property associated with the attribute
- Throws:
IllegalArgumentException
- in case the attribute does not represent aColumnProperty
-
property
<T> Property<T> property(Attribute<T> attribute)
- Type Parameters:
T
- the attribute type- Parameters:
attribute
- the attribute- Returns:
- the property associated with
attribute
. - Throws:
IllegalArgumentException
- in case no such property exists
-
primaryKeyProperty
<T> ColumnProperty<T> primaryKeyProperty(Attribute<T> attribute)
- Type Parameters:
T
- the attribute type- Parameters:
attribute
- the attribute- Returns:
- the primary key property associated with
attribute
. - Throws:
IllegalArgumentException
- in case no such property exists
-
properties
List<Property<?>> properties(Collection<Attribute<?>> attributes)
Returns theProperty
s based on the given attributes- Parameters:
attributes
- the attributes which properties to retrieve- Returns:
- a list containing the properties based on the given attributes
-
columnProperties
List<ColumnProperty<?>> columnProperties(List<Attribute<?>> attributes)
Returns theColumnProperty
s based on the given attributes- Parameters:
attributes
- the attributes which properties to retrieve- Returns:
- a list of column properties
-
writableColumnProperties
List<ColumnProperty<?>> writableColumnProperties(boolean includePrimaryKeyProperties, boolean includeNonUpdatable)
Retrieves the writable (non-read-only) column properties comprising this entity type- Parameters:
includePrimaryKeyProperties
- if true primary key properties are included, non-updatable primary key properties are only included ifincludeNonUpdatable
is trueincludeNonUpdatable
- if true then non-updatable properties are included- Returns:
- a list containing the writable column properties (properties that map to database columns) comprising
the entity of type
entityType
-
updatableProperties
List<Property<?>> updatableProperties()
- Returns:
- a list containing all updatable properties associated with the given entityType
-
isUpdatable
boolean isUpdatable(ForeignKey foreignKey)
- Parameters:
foreignKey
- the foreign key- Returns:
- true if all the underlying properties are updatable
-
isForeignKeyAttribute
boolean isForeignKeyAttribute(Attribute<?> attribute)
- Parameters:
attribute
- the attribute- Returns:
- true if the given attribute is part of a foreign key
-
foreignKeys
List<ForeignKey> foreignKeys(EntityType referencedEntityType)
Returns the foreign keys referencing entities of the given type- Parameters:
referencedEntityType
- the referenced entity type- Returns:
- a List containing the foreign keys, an empty list is returned in case no foreign keys are found
-
foreignKeyProperty
ForeignKeyProperty foreignKeyProperty(ForeignKey foreignKey)
- Parameters:
foreignKey
- the foreign key- Returns:
- the ForeignKeyProperty based on the given foreign key
- Throws:
IllegalArgumentException
- in case no such property exists
-
foreignKeyProperties
<T> List<ForeignKeyProperty> foreignKeyProperties(Attribute<T> columnAttribute)
- Type Parameters:
T
- the attribute type- Parameters:
columnAttribute
- the column attribute- Returns:
- the ForeignKeyProperties based on the given column attribute
-
backgroundColorProvider
ColorProvider backgroundColorProvider()
Returns the background color provider, never null- Returns:
- the background color provider
-
foregroundColorProvider
ColorProvider foregroundColorProvider()
Returns the foreground color provider, never null- Returns:
- the foreground color provider
-
entity
Entity entity()
Creates a newEntity
instance based on this definition- Returns:
- a new
Entity
instance
-
entity
Entity entity(Map<Attribute<?>,Object> values)
Creates a newEntity
instance based on this definition- Parameters:
values
- the values- Returns:
- a new
Entity
instance - Throws:
IllegalArgumentException
- in case any of the value attributes are not part of the entity.
-
entity
Entity entity(Map<Attribute<?>,Object> values, Map<Attribute<?>,Object> originalValues)
Creates a newEntity
instance based on this definition- Parameters:
values
- the valuesoriginalValues
- the original values- Returns:
- a new
Entity
instance - Throws:
IllegalArgumentException
- in case any of the value attributes are not part of the entity.
-
primaryKey
<T> Key primaryKey(T value)
Creates a newKey
instance based on this definition, initialised with the given value- Type Parameters:
T
- the key value type- Parameters:
value
- the key value, assuming a single value key- Returns:
- a new
Key
instance - Throws:
IllegalStateException
- in case the given primary key is a composite keyIllegalArgumentException
- in case the value is not of the correct type
-
getterAttribute
Attribute<?> getterAttribute(Method method)
Returns the Attribute for the getter this method represents in theEntityType.entityClass()
, null if none exists.- Parameters:
method
- the method- Returns:
- the getter attribute
-
setterAttribute
Attribute<?> setterAttribute(Method method)
Returns the Attribute for the setter this method represents in theEntityType.entityClass()
, null if none exists.- Parameters:
method
- the method- Returns:
- the setter attribute
-
defaultMethodHandle
MethodHandle defaultMethodHandle(Method method)
Returns the MethodHandle for the given default method in theEntityType.entityClass()
.- Parameters:
method
- the method- Returns:
- a MethodHandle based on the method
-
serializationVersion
int serializationVersion()
Returns a serialization version indicator for the underlying entity. TwoEntityDefinition
s having the same version means they are (very likely) compatible when it comes to serialization.- Returns:
- a version indicator for the underlying entity
-
definition
static EntityDefinition.Builder definition(Property.Builder<?,?>... propertyBuilders)
Creates aEntityDefinition.Builder
instance based on the given property builders.- Parameters:
propertyBuilders
- builders for the properties comprising the entity- Returns:
- a
EntityDefinition.Builder
instance - Throws:
IllegalArgumentException
- in casepropertyBuilders
is empty
-
definition
static EntityDefinition.Builder definition(List<Property.Builder<?,?>> propertyBuilders)
Creates aEntityDefinition.Builder
instance based on the given property builders.- Parameters:
propertyBuilders
- builders for the properties comprising the entity- Returns:
- a
EntityDefinition.Builder
instance - Throws:
IllegalArgumentException
- in casepropertyBuilders
is empty
-
-