- java.lang.Object
-
- org.tentackle.model.impl.AttributeImpl
-
- All Implemented Interfaces:
java.lang.Comparable<AttributeImpl>,Attribute,ModelElement
public class AttributeImpl extends java.lang.Object implements Attribute, java.lang.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(java.lang.String message)Creates a model exception.booleanequals(java.lang.Object obj)java.lang.StringgetApplicationType()Gets the application specific type.java.lang.StringgetBindableAnnotation()Returns the @Bindable-annotation text.java.lang.StringgetColumnName()Gets the database column name.DataTypegetDataType()Gets the data type.DataTypegetEffectiveType()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.java.lang.StringgetGetterName()Gets the getter method name.java.lang.StringgetInnerName()Returns the inner type.DataTypegetInnerType()Gets the innertype for application specific types.java.lang.StringgetJavaType()Gets the java type.
Returns the java type with optional generic info.java.lang.StringgetMethodNameSuffix()Gets the suffix to be used in methodnames.java.lang.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.java.lang.IntegergetScale()Gets the scale for numbers with a fraction part.intgetScaleWithDefault()Gets the scale width with default 0.java.lang.StringgetSetterName()Gets the setter method name.java.lang.IntegergetSize()Gets the column width.intgetSizeWithDefault()Gets the column width with default 0.SourceInfogetSourceInfo()Gets the information about the source where this element is defined.AttributeLinegetSourceLine()Gets the source line.inthashCode()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.voidsetApplicationType(java.lang.String applicationType)Sets the application specific type.
Only allowedDataType.APPLICATION.voidsetColumnName(java.lang.String columnName)voidsetDataType(DataType dataType)voidsetInnerName(java.lang.String innerType)Sets the inner type.voidsetName(java.lang.String javaName)voidsetNullable(java.lang.Boolean nullable)Overrides nullable feature.voidsetOrdinal(int ordinal)voidsetRelation(Relation relation)voidsetScale(java.lang.Integer scale)voidsetSize(java.lang.Integer size)voidsetSourceLine(AttributeLine sourceLine)Sets the source line.java.lang.StringtoMethodArgument(java.lang.String value)Conberts a given value string to a valid java method argument.
Adds downcasts, if necessary.java.lang.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
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
compareTo
public int compareTo(AttributeImpl o)
- Specified by:
compareToin interfacejava.lang.Comparable<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
-
setApplicationType
public void setApplicationType(java.lang.String applicationType) throws ModelExceptionSets the application specific type.
Only allowedDataType.APPLICATION.- Parameters:
applicationType- the application specific type- Throws:
ModelException- if this is notDataType.APPLICATION
-
getApplicationType
public java.lang.String getApplicationType() throws ModelExceptionGets the application specific type.- Specified by:
getApplicationTypein interfaceAttribute- Returns:
- the application specific type, never null or empty
- Throws:
ModelException- if application specific type not set or this is notDataType.APPLICATION
-
setInnerName
public void setInnerName(java.lang.String innerType) throws ModelExceptionSets the inner type.- Parameters:
innerType- the inner type- Throws:
ModelException- if this is neitherDataType.APPLICATIONnorDataType.BINARY
-
getInnerName
public java.lang.String getInnerName() throws ModelExceptionReturns the inner type.- Specified by:
getInnerNamein interfaceAttribute- Returns:
- the inner type, null if none (only if
DataType.BINARY) - Throws:
ModelException- this isDataType.APPLICATIONand inner type not set
-
getInnerType
public DataType getInnerType() throws ModelException
Gets the innertype for application specific types.- Specified by:
getInnerTypein interfaceAttribute- Returns:
- the inner type to convert to agains the SQL backend
- Throws:
ModelException- if notDataType.APPLICATIONor innertype not a legal DataType.
-
getEffectiveType
public DataType getEffectiveType() 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:
getEffectiveTypein interfaceAttribute- Returns:
- the effective data type
- Throws:
ModelException- if model garbeled
-
getJavaType
public java.lang.String getJavaType() throws ModelExceptionGets the java type.
Returns the java type with optional generic info.Examples:
Date Binary<Invoice> MyType<int>
- 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 java.lang.String getName()
Description copied from interface:ModelElementGets the name of the element.- Specified by:
getNamein interfaceModelElement- Returns:
- the name
-
getColumnName
public java.lang.String getColumnName()
Description copied from interface:AttributeGets the database column name.- Specified by:
getColumnNamein interfaceAttribute- Returns:
- the column name (always in lowercase)
-
getDataType
public DataType getDataType()
Description copied from interface:AttributeGets the data type.- Specified by:
getDataTypein interfaceAttribute- Returns:
- the java data type
-
getSize
public java.lang.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.
-
getSizeWithDefault
public int getSizeWithDefault()
Description copied from interface:AttributeGets the column width with default 0.- Specified by:
getSizeWithDefaultin interfaceAttribute- Returns:
- the column width or 0 if not set
-
getScale
public java.lang.Integer getScale()
Description copied from interface:AttributeGets the scale for numbers with a fraction part.
-
getScaleWithDefault
public int getScaleWithDefault()
Description copied from interface:AttributeGets the scale width with default 0.- Specified by:
getScaleWithDefaultin interfaceAttribute- Returns:
- the scale or 0 if not set
-
getOptions
public AttributeOptionsImpl getOptions()
Description copied from interface:AttributeGets the options.- Specified by:
getOptionsin interfaceAttribute- Returns:
- the options
-
setColumnName
public void setColumnName(java.lang.String columnName)
-
setDataType
public void setDataType(DataType dataType)
-
setRelation
public void setRelation(Relation relation)
-
setName
public void setName(java.lang.String javaName)
-
setScale
public void setScale(java.lang.Integer scale)
-
setSize
public void setSize(java.lang.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(java.lang.Boolean nullable)
Overrides nullable feature.- Parameters:
nullable- null to determine from datatype
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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(java.lang.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 java.lang.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 java.lang.String getGetterName()
Description copied from interface:AttributeGets the getter method name.- Specified by:
getGetterNamein interfaceAttribute- Returns:
- the getter
-
getSetterName
public java.lang.String getSetterName()
Description copied from interface:AttributeGets the setter method name.- Specified by:
getSetterNamein interfaceAttribute- Returns:
- the setter
-
getBindableAnnotation
public java.lang.String getBindableAnnotation()
Description copied from interface:AttributeReturns the @Bindable-annotation text.- Specified by:
getBindableAnnotationin interfaceAttribute- Returns:
- the annotation text, null if none
-
toMethodArgument
public java.lang.String toMethodArgument(java.lang.String value)
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
-
-