Class AttributeImpl

java.lang.Object
org.tentackle.model.impl.AttributeImpl
All Implemented Interfaces:
Cloneable, Comparable<AttributeImpl>, Attribute, ModelElement

public class AttributeImpl extends Object implements Attribute, Comparable<AttributeImpl>, Cloneable
Attribute implementation.
Author:
harald
  • Constructor Details

    • AttributeImpl

      public AttributeImpl(EntityFactoryImpl factory, Entity entity, SourceInfo sourceInfo, boolean implicit, AttributeOptionsImpl options)
      Creates an attribute.
      Parameters:
      factory - the factory to create the attribute options
      entity - the entity this attribute belongs to
      sourceInfo - the source info
      implicit - true if implicit attribute
      options - the attribute's options, null to create from source info
    • AttributeImpl

      public AttributeImpl(EntityFactoryImpl factory, Entity entity, SourceInfo sourceInfo, boolean implicit)
      Creates an attribute.
      Parameters:
      factory - the factory to create the attribute options
      entity - the entity this attribute belongs to
      sourceInfo - the source info
      implicit - true if implicit attribute
  • Method Details

    • createEmbedded

      public Attribute createEmbedded(Entity embeddingEntity, String pathName, String columnName)
      Description copied from interface: Attribute
      Creates an embedded copy of this attribute.
      Specified by:
      createEmbedded in interface Attribute
      Parameters:
      embeddingEntity - the embedding entity
      pathName - the logical pathname
      columnName - the new column name
      Returns:
      the created attribute
    • clone

      protected AttributeImpl clone()
      Clones an attribute.
      The method is protected, since createEmbedded(Entity, String, String) should be used instead, which invokes clone().
      Overrides:
      clone in class Object
      Returns:
      the cloned attribute
    • getSourceInfo

      public SourceInfo getSourceInfo()
      Description copied from interface: ModelElement
      Gets the information about the source where this element is defined.
      Specified by:
      getSourceInfo in interface ModelElement
      Returns:
      the source info
    • getParent

      public ModelElement getParent()
      Description copied from interface: ModelElement
      Gets the parent element.
      Specified by:
      getParent in interface ModelElement
      Returns:
      the parent, null if none
    • hashCode

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

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

      public int compareTo(AttributeImpl o)
      Specified by:
      compareTo in interface Comparable<AttributeImpl>
    • isImplicit

      public boolean isImplicit()
      Description copied from interface: Attribute
      Returns whether attribute is implicit and not result of an attribute line configuration.
      Specified by:
      isImplicit in interface Attribute
      Returns:
      true if implicit
    • isHidden

      public boolean isHidden()
      Description copied from interface: Attribute
      Returns whether attribute is hidden and not part of the interface.
      Specified by:
      isHidden in interface Attribute
      Returns:
      true if hidden
    • getEntity

      public Entity getEntity()
      Description copied from interface: Attribute
      Gets the entity this attribute belongs to.
      Specified by:
      getEntity in interface Attribute
      Returns:
      the entity
    • getOrdinal

      public int getOrdinal()
      Description copied from interface: ModelElement
      Gets the ordinal along the inheritance path.
      Specified by:
      getOrdinal in interface ModelElement
      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 entity
      line - the source line
      Throws:
      ModelException - if parsing the model failed
    • isConvertible

      public boolean isConvertible()
      Description copied from interface: Attribute
      Returns whether the attribute's type implements a Convertible.
      Specified by:
      isConvertible in interface Attribute
      Returns:
      true if Convertible
    • isEmbedded

      public boolean isEmbedded()
      Description copied from interface: Attribute
      Returns whether the attribute belongs to an embedded entity.
      Specified by:
      isEmbedded in interface Attribute
      Returns:
      true if embedded
    • getEmbeddingEntity

      public Entity getEmbeddingEntity()
      Description copied from interface: Attribute
      Gets the embedding entity.
      Please notice that the embedding entity is determined by the specific relation, and Attribute.isEmbedded() just means that the attribute is part of an embeddable entity.
      Specified by:
      getEmbeddingEntity in interface Attribute
      Returns:
      the embedding entity, null if not an embedded attribute
    • getEmbeddingPath

      public List<Entity> getEmbeddingPath()
      Description copied from interface: Attribute
      Gets the path of embedding entities.
      The first entity is non-embedded.
      Specified by:
      getEmbeddingPath in interface Attribute
      Returns:
      the embedding path (never empty), null if attribute is not embedded
    • getPathName

      public String getPathName()
      Description copied from interface: Attribute
      Gets the pathname.
      The pathname is identical to the java name for non-embedded entities.
      For embedded entities, the pathname consists of the dotted path from the parent entity to the embedded attribute.
      Specified by:
      getPathName in interface Attribute
      Returns:
      the pathname
    • 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: Attribute
      Gets the name of the application specific type, if a Convertible type.
      Specified by:
      getApplicationTypeName in interface Attribute
      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: Attribute
      Gets the inner type name.
      This is either the generic inner type or the wrapped type of Convertible types.
      Specified by:
      getInnerTypeName in interface Attribute
      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: Attribute
      Gets the inner datatype exposed to the backend if Convertible.
      Specified by:
      getInnerDataType in interface Attribute
      Returns:
      the inner type for the backend
      Throws:
      ModelException - if not a Convertible
    • getEffectiveDataType

      public DataType<?> getEffectiveDataType() throws ModelException
      Description copied from interface: Attribute
      Gets the effective type exposed to the backend.
      If this is an application specific type, the inner type will be returned.
      Specified by:
      getEffectiveDataType in interface Attribute
      Returns:
      the effective data type
      Throws:
      ModelException - if model garbled
    • getJavaType

      public String getJavaType() throws ModelException
      Description copied from interface: Attribute
      Gets the java type.
      Returns the java type with optional generic info.

      Examples:

       Date
       Binary<Invoice>
       MyType;
       
      Specified by:
      getJavaType in interface Attribute
      Returns:
      the type string
      Throws:
      ModelException - if type is misconfigured
    • getRelation

      public Relation getRelation()
      Description copied from interface: Attribute
      Gets the associated relation.
      Specified by:
      getRelation in interface Attribute
      Returns:
      the relation, null if none
    • getName

      public String getName()
      Description copied from interface: ModelElement
      Gets the name of the element.
      Specified by:
      getName in interface ModelElement
      Returns:
      the name
    • getColumnName

      public String getColumnName()
      Description copied from interface: Attribute
      Gets the column name.
      This is the model's column name.
      According to the DataType, an attribute may be mapped to more than one database column.
      Specified by:
      getColumnName in interface Attribute
      Returns:
      the column name (always in lowercase)
      See Also:
    • getColumnName

      public String getColumnName(Backend backend, int columnIndex) throws ModelException
      Description copied from interface: Attribute
      Gets the database column name.
      For datatype with only one column, this is usually the same as the model's column name.
      Specified by:
      getColumnName in interface Attribute
      columnIndex - the column index according to the DataType.
      Returns:
      the column name used by the database
      Throws:
      ModelException
      See Also:
    • getDataType

      public DataType<?> getDataType()
      Description copied from interface: Attribute
      Gets the model's data type.
      Specified by:
      getDataType in interface Attribute
      Returns:
      the data type
    • getSize

      public Integer getSize()
      Description copied from interface: Attribute
      Gets the column width.

      For strings this is the maximum number of characters. For numerics this is only a hint for the GUI.

      Specified by:
      getSize in interface Attribute
      Returns:
      the size, null if not set
    • getScale

      public Integer getScale()
      Description copied from interface: Attribute
      Gets the scale for numbers with a fraction part.
      Specified by:
      getScale in interface Attribute
      Returns:
      the scale, null if not set
    • getOptions

      public AttributeOptionsImpl getOptions()
      Description copied from interface: Attribute
      Gets the options.
      Specified by:
      getOptions in interface Attribute
      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 ModelException
      Description copied from interface: Attribute
      Returns whether database column is nullable.
      Specified by:
      isNullable in interface Attribute
      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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • validate

      public void validate() throws ModelException
      Description copied from interface: Attribute
      Validates the attribute.
      Specified by:
      validate in interface Attribute
      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: Attribute
      Gets the suffix to be used in methodnames.

      Example:

       "set" + getMethodNameSuffix() would return "setBlah" if the javaName is "blah".
       
      Specified by:
      getMethodNameSuffix in interface Attribute
      Returns:
      the suffix
    • getGetterName

      public String getGetterName()
      Description copied from interface: Attribute
      Gets the getter method name.
      Specified by:
      getGetterName in interface Attribute
      Returns:
      the getter
    • getSetterName

      public String getSetterName()
      Description copied from interface: Attribute
      Gets the setter method name.
      Specified by:
      getSetterName in interface Attribute
      Returns:
      the setter
    • getBindableAnnotation

      public String getBindableAnnotation()
      Description copied from interface: Attribute
      Returns the @Bindable-annotation text.
      Specified by:
      getBindableAnnotation in interface Attribute
      Returns:
      the annotation text, null if none
    • toMethodArgument

      public String toMethodArgument(String value) throws ModelException
      Description copied from interface: Attribute
      Converts a given value string to a valid java method argument.
      Adds a downcast, if necessary.
      Specified by:
      toMethodArgument in interface Attribute
      Parameters:
      value - the value string
      Returns:
      the method argument string
      Throws:
      ModelException