Class FieldDef
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.FieldDef
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,SchemaProblemsSupplier,JavaCodeGenerator,Serializable,Cloneable
- Direct Known Subclasses:
BinaryFieldDef,BooleanFieldDef,NumericFieldDef,RecordFieldDef,TemporalFieldDef,TextFieldDef,UuidFieldDef
The metadata structure of one column or property in 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 TypeMethodDescriptionThrows aDataExceptionif this object is invalid, otherwise returns it; the base implementation checks nothing.clone()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 fieldDefElement) protected voidgenerateConstructor(JavaCodeBuilder code, CodeWriter writer) Writes the constructor call that starts this field's generated Java code; subclasses override it to match their constructors.voidAppends Java source code representing this object to the given builder.ValueMatch<?> The optional set of values this field allows.User-defined key-value pairs to attached arbitrary metadata to this field.ExpressionThe calculated value to set in the data if the field is null or missing.The calculated value to set in the data if the field is null or missing.The human-readable summary of this field.The user-friendly name for this field.The user-friendly name for this field if one is set or thegetName()value otherwise.The parent entity containing this field.Returns the qualified name that includes the name of this field and theEntityDefabove it separated by period.A human-readable example of values supported by this field.intReturns the zero-based index of this field inEntityDef.The maximum numbers of array elements allowed by this array field.The minimum numbers of array elements allowed by this array field.getName()The human-readable text identifier for this field.The fully-qualified name for use in error and validation messages usinggetDisplayNameOrName()for each name segment.The zero-based location of this field in the data (if applicable).Returns the zero-based position of this field in its entity's primary key or null if it is not part of the key.Returns the strategy used to generate this primary key field's values or null if none is set.Returns the fully qualified name that includes the name of this field definition and all names in its hierarchy separated by period.The schema of the parent entity containing this field.getSchemaDef(boolean throwException) Returns the schema of the entity containing this field; if either is missing, throws aDataExceptionwhenthrowExceptionis true and returns null otherwise.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.getTags()The set of labels used to organize, filter, and classify this field.getType()The data type of this field.inthashCode()booleanisArray()Indicates if eithergetMinimumElements()orgetMaximumElements()are not null.booleanIndicates if values not itgetAllowedValues()are allowed.booleanReturnstrueifprimaryKeyPositionis not null.booleanIndicates if this field can be null or missing.booleanIndicates if arrays should be strictly handled as arrays (default/true) or if an array with one value can be treated and a non-array and vice-versa (false).final ObjectConverts a value to this field's type, using the default value expression when the value is null.protected ObjectmapValueImpl(Object value) Converts a single (non-array) value to this field's type; subclasses override it to parse or adjust values first.static FieldDefnewInstanceFromRecord(Record fieldDefRecord) Creates a field definition from its record form, picking the subclass by thetypefield; returns null if the type is missing or has no matching subclass.static FieldDefnewInstanceFromType(String type) Creates the field definition subclass for the givenFieldTypename (ignoring case) or returns null if the name is empty or the type has no matching subclass.static FieldDefnewInstanceFromXml(Element fieldDefElement) Creates a field definition from afieldelement, picking the subclass by itstypeattribute; returns null if the type is missing or has no matching subclass.setAllowedValues(ValueMatch<?> allowedValues) Sets the optional set of values this field allows; they are enforced only whenisLimitToAllowedValues()is true.setArray(boolean array) Forces this field to be an array by setting thegetMinimumElements()to zero (0) if bothgetMinimumElements()andgetMaximumElements()are null, otherwise, does nothing.setAttributes(Attributes attributes) Sets the user-defined key-value pairs attached to this field (null is treated as empty).setDefaultValueExpression(Expression defaultValueExpression) The calculated value to set in the data if the field is null or missing.setDescription(String description) setDisplayName(String displayName) Sets the user-friendly name for this field, used instead of the name in validation messages.protected FieldDefsetEntityDef(EntityDef entityDef) Sets the parent entity; called byEntityDefwhen this field is added to it.setExample(String example) setLimitToAllowedValues(boolean limitToAllowedValues) Indicates if values must be one ofgetAllowedValues()to pass validation (defaults to false).setMaximumElements(Integer maximumElements) Sets the maximum number of array elements allowed; a non-null value makes this field an array.setMinimumElements(Integer minimumElements) Sets the minimum number of array elements allowed; a non-null value makes this field an array.setPosition(Integer position) Sets the zero-based position of this field in the data or null to locate it by name; mapping renames the field found at this position to this field's name.setPrimaryKeyPosition(Integer primaryKeyPosition) Sets the zero-based position of this field in its entity's primary key or null if it is not part of the key.setPrimaryKeyType(PrimaryKeyType primaryKeyType) Sets the strategy used to generate this primary key field's values; a primary key position must also be set.setRequired(boolean required) Indicates if this field must be present and not null to pass validation (defaults to false).setStrictArrays(boolean strictArrays) Indicates if values must match this field's array setting exactly (defaults to true); when false, a single value and a one-element array are interchangeable.Sets the labels used to organize, filter, and classify this field (null is treated as empty).Sets the data type of this field; each subclass accepts only its own kind of type, such as numeric types forNumericFieldDef.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.protected voidvalidateAllowedValues(Object value, ValidationResult result) Adds an error ifisLimitToAllowedValues()is true and the value is not one of the allowed values.final ValidationResultvalidateField(Field field) Validates the given field against this definition, treating null as a missing field, and returns the errors found.final ValidationResultvalidateField(Field field, ValidationResult result) Validates the field likevalidateField(Field), adding errors to the given result (or a new one if null) and returning it.validateField(Record record) Validates this field in the given record, locating it bygetPosition()when set and by name otherwise.validateField(Record record, ValidationResult result) Validates this field in the record likevalidateField(Record), adding errors to the given result (or a new one if null) and returning it.final ValidationResultvalidateValue(Object value) Validates a Java value against this definition, treating arrays and collections as array values, and returns the errors found.final ValidationResultvalidateValue(Object value, ValidationResult result) Validates the value likevalidateValue(Object), adding errors to the given result (or a new one if null) and returning it.protected abstract voidvalidateValueImpl(Object value, ValidationResult result) Applies the subclass-specific checks to a single (non-array) value, adding any errors to the result; called after the common type, array and allowed-value checks.Methods inherited from class com.northconcepts.datapipeline.foundations.schema.SchemaPart
getSchemaName, getSchemaPartContainerName, getSchemaPartContainerTypeMethods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
addExceptionProperties, 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
-
FieldDef
public FieldDef() -
FieldDef
-
-
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
-
validateField
Validates this field in the given record, locating it bygetPosition()when set and by name otherwise. -
validateField
Validates this field in the record likevalidateField(Record), adding errors to the given result (or a new one if null) and returning it. -
validateField
Validates the given field against this definition, treating null as a missing field, and returns the errors found. -
validateField
Validates the field likevalidateField(Field), adding errors to the given result (or a new one if null) and returning it. -
assertValid
Description copied from class:FoundationObjectThrows aDataExceptionif this object is invalid, otherwise returns it; the base implementation checks nothing.- Overrides:
assertValidin classFoundationObject
-
validateValue
Validates a Java value against this definition, treating arrays and collections as array values, and returns the errors found. -
validateValue
Validates the value likevalidateValue(Object), adding errors to the given result (or a new one if null) and returning it. -
validateAllowedValues
Adds an error ifisLimitToAllowedValues()is true and the value is not one of the allowed values. -
validateValueImpl
Applies the subclass-specific checks to a single (non-array) value, adding any errors to the result; called after the common type, array and allowed-value checks.- Throws:
Throwable
-
mapValue
Converts a value to this field's type, using the default value expression when the value is null. Array fields return aListof converted elements; other fields convert only the first element of an array or collection. -
mapValueImpl
Converts a single (non-array) value to this field's type; subclasses override it to parse or adjust values first.- Throws:
Throwable
-
generateConstructor
Writes the constructor call that starts this field's generated Java code; subclasses override it to match their constructors. -
generateJavaCode
Description copied from interface:JavaCodeGeneratorAppends Java source code representing this object to the given builder.- Specified by:
generateJavaCodein interfaceJavaCodeGenerator
-
getEntityDef
The parent entity containing this field. -
setEntityDef
Sets the parent entity; called byEntityDefwhen this field is added to it. -
getSchemaDef
Returns the schema of the entity containing this field; if either is missing, throws aDataExceptionwhenthrowExceptionis true and returns null otherwise. -
getSchemaDef
The schema of the parent entity containing this field.- Specified by:
getSchemaDefin classSchemaPart
-
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 field. -
setName
-
getQualifiedName
Returns the fully qualified name that includes the name of this field definition and all names in its hierarchy separated by period. -
getEntityQualifiedName
Returns the qualified name that includes the name of this field and theEntityDefabove it separated by period. -
getDisplayName
The user-friendly name for this field. -
setDisplayName
Sets the user-friendly name for this field, used instead of the name in validation messages. -
getDisplayNameOrName
The user-friendly name for this field if one is set or thegetName()value otherwise. -
getNameForErrorMessage
The fully-qualified name for use in error and validation messages usinggetDisplayNameOrName()for each name segment. -
getDescription
The human-readable summary of this field. -
setDescription
-
getType
The data type of this field. -
setType
Sets the data type of this field; each subclass accepts only its own kind of type, such as numeric types forNumericFieldDef. -
isRequired
public boolean isRequired()Indicates if this field can be null or missing. -
setRequired
Indicates if this field must be present and not null to pass validation (defaults to false). -
getMinimumElements
The minimum numbers of array elements allowed by this array field. This field is treated as an array if either this property of thegetMaximumElements()property are not null. Negative values will be set to zero (0). -
setMinimumElements
Sets the minimum number of array elements allowed; a non-null value makes this field an array. Negative values are set to zero (0). -
getMaximumElements
The maximum numbers of array elements allowed by this array field. This field is treated as an array if either this property of thegetMinimumElements()property are not null. Negative values will be set to the max integer (2147483647). Zero (0) is allowed, it means the array must always be empty. -
setMaximumElements
Sets the maximum number of array elements allowed; a non-null value makes this field an array. Negative values are set to the max integer and zero (0) means the array must be empty. -
isArray
public boolean isArray()Indicates if eithergetMinimumElements()orgetMaximumElements()are not null. -
setArray
Forces this field to be an array by setting thegetMinimumElements()to zero (0) if bothgetMinimumElements()andgetMaximumElements()are null, otherwise, does nothing. -
isStrictArrays
public boolean isStrictArrays()Indicates if arrays should be strictly handled as arrays (default/true) or if an array with one value can be treated and a non-array and vice-versa (false). Most developers will want to leave this set to the default (true). -
setStrictArrays
Indicates if values must match this field's array setting exactly (defaults to true); when false, a single value and a one-element array are interchangeable. -
isLimitToAllowedValues
public boolean isLimitToAllowedValues()Indicates if values not itgetAllowedValues()are allowed. -
setLimitToAllowedValues
Indicates if values must be one ofgetAllowedValues()to pass validation (defaults to false). -
getAllowedValues
The optional set of values this field allows. TheisLimitToAllowedValues()property indicates if other values can be set. -
setAllowedValues
Sets the optional set of values this field allows; they are enforced only whenisLimitToAllowedValues()is true. -
getPosition
The zero-based location of this field in the data (if applicable). This can be used to name previously unnamed fields based on their position (or override the names of already named fields). -
setPosition
Sets the zero-based position of this field in the data or null to locate it by name; mapping renames the field found at this position to this field's name. -
getDefaultValueExpression
public Expression getDefaultValueExpression()The calculated value to set in the data if the field is null or missing. -
getDefaultValueExpressionAsString
The calculated value to set in the data if the field is null or missing. -
setDefaultValueExpression
The calculated value to set in the data if the field is null or missing. -
getExample
A human-readable example of values supported by this field. A "country" field might have "Japan" as an example. -
setExample
-
getAttributes
User-defined key-value pairs to attached arbitrary metadata to this field. -
setAttributes
Sets the user-defined key-value pairs attached to this field (null is treated as empty). -
getTags
The set of labels used to organize, filter, and classify this field. -
setTags
Sets the labels used to organize, filter, and classify this field (null is treated as empty). -
getPrimaryKeyPosition
Returns the zero-based position of this field in its entity's primary key or null if it is not part of the key. -
setPrimaryKeyPosition
Sets the zero-based position of this field in its entity's primary key or null if it is not part of the key. -
isPrimaryKey
public boolean isPrimaryKey()ReturnstrueifprimaryKeyPositionis not null. -
getPrimaryKeyType
Returns the strategy used to generate this primary key field's values or null if none is set. -
setPrimaryKeyType
Sets the strategy used to generate this primary key field's values; a primary key position must also be set. -
getIndexInEntityDef
public int getIndexInEntityDef()Returns the zero-based index of this field inEntityDef. -
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
-
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
-
newInstanceFromType
Creates the field definition subclass for the givenFieldTypename (ignoring case) or returns null if the name is empty or the type has no matching subclass. -
newInstanceFromXml
Creates a field definition from afieldelement, picking the subclass by itstypeattribute; returns null if the type is missing or has no matching subclass. -
newInstanceFromRecord
Creates a field definition from its record form, picking the subclass by thetypefield; returns null if the type is missing or has no matching subclass. -
hashCode
public int hashCode() -
equals
-