Interface EntityDefinition


  • public interface EntityDefinition
    Specifies an entity definition.
    • 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 the ConditionProvider 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
      • 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
      • setSelectQuery

        SelectQuery setSelectQuery()
        Returns:
        the select query to use when selecting entities of this type
      • 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
      • properties

        List<Property<?>> properties()
        Returns:
        an unmodifiable list view of the properties
      • 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
      • referencedEntityDefinition

        EntityDefinition referencedEntityDefinition​(ForeignKey foreignKey)
        Returns the EntityDefinition 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
      • 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 a ColumnProperty
      • 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 the Propertys 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 the ColumnPropertys 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 if includeNonUpdatable is true
        includeNonUpdatable - 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
      • 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 new Entity instance based on this definition
        Returns:
        a new Entity instance
      • primaryKey

        <T> Key primaryKey​(T value)
        Creates a new Key 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 key
        IllegalArgumentException - 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 the EntityType.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 the EntityType.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 the EntityType.entityClass().
        Parameters:
        method - the method
        Returns:
        a MethodHandle based on the method
      • serializationVersion

        int serializationVersion()
        Returns a serialization version indicator for the underlying entity. Two EntityDefinitions having the same version means they are (very likely) compatible when it comes to serialization.
        Returns:
        a version indicator for the underlying entity