- java.lang.Object
-
- org.tentackle.model.impl.AttributeImpl
-
- All Implemented Interfaces:
Comparable<AttributeImpl>,Attribute,ModelElement
public class AttributeImpl extends Object implements Attribute, Comparable<AttributeImpl>
Attribute implementation.- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description AttributeImpl(EntityFactoryImpl factory, Entity entity, SourceInfo sourceInfo, boolean implicit)Creates an attribute.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(AttributeImpl o)ModelExceptioncreateModelException(String message)Creates a model exception.booleanequals(Object obj)StringgetApplicationTypeName()Gets the name of the application specific type, if a Convertible type.StringgetBindableAnnotation()Returns the @Bindable-annotation text.StringgetColumnName()Gets the column name.
This is the model's column name.
According to theDataType, an attribute may be mapped to more than one database column.StringgetColumnName(int columnIndex)Gets the database column name.
For datatype with only one column, this is usually the same as the model's column name.DataType<?>getDataType()Gets the model's data type.DataType<?>getEffectiveDataType()Gets the effective type exposed to the backend.
If this is an application specific type, the inner type will be returned.EntitygetEntity()Gets the entity this attribute belongs to.StringgetGetterName()Gets the getter method name.DataType<?>getInnerDataType()Gets the inner datatype exposed to the backend if Convertible.StringgetInnerTypeName()Gets the inner type name.
This is either the generic inner type or the wrapped type of Convertible types.StringgetJavaType()Gets the java type.
Returns the java type with optional generic info.StringgetMethodNameSuffix()Gets the suffix to be used in methodnames.StringgetName()Gets the name of the element.AttributeOptionsImplgetOptions()Gets the options.intgetOrdinal()Gets the ordinal along the inheritance path.ModelElementgetParent()Gets the parent element.RelationgetRelation()Gets the associated relation.IntegergetScale()Gets the scale for numbers with a fraction part.StringgetSetterName()Gets the setter method name.IntegergetSize()Gets the column width.SourceInfogetSourceInfo()Gets the information about the source where this element is defined.AttributeLinegetSourceLine()Gets the source line.inthashCode()booleanisConvertible()Returns whether the attribute's type implements a Convertible.booleanisHidden()Returns whether attribute is hidden and not part of the interface.booleanisImplicit()Returns whether attribute is implicit and not result of an attribute line configuration.booleanisNullable()Returns whether database column is nullable.voidparse(Entity entity, AttributeLine line)Parses an attribute line.voidsetApplicationTypeName(String applicationTypeName)Sets the application specific type if Convertible.voidsetColumnName(String columnName)voidsetDataType(DataType<?> dataType)voidsetInnerTypeName(String innerTypeName)Sets the inner type name.voidsetName(String javaName)voidsetNullable(Boolean nullable)Overrides nullable feature.voidsetOrdinal(int ordinal)voidsetRelation(Relation relation)voidsetScale(Integer scale)voidsetSize(Integer size)voidsetSourceLine(AttributeLine sourceLine)Sets the source line.StringtoMethodArgument(String value)Conberts a given value string to a valid java method argument.
Adds downcasts, if necessary.StringtoString()voidvalidate()Validates the attribute.
-
-
-
Constructor Detail
-
AttributeImpl
public AttributeImpl(EntityFactoryImpl factory, Entity entity, SourceInfo sourceInfo, boolean implicit)
Creates an attribute.- Parameters:
factory- the factory to create the attribute optionsentity- the entity this attribute belongs tosourceInfo- the source infoimplicit- true if implicit attribute
-
-
Method Detail
-
getSourceInfo
public SourceInfo getSourceInfo()
Description copied from interface:ModelElementGets the information about the source where this element is defined.- Specified by:
getSourceInfoin interfaceModelElement- Returns:
- the source info
-
getParent
public ModelElement getParent()
Description copied from interface:ModelElementGets the parent element.- Specified by:
getParentin interfaceModelElement- Returns:
- the parent, null if none
-
compareTo
public int compareTo(AttributeImpl o)
- Specified by:
compareToin interfaceComparable<AttributeImpl>
-
isImplicit
public boolean isImplicit()
Description copied from interface:AttributeReturns whether attribute is implicit and not result of an attribute line configuration.- Specified by:
isImplicitin interfaceAttribute- Returns:
- true if implicit
-
isHidden
public boolean isHidden()
Description copied from interface:AttributeReturns whether attribute is hidden and not part of the interface.
-
getEntity
public Entity getEntity()
Description copied from interface:AttributeGets the entity this attribute belongs to.
-
getOrdinal
public int getOrdinal()
Description copied from interface:ModelElementGets the ordinal along the inheritance path.- Specified by:
getOrdinalin interfaceModelElement- Returns:
- the ordinal, starting at 0
-
setOrdinal
public void setOrdinal(int ordinal)
-
parse
public void parse(Entity entity, AttributeLine line) throws ModelException
Parses an attribute line.- Parameters:
entity- the entityline- the source line- Throws:
ModelException- if parsing the model failed
-
isConvertible
public boolean isConvertible()
Description copied from interface:AttributeReturns whether the attribute's type implements a Convertible.- Specified by:
isConvertiblein interfaceAttribute- Returns:
- true if Convertible
-
setApplicationTypeName
public void setApplicationTypeName(String applicationTypeName)
Sets the application specific type if Convertible.- Parameters:
applicationTypeName- the name of the application specific type
-
getApplicationTypeName
public String getApplicationTypeName() throws ModelException
Description copied from interface:AttributeGets the name of the application specific type, if a Convertible type.- Specified by:
getApplicationTypeNamein interfaceAttribute- Returns:
- the application specific type, never null or empty
- Throws:
ModelException- if this is not a Convertible type
-
setInnerTypeName
public void setInnerTypeName(String innerTypeName) throws ModelException
Sets the inner type name.- Parameters:
innerTypeName- the name of the inner type- Throws:
ModelException- if datatype is Convertible and the inner type is not supported or inner type not applicable to datatype
-
getInnerTypeName
public String getInnerTypeName() throws ModelException
Description copied from interface:AttributeGets the inner type name.
This is either the generic inner type or the wrapped type of Convertible types.- Specified by:
getInnerTypeNamein interfaceAttribute- Returns:
- the inner type name
- Throws:
ModelException- if not an application type or innername not set
-
getInnerDataType
public DataType<?> getInnerDataType() throws ModelException
Description copied from interface:AttributeGets the inner datatype exposed to the backend if Convertible.- Specified by:
getInnerDataTypein interfaceAttribute- Returns:
- the inner type for the backend
- Throws:
ModelException- if not a Convertible
-
getEffectiveDataType
public DataType<?> getEffectiveDataType() throws ModelException
Description copied from interface:AttributeGets the effective type exposed to the backend.
If this is an application specific type, the inner type will be returned.- Specified by:
getEffectiveDataTypein interfaceAttribute- Returns:
- the effective data type
- Throws:
ModelException- if model garbeled
-
getJavaType
public String getJavaType() throws ModelException
Description copied from interface:AttributeGets the java type.
Returns the java type with optional generic info.Examples:
Date Binary<Invoice> MyType;
- Specified by:
getJavaTypein interfaceAttribute- Returns:
- the type string
- Throws:
ModelException- if type is misconfigured
-
getRelation
public Relation getRelation()
Description copied from interface:AttributeGets the associated relation.- Specified by:
getRelationin interfaceAttribute- Returns:
- the relation, null if none
-
getName
public String getName()
Description copied from interface:ModelElementGets the name of the element.- Specified by:
getNamein interfaceModelElement- Returns:
- the name
-
getColumnName
public String getColumnName()
Description copied from interface:AttributeGets the column name.
This is the model's column name.
According to theDataType, an attribute may be mapped to more than one database column.- Specified by:
getColumnNamein interfaceAttribute- Returns:
- the column name (always in lowercase)
- See Also:
Attribute.getColumnName(int),Attribute.getDataType()
-
getColumnName
public String getColumnName(int columnIndex) throws ModelException
Description copied from interface:AttributeGets the database column name.
For datatype with only one column, this is usually the same as the model's column name.- Specified by:
getColumnNamein interfaceAttribute- Parameters:
columnIndex- the column index according to theDataType.- Returns:
- the column name used by the database
- Throws:
ModelException- if the effective datatype could not be determined- See Also:
Attribute.getColumnName(),Attribute.getDataType()
-
getDataType
public DataType<?> getDataType()
Description copied from interface:AttributeGets the model's data type.- Specified by:
getDataTypein interfaceAttribute- Returns:
- the data type
-
getSize
public Integer getSize()
Description copied from interface:AttributeGets the column width.For strings this is the maximum number of characters. For numerics this is only a hint for the GUI.
-
getScale
public Integer getScale()
Description copied from interface:AttributeGets the scale for numbers with a fraction part.
-
getOptions
public AttributeOptionsImpl getOptions()
Description copied from interface:AttributeGets the options.- Specified by:
getOptionsin interfaceAttribute- Returns:
- the options
-
setColumnName
public void setColumnName(String columnName)
-
setDataType
public void setDataType(DataType<?> dataType)
-
setRelation
public void setRelation(Relation relation)
-
setName
public void setName(String javaName)
-
setScale
public void setScale(Integer scale)
-
setSize
public void setSize(Integer size)
-
isNullable
public boolean isNullable() throws ModelExceptionDescription copied from interface:AttributeReturns whether database column is nullable.- Specified by:
isNullablein interfaceAttribute- Returns:
- true if WITH NULL, false if NOT NULL
- Throws:
ModelException- if type is misconfigured
-
setNullable
public void setNullable(Boolean nullable)
Overrides nullable feature.- Parameters:
nullable- null to determine from datatype
-
validate
public void validate() throws ModelExceptionDescription copied from interface:AttributeValidates the attribute.- Specified by:
validatein interfaceAttribute- Throws:
ModelException- if validation failed
-
getSourceLine
public AttributeLine getSourceLine()
Gets the source line.- Returns:
- the line
-
setSourceLine
public void setSourceLine(AttributeLine sourceLine)
Sets the source line.- Parameters:
sourceLine- the line
-
createModelException
public ModelException createModelException(String message)
Creates a model exception.Refers to the source line if set, otherwise just the message.
- Parameters:
message- the message- Returns:
- the exception
-
getMethodNameSuffix
public String getMethodNameSuffix()
Description copied from interface:AttributeGets the suffix to be used in methodnames.Example:
"set" + getMethodNameSuffix() would return "setBlah" if the javaName is "blah".
- Specified by:
getMethodNameSuffixin interfaceAttribute- Returns:
- the suffix
-
getGetterName
public String getGetterName()
Description copied from interface:AttributeGets the getter method name.- Specified by:
getGetterNamein interfaceAttribute- Returns:
- the getter
-
getSetterName
public String getSetterName()
Description copied from interface:AttributeGets the setter method name.- Specified by:
getSetterNamein interfaceAttribute- Returns:
- the setter
-
getBindableAnnotation
public String getBindableAnnotation()
Description copied from interface:AttributeReturns the @Bindable-annotation text.- Specified by:
getBindableAnnotationin interfaceAttribute- Returns:
- the annotation text, null if none
-
toMethodArgument
public String toMethodArgument(String value) throws ModelException
Description copied from interface:AttributeConberts a given value string to a valid java method argument.
Adds downcasts, if necessary.- Specified by:
toMethodArgumentin interfaceAttribute- Parameters:
value- the value string- Returns:
- the method argument string
- Throws:
ModelException
-
-