All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, SchemaProblemsSupplier, JavaCodeGenerator, Serializable, Cloneable

public class EntityDef extends SchemaPart implements Cloneable, SchemaProblemsSupplier
The metadata structure defining a file, JSON object, database table, or class for validation and mapping.
See Also:
  • Constructor Details

    • EntityDef

      public EntityDef()
    • EntityDef

      public EntityDef(String name)
  • Method Details

    • getSchemaProblems

      public void getSchemaProblems(List<SchemaProblem> problems, boolean includeChildren)
      Description copied from interface: SchemaProblemsSupplier
      Adds this element's problems to the list, plus those of its children when includeChildren is true; the default adds none.
      Specified by:
      getSchemaProblems in interface SchemaProblemsSupplier
    • clone

      public EntityDef clone()
      Overrides:
      clone in class FoundationObject
    • mapAndValidateRecord

      public final ValidationResult mapAndValidateRecord(Record record)
      Maps the record in place with mapRecord(Record) and then validates it; if mapping fails, validation runs on a copy without the fields that failed to map.
    • mapAndValidateRecord

      public final ValidationResult mapAndValidateRecord(Record record, ValidationResult result)
      Maps and validates the record like mapAndValidateRecord(Record), adding errors to the given result (or a new one if null) and returning it.
    • mapRecord

      public final ValidationResult mapRecord(Record record)
      Converts the record's values in place to the types of this entity's fields, including inherited ones, and applies default values; mapping errors are returned instead of thrown.
    • mapRecord

      public final ValidationResult mapRecord(Record record, ValidationResult result)
      Maps the record like mapRecord(Record), adding errors to the given result (or a new one if null) and returning it.
    • validateRecord

      public final ValidationResult validateRecord(Record record)
      Checks the record, without changing it, against this entity's fields (including inherited ones) and validation rules; returns the errors found.
    • validateRecord

      public final ValidationResult validateRecord(Record record, ValidationResult result)
      Validates the record like validateRecord(Record), adding errors to the given result (or a new one if null) and returning it.
    • generateJavaCode

      public void generateJavaCode(JavaCodeBuilder code)
      Description copied from interface: JavaCodeGenerator
      Appends Java source code representing this object to the given builder.
      Specified by:
      generateJavaCode in interface JavaCodeGenerator
    • getSchemaDef

      public SchemaDef getSchemaDef()
      The parent schema this entity belongs to. The parent schema link is automatically created when this entity is added to a schema.
      Specified by:
      getSchemaDef in class SchemaPart
    • setSchemaDef

      protected EntityDef setSchemaDef(SchemaDef schemaDef)
      Sets the parent schema; called by SchemaDef when this entity is added to it.
    • getSchemaPartContainer

      public SchemaPart getSchemaPartContainer()
      Description copied from class: SchemaPart
      Returns the schema part containing this one or null if there is none.
      Specified by:
      getSchemaPartContainer in class SchemaPart
    • getSchemaPartType

      public SchemaPartType getSchemaPartType()
      Description copied from class: SchemaPart
      Returns the kind of part this is, such as SchemaPartType.ENTITY.
      Specified by:
      getSchemaPartType in class SchemaPart
    • getSchemaPartName

      public String getSchemaPartName()
      Description copied from class: SchemaPart
      Returns the name identifying this part, such as an entity's name or an index field's field name.
      Specified by:
      getSchemaPartName in class SchemaPart
    • getName

      public String getName()
      The human-readable text identifier for this entity.
    • setName

      public EntityDef setName(String name)
    • getQualifiedName

      public String getQualifiedName()
      Returns the fully qualified name that includes the name of this entity and all names in its hierarchy separated by period.
    • getDescription

      public String getDescription()
      The human-readable summary of this entity.
    • setDescription

      public EntityDef setDescription(String description)
    • getSuperEntityName

      public String getSuperEntityName()
      Returns the name of the parent entity this entity inherits from (a superclass in object-oriented programming).
    • setSuperEntityName

      public EntityDef setSuperEntityName(String superEntityName)
      Sets the name of the parent entity this entity inherits from (a superclass in object-oriented programming).
    • getSuperEntity

      public EntityDef getSuperEntity()
      Returns the parent entity this entity inherits from (a superclass in object-oriented programming).
    • getPrimaryKeyFields

      public List<FieldDef> getPrimaryKeyFields()
      Returns this entity's own primary key fields (not inherited ones) ordered by their primary key position.
    • getPrimaryKeyFieldNames

      public List<String> getPrimaryKeyFieldNames()
      Returns the names of this entity's own primary key fields (not inherited ones) ordered by their primary key position.
    • getInheritedFieldCount

      public int getInheritedFieldCount()
      Returns the number of fields in this entity and its super entities, counting overridden super fields too.
    • getFieldCount

      public int getFieldCount()
      Returns the number of fields declared in this entity, excluding inherited ones.
    • getFieldNames

      public List<String> getFieldNames()
      Returns the names of the fields declared in this entity, excluding inherited ones.
    • getFields

      public List<FieldDef> getFields(boolean create)
      Returns the fields declared in this entity, creating the list if it is null and create is true.
    • getInheritedFields

      public List<FieldDef> getInheritedFields()
      Returns the fields in this entity and its super entities with overridden super fields removed.
    • getInheritedFields

      public List<FieldDef> getInheritedFields(boolean excludeOverriddenFields)
      Returns the fields in this entity and its super entities, optionally removing overridden super fields.
    • getInheritedFields

      public List<FieldDef> getInheritedFields(List<FieldDef> result, boolean excludeOverriddenFields)
      Returns the fields in this entity and its super entities, optionally removing overridden super fields.
    • getFields

      public List<FieldDef> getFields()
      Returns the fields declared in this entity (excluding inherited ones) or null if none were added.
    • setFields

      public EntityDef setFields(List<FieldDef> fields)
      Replaces the fields with the given list (not copied) and makes this entity their parent.
    • addField

      public EntityDef addField(FieldDef field)
      Appends the field and makes this entity its parent.
    • indexOfField

      public int indexOfField(String fieldName)
      Returns the zero-based position of the field with the specified name (ignoring case) among this entity's own fields or -1 if it is not found.
    • indexOfField

      public int indexOfField(String fieldName, boolean throwExceptionOnFailure)
      Returns the zero-based position of the field with the specified name (ignoring case) among this entity's own fields or -1 if it is not found and throwExceptionOnFailure is false, otherwise a DataException is thrown.
    • indexOfIndex

      public int indexOfIndex(String indexName)
      Returns the zero-based position of the IndexDef with the specified name or -1 if it is not found.
    • indexOfIndex

      public int indexOfIndex(String indexName, boolean throwExceptionOnFailure)
      Returns the zero-based position of the IndexDef with the specified name or -1 if it is not found and throwExceptionOnFailure is false, otherwise a DataException is thrown.
    • containsInheritedField

      public boolean containsInheritedField(String name)
      Returns true if this entity or any of its super entities contains a FieldDef with the specified name.
    • containsField

      public boolean containsField(String name)
      Returns true if this entity contains a FieldDef with the specified name.
    • containsInheritedIndex

      public boolean containsInheritedIndex(String name)
      Returns true if this entity or any of its super entities contains an IndexDef with the specified name.
    • containsIndex

      public boolean containsIndex(String name)
      Returns true if this entity contains an IndexDef with the specified name.
    • hasCompositePrimaryKeys

      public boolean hasCompositePrimaryKeys()
      Returns true if more than one of this entity's own fields is part of its primary key.
    • getField

      public FieldDef getField(String name)
      Returns the FieldDef that matches the specified name.
    • getFields

      public List<FieldDef> getFields(String name)
      Returns this entity's own fields whose name matches the given name, ignoring case; empty if none match or the name is empty.
    • getValidations

      public List<Filter> getValidations()
      The list of arbitrary validations associated with this entity.
    • getValidationsSource

      public List<String> getValidationsSource()
      The list of toString() results from all filters.
      Returns:
    • getValidations

      public List<Filter> getValidations(boolean create)
      Returns the validation rules, creating the list if it is null and create is true.
    • setValidations

      public EntityDef setValidations(List<Filter> validations)
      Sets the filters that records must pass during validation.
    • addValidation

      public EntityDef addValidation(String validationExpression)
      Adds a validation rule from a logical expression (parsed as a FilterExpression) that records must satisfy.
    • addValidation

      public EntityDef addValidation(Filter validation)
      Adds a filter that records must pass during validation; each rejected record gets an error.
    • isAllowExtraFieldsInValidation

      public boolean isAllowExtraFieldsInValidation()
      Indicates if data validation should fail when the data contains fields not present in this entity (doesn't apply during mapping ).
    • setAllowExtraFieldsInValidation

      public EntityDef setAllowExtraFieldsInValidation(boolean allowExtraFieldsInValidation)
      Indicates if records may contain fields not defined in this entity without failing validation (defaults to true). When false, missing fields are reported too.
    • isAllowExtraFieldsInMapping

      public boolean isAllowExtraFieldsInMapping()
      Indicates if data mapping should fail when the data contains fields not present in this entity (doesn't apply during validation).
    • setAllowExtraFieldsInMapping

      public EntityDef setAllowExtraFieldsInMapping(boolean allowExtraFieldsInMapping)
      Indicates if records may contain fields not defined in this entity without failing mapping (defaults to true).
    • isAddMissingOptionalFields

      public boolean isAddMissingOptionalFields()
      Indicates if data mapping should add optional fields in this entity that are not present in the data (doesn't apply during validation).
    • setAddMissingOptionalFields

      public EntityDef setAddMissingOptionalFields(boolean addMissingOptionalFields)
      Indicates if mapping adds missing fields that have no default value to the record as nulls or empty arrays (defaults to false).
    • getAttributes

      public Attributes getAttributes()
      User-defined key-value pairs to attached arbitrary metadata to this entity.
    • setAttributes

      public EntityDef setAttributes(Attributes attributes)
      Sets the user-defined key-value pairs attached to this entity (null is treated as empty).
    • getTags

      public Tags getTags()
      The set of labels used to organize, filter, and classify this entity.
    • setTags

      public EntityDef setTags(Tags tags)
      Sets the labels used to organize, filter, and classify this entity (null is treated as empty).
    • getInheritedIndexCount

      public int getInheritedIndexCount()
      Returns the number of indexes in this entity and its super entities.
    • getIndexCount

      public int getIndexCount()
      Returns the number of indexes in this entity.
    • getIndexNames

      public List<String> getIndexNames()
      Returns the names of all indexes in this entity.
    • getIndexes

      public List<IndexDef> getIndexes(boolean create)
      Returns the indexes declared in this entity, creating the list if it is null and create is true.
    • getIndexes

      public List<IndexDef> getIndexes()
      Returns the indexes declared in this entity (excluding inherited ones) or null if none were added.
    • setIndexes

      public EntityDef setIndexes(List<IndexDef> indexes)
      Replaces the indexes with the given list (not copied) and makes this entity their parent.
    • addIndex

      public EntityDef addIndex(IndexDef index)
      Appends the index and makes this entity its parent.
    • getIndex

      public IndexDef getIndex(String name)
      Returns the first of this entity's own indexes whose name matches, ignoring case, or null if none does.
    • getIndexes

      public List<IndexDef> getIndexes(String name)
      Returns this entity's own indexes whose name matches the given name, ignoring case; empty if none match or the name is empty.
    • createEmptyRecord

      public Record createEmptyRecord()
      Creates a record with a typed null (or an empty array for array fields) for each field of this entity and its super entities.
    • toXmlElement

      public Element toXmlElement(Document document)
      Description copied from interface: XmlSerializable
      Returns an element, created with document, describing this object; the default implementation throws a DataException.
      Specified by:
      toXmlElement in interface XmlSerializable
    • fromXmlElement

      public EntityDef fromXmlElement(Element entityDefElement)
      Specified by:
      fromXmlElement in interface XmlSerializable
    • toJson

      public String toJson()
      Specified by:
      toJson in interface JsonSerializable
      Specified by:
      toJson in interface RecordSerializable
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
      Overrides:
      toRecord in class Bean
    • fromRecord

      public EntityDef fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Overrides:
      fromRecord in class Bean
      Parameters:
      source -
      Returns:
      this instance.
    • fromJson

      public EntityDef fromJson(String jsonString)
      Description copied from interface: JsonSerializable
      Loads this object's state from the given JSON text.
      Specified by:
      fromJson in interface JsonSerializable
      Specified by:
      fromJson in interface RecordSerializable
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • moveField

      public void moveField(int oldIndex, int newIndex)
      Moves the field at the oldIndex to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveField

      public void moveField(String fieldName, int newIndex)
      Moves the field with the given name to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveFieldBefore

      public void moveFieldBefore(String fieldName, String beforeFieldName)
      Moves the field with the given fieldName before to the field with the specified beforeFieldName, shifting elements at or after beforeFieldName to the right.
    • moveFieldAfter

      public void moveFieldAfter(String fieldName, String afterFieldName)
      Moves the field with the given fieldName after to the field with the specified afterFieldName, shifting any existing elements after afterFieldName to the right.
    • moveIndex

      public void moveIndex(int oldIndex, int newIndex)
      Moves the index at the oldIndex to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveIndex

      public void moveIndex(String indexName, int newIndex)
      Moves the index with the given name to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveIndexBefore

      public void moveIndexBefore(String indexName, String beforeIndexName)
      Moves the index with the given indexName before to the index with the specified beforeIndexName, shifting elements at or after beforeIndexName to the right.
    • moveIndexAfter

      public void moveIndexAfter(String indexName, String afterIndexName)
      Moves the index with the given indexName after to the index with the specified afterIndexName, shifting any existing elements after afterIndexName to the right.