Class EntityDef
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.core.FoundationObject
com.northconcepts.datapipeline.foundations.schema.SchemaObject
com.northconcepts.datapipeline.foundations.schema.SchemaPart
com.northconcepts.datapipeline.foundations.schema.EntityDef
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,SchemaProblemsSupplier,JavaCodeGenerator,Serializable,Cloneable
The metadata structure defining a file, JSON object, database table, or class for validation and mapping.
- See Also:
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
internalId, internalName, log, TIMESTAMP_FORMATFields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPEFields inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
XML_SERIALIZED_CLASS_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the field and makes this entity its parent.Appends the index and makes this entity its parent.addValidation(Filter validation) Adds a filter that records must pass during validation; each rejected record gets an error.addValidation(String validationExpression) Adds a validation rule from a logical expression (parsed as aFilterExpression) that records must satisfy.clone()booleancontainsField(String name) Returns true if this entity contains aFieldDefwith the specifiedname.booleancontainsIndex(String name) Returns true if this entity contains anIndexDefwith the specifiedname.booleancontainsInheritedField(String name) Returns true if this entity or any of its super entities contains aFieldDefwith the specifiedname.booleancontainsInheritedIndex(String name) Returns true if this entity or any of its super entities contains anIndexDefwith the specifiedname.Creates a record with a typed null (or an empty array for array fields) for each field of this entity and its super entities.booleanLoads this object's state from the given JSON text.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXmlElement(Element entityDefElement) voidAppends Java source code representing this object to the given builder.User-defined key-value pairs to attached arbitrary metadata to this entity.The human-readable summary of this entity.Returns theFieldDefthat matches the specified name.intReturns the number of fields declared in this entity, excluding inherited ones.Returns the names of the fields declared in this entity, excluding inherited ones.Returns the fields declared in this entity (excluding inherited ones) or null if none were added.getFields(boolean create) Returns the fields declared in this entity, creating the list if it is null andcreateis true.Returns this entity's own fields whose name matches the given name, ignoring case; empty if none match or the name is empty.Returns the first of this entity's own indexes whose name matches, ignoring case, or null if none does.intReturns the number of indexes in this entity.Returns the indexes declared in this entity (excluding inherited ones) or null if none were added.getIndexes(boolean create) Returns the indexes declared in this entity, creating the list if it is null andcreateis true.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.Returns the names of all indexes in this entity.intReturns the number of fields in this entity and its super entities, counting overridden super fields too.Returns the fields in this entity and its super entities with overridden super fields removed.getInheritedFields(boolean excludeOverriddenFields) Returns the fields in this entity and its super entities, optionally removing overridden super fields.getInheritedFields(List<FieldDef> result, boolean excludeOverriddenFields) Returns the fields in this entity and its super entities, optionally removing overridden super fields.intReturns the number of indexes in this entity and its super entities.getName()The human-readable text identifier for this entity.Returns the names of this entity's own primary key fields (not inherited ones) ordered by their primary key position.Returns this entity's own primary key fields (not inherited ones) ordered by their primary key position.Returns the fully qualified name that includes the name of this entity and all names in its hierarchy separated by period.The parent schema this entity belongs to.Returns the schema part containing this one or null if there is none.Returns the name identifying this part, such as an entity's name or an index field's field name.Returns the kind of part this is, such asSchemaPartType.ENTITY.voidgetSchemaProblems(List<SchemaProblem> problems, boolean includeChildren) Adds this element's problems to the list, plus those of its children whenincludeChildrenis true; the default adds none.Returns the parent entity this entity inherits from (a superclass in object-oriented programming).Returns the name of the parent entity this entity inherits from (a superclass in object-oriented programming).getTags()The set of labels used to organize, filter, and classify this entity.The list of arbitrary validations associated with this entity.getValidations(boolean create) Returns the validation rules, creating the list if it is null andcreateis true.The list oftoString()results from all filters.booleanReturns true if more than one of this entity's own fields is part of its primary key.inthashCode()intindexOfField(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.intindexOfField(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 andthrowExceptionOnFailureis false, otherwise aDataExceptionis thrown.intindexOfIndex(String indexName) Returns the zero-based position of theIndexDefwith the specified name or -1 if it is not found.intindexOfIndex(String indexName, boolean throwExceptionOnFailure) Returns the zero-based position of theIndexDefwith the specified name or -1 if it is not found andthrowExceptionOnFailureis false, otherwise aDataExceptionis thrown.booleanIndicates if data mapping should add optional fields in this entity that are not present in the data (doesn't apply during validation).booleanIndicates if data mapping should fail when the data contains fields not present in this entity (doesn't apply during validation).booleanIndicates if data validation should fail when the data contains fields not present in this entity (doesn't apply during mapping ).final ValidationResultmapAndValidateRecord(Record record) Maps the record in place withmapRecord(Record)and then validates it; if mapping fails, validation runs on a copy without the fields that failed to map.final ValidationResultmapAndValidateRecord(Record record, ValidationResult result) Maps and validates the record likemapAndValidateRecord(Record), adding errors to the given result (or a new one if null) and returning it.final ValidationResultConverts 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.final ValidationResultmapRecord(Record record, ValidationResult result) Maps the record likemapRecord(Record), adding errors to the given result (or a new one if null) and returning it.voidmoveField(int oldIndex, int newIndex) Moves the field at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right.voidMoves the field with the given name to thenewIndex, shifting any existing elements at or afternewIndexto the right.voidmoveFieldAfter(String fieldName, String afterFieldName) Moves the field with the givenfieldNameafter to the field with the specifiedafterFieldName, shifting any existing elements afterafterFieldNameto the right.voidmoveFieldBefore(String fieldName, String beforeFieldName) Moves the field with the givenfieldNamebefore to the field with the specifiedbeforeFieldName, shifting elements at or afterbeforeFieldNameto the right.voidmoveIndex(int oldIndex, int newIndex) Moves the index at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right.voidMoves the index with the given name to thenewIndex, shifting any existing elements at or afternewIndexto the right.voidmoveIndexAfter(String indexName, String afterIndexName) Moves the index with the givenindexNameafter to the index with the specifiedafterIndexName, shifting any existing elements afterafterIndexNameto the right.voidmoveIndexBefore(String indexName, String beforeIndexName) Moves the index with the givenindexNamebefore to the index with the specifiedbeforeIndexName, shifting elements at or afterbeforeIndexNameto the right.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).setAllowExtraFieldsInMapping(boolean allowExtraFieldsInMapping) Indicates if records may contain fields not defined in this entity without failing mapping (defaults to true).setAllowExtraFieldsInValidation(boolean allowExtraFieldsInValidation) Indicates if records may contain fields not defined in this entity without failing validation (defaults to true).setAttributes(Attributes attributes) Sets the user-defined key-value pairs attached to this entity (null is treated as empty).setDescription(String description) Replaces the fields with the given list (not copied) and makes this entity their parent.setIndexes(List<IndexDef> indexes) Replaces the indexes with the given list (not copied) and makes this entity their parent.protected EntityDefsetSchemaDef(SchemaDef schemaDef) Sets the parent schema; called bySchemaDefwhen this entity is added to it.setSuperEntityName(String superEntityName) Sets the name of the parent entity this entity inherits from (a superclass in object-oriented programming).Sets the labels used to organize, filter, and classify this entity (null is treated as empty).setValidations(List<Filter> validations) Sets the filters that records must pass during validation.toJson()toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.toXmlElement(Document document) Returns an element, created withdocument, describing this object; the default implementation throws aDataException.final ValidationResultvalidateRecord(Record record) Checks the record, without changing it, against this entity's fields (including inherited ones) and validation rules; returns the errors found.final ValidationResultvalidateRecord(Record record, ValidationResult result) Validates the record likevalidateRecord(Record), adding errors to the given result (or a new one if null) and returning it.Methods inherited from class com.northconcepts.datapipeline.foundations.schema.SchemaPart
getSchemaName, getSchemaPartContainerName, getSchemaPartContainerTypeMethods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
addExceptionProperties, assertValid, assertValid, exception, exception, exception, getInternalId, getInternalName, resetInternalIdMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionPropertiesMethods inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
fromJson, toJson, toJsonMethods inherited from interface com.northconcepts.datapipeline.foundations.schema.SchemaProblemsSupplier
getSchemaProblems, getSchemaProblems
-
Constructor Details
-
EntityDef
public EntityDef() -
EntityDef
-
-
Method Details
-
getSchemaProblems
Description copied from interface:SchemaProblemsSupplierAdds this element's problems to the list, plus those of its children whenincludeChildrenis true; the default adds none.- Specified by:
getSchemaProblemsin interfaceSchemaProblemsSupplier
-
clone
- Overrides:
clonein classFoundationObject
-
mapAndValidateRecord
Maps the record in place withmapRecord(Record)and then validates it; if mapping fails, validation runs on a copy without the fields that failed to map. -
mapAndValidateRecord
Maps and validates the record likemapAndValidateRecord(Record), adding errors to the given result (or a new one if null) and returning it. -
mapRecord
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
Maps the record likemapRecord(Record), adding errors to the given result (or a new one if null) and returning it. -
validateRecord
Checks the record, without changing it, against this entity's fields (including inherited ones) and validation rules; returns the errors found. -
validateRecord
Validates the record likevalidateRecord(Record), adding errors to the given result (or a new one if null) and returning it. -
generateJavaCode
Description copied from interface:JavaCodeGeneratorAppends Java source code representing this object to the given builder.- Specified by:
generateJavaCodein interfaceJavaCodeGenerator
-
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:
getSchemaDefin classSchemaPart
-
setSchemaDef
Sets the parent schema; called bySchemaDefwhen this entity is added to it. -
getSchemaPartContainer
Description copied from class:SchemaPartReturns the schema part containing this one or null if there is none.- Specified by:
getSchemaPartContainerin classSchemaPart
-
getSchemaPartType
Description copied from class:SchemaPartReturns the kind of part this is, such asSchemaPartType.ENTITY.- Specified by:
getSchemaPartTypein classSchemaPart
-
getSchemaPartName
Description copied from class:SchemaPartReturns the name identifying this part, such as an entity's name or an index field's field name.- Specified by:
getSchemaPartNamein classSchemaPart
-
getName
The human-readable text identifier for this entity. -
setName
-
getQualifiedName
Returns the fully qualified name that includes the name of this entity and all names in its hierarchy separated by period. -
getDescription
The human-readable summary of this entity. -
setDescription
-
getSuperEntityName
Returns the name of the parent entity this entity inherits from (a superclass in object-oriented programming). -
setSuperEntityName
Sets the name of the parent entity this entity inherits from (a superclass in object-oriented programming). -
getSuperEntity
Returns the parent entity this entity inherits from (a superclass in object-oriented programming). -
getPrimaryKeyFields
Returns this entity's own primary key fields (not inherited ones) ordered by their primary key position. -
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
Returns the names of the fields declared in this entity, excluding inherited ones. -
getFields
Returns the fields declared in this entity, creating the list if it is null andcreateis true. -
getInheritedFields
Returns the fields in this entity and its super entities with overridden super fields removed. -
getInheritedFields
Returns the fields in this entity and its super entities, optionally removing overridden super fields. -
getInheritedFields
Returns the fields in this entity and its super entities, optionally removing overridden super fields. -
getFields
Returns the fields declared in this entity (excluding inherited ones) or null if none were added. -
setFields
Replaces the fields with the given list (not copied) and makes this entity their parent. -
addField
Appends the field and makes this entity its parent. -
indexOfField
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
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 andthrowExceptionOnFailureis false, otherwise aDataExceptionis thrown. -
indexOfIndex
Returns the zero-based position of theIndexDefwith the specified name or -1 if it is not found. -
indexOfIndex
Returns the zero-based position of theIndexDefwith the specified name or -1 if it is not found andthrowExceptionOnFailureis false, otherwise aDataExceptionis thrown. -
containsInheritedField
Returns true if this entity or any of its super entities contains aFieldDefwith the specifiedname. -
containsField
Returns true if this entity contains aFieldDefwith the specifiedname. -
containsInheritedIndex
Returns true if this entity or any of its super entities contains anIndexDefwith the specifiedname. -
containsIndex
Returns true if this entity contains anIndexDefwith the specifiedname. -
hasCompositePrimaryKeys
public boolean hasCompositePrimaryKeys()Returns true if more than one of this entity's own fields is part of its primary key. -
getField
Returns theFieldDefthat matches the specified name. -
getFields
Returns this entity's own fields whose name matches the given name, ignoring case; empty if none match or the name is empty. -
getValidations
The list of arbitrary validations associated with this entity. -
getValidationsSource
The list oftoString()results from all filters.- Returns:
-
getValidations
Returns the validation rules, creating the list if it is null andcreateis true. -
setValidations
Sets the filters that records must pass during validation. -
addValidation
Adds a validation rule from a logical expression (parsed as aFilterExpression) that records must satisfy. -
addValidation
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
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
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
Indicates if mapping adds missing fields that have no default value to the record as nulls or empty arrays (defaults to false). -
getAttributes
User-defined key-value pairs to attached arbitrary metadata to this entity. -
setAttributes
Sets the user-defined key-value pairs attached to this entity (null is treated as empty). -
getTags
The set of labels used to organize, filter, and classify this entity. -
setTags
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
Returns the names of all indexes in this entity. -
getIndexes
Returns the indexes declared in this entity, creating the list if it is null andcreateis true. -
getIndexes
Returns the indexes declared in this entity (excluding inherited ones) or null if none were added. -
setIndexes
Replaces the indexes with the given list (not copied) and makes this entity their parent. -
addIndex
Appends the index and makes this entity its parent. -
getIndex
Returns the first of this entity's own indexes whose name matches, ignoring case, or null if none does. -
getIndexes
Returns this entity's own indexes whose name matches the given name, ignoring case; empty if none match or the name is empty. -
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
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException.- Specified by:
toXmlElementin interfaceXmlSerializable
-
fromXmlElement
- Specified by:
fromXmlElementin interfaceXmlSerializable
-
toJson
- Specified by:
toJsonin interfaceJsonSerializable- Specified by:
toJsonin interfaceRecordSerializable
-
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable- Overrides:
toRecordin classBean
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Overrides:
fromRecordin classBean- Parameters:
source-- Returns:
- this instance.
-
fromJson
Description copied from interface:JsonSerializableLoads this object's state from the given JSON text.- Specified by:
fromJsonin interfaceJsonSerializable- Specified by:
fromJsonin interfaceRecordSerializable
-
hashCode
public int hashCode() -
equals
-
moveField
public void moveField(int oldIndex, int newIndex) Moves the field at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right. -
moveField
Moves the field with the given name to thenewIndex, shifting any existing elements at or afternewIndexto the right. -
moveFieldBefore
Moves the field with the givenfieldNamebefore to the field with the specifiedbeforeFieldName, shifting elements at or afterbeforeFieldNameto the right. -
moveFieldAfter
Moves the field with the givenfieldNameafter to the field with the specifiedafterFieldName, shifting any existing elements afterafterFieldNameto the right. -
moveIndex
public void moveIndex(int oldIndex, int newIndex) Moves the index at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right. -
moveIndex
Moves the index with the given name to thenewIndex, shifting any existing elements at or afternewIndexto the right. -
moveIndexBefore
Moves the index with the givenindexNamebefore to the index with the specifiedbeforeIndexName, shifting elements at or afterbeforeIndexNameto the right. -
moveIndexAfter
Moves the index with the givenindexNameafter to the index with the specifiedafterIndexName, shifting any existing elements afterafterIndexNameto the right.
-