Class RelationImpl

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

public class RelationImpl extends Object implements Relation, Comparable<RelationImpl>, Cloneable
Relation implementation.
Author:
harald
  • Field Details

  • Constructor Details

    • RelationImpl

      public RelationImpl(Entity entity, SourceInfo sourceInfo)
      Creates a relation.
      Parameters:
      entity - the entity this relation belongs to
      sourceInfo - the source info
  • Method Details

    • createEmbedded

      public RelationImpl createEmbedded(Entity embeddingEntity, String pathName, String columnPrefixPath)
      Description copied from interface: Relation
      Creates an embedded copy of this relation.
      Specified by:
      createEmbedded in interface Relation
      Parameters:
      embeddingEntity - the embedding entity
      pathName - the logical pathname
      columnPrefixPath - the column prefix path
      Returns:
      the created relation
    • clone

      protected RelationImpl clone()
      Overrides:
      clone in class Object
    • 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
    • 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)
    • hashCode

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

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

      public int compareTo(RelationImpl o)
      Specified by:
      compareTo in interface Comparable<RelationImpl>
    • parse

      public void parse(Entity entity, RelationLine line) throws ModelException
      Parses a relation line.
      Parameters:
      entity - the entity
      line - the source line
      Throws:
      ModelException - if parsing the model failed
    • getEntity

      public Entity getEntity()
      Description copied from interface: Relation
      Gets the entity this relation belongs to.
      Specified by:
      getEntity in interface Relation
      Returns:
      the entity
    • getEmbeddingEntity

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

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

      public String getPathName()
      Description copied from interface: Relation
      Gets the pathname.
      The pathname is identical to the java name for non-embedded relations.
      For embedded entities, the pathname consists of the dotted path from the parent entity to the embedded attribute.
      Specified by:
      getPathName in interface Relation
      Returns:
      the pathname
    • getColumnPrefixPath

      public String getColumnPrefixPath()
      Description copied from interface: Relation
      Gets the column prefix path for embedded relations.
      Specified by:
      getColumnPrefixPath in interface Relation
      Returns:
      the column path, null if not embedded
    • getAnnotations

      public List<String> getAnnotations()
      Description copied from interface: Relation
      Gets the list of annotations.
      Annotations start with an @. By default, they are applied to the getters of the interfaces only. However, the at-sign may be followed by one or two modifiers that changes the code generation:
      • =: annotate setter only.
      • +: annotate setter and getter.
      • ~: annotation is hidden, i.e. applied to the implementations instead of the interfaces.
      Example:
         @=~MyAnno
         will be applied to the implementation of the setter only.
       
      Specified by:
      getAnnotations in interface Relation
      Returns:
      the annotations
    • setAnnotations

      public void setAnnotations(List<String> annotations)
    • getStereotypes

      public List<String> getStereotypes()
      Description copied from interface: Relation
      Gets the list of custom stereotypes.
      Specified by:
      getStereotypes in interface Relation
      Returns:
      the stereotypes
    • setStereotypes

      public void setStereotypes(List<String> stereotypes)
    • isSelectionTypeDetermined

      public boolean isSelectionTypeDetermined()
      Returns whether selection type was determined by rule.
      Returns:
      false if provided by the model, true if by automatic rule
    • setSelectionTypeDetermined

      public void setSelectionTypeDetermined(boolean selectionTypeDetermined)
    • getGetterSetterComment

      public String getGetterSetterComment()
      Description copied from interface: Relation
      Gets the comment line for getter and setter.
      Specified by:
      getGetterSetterComment in interface Relation
      Returns:
      the comment
    • toString

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

      public void validate() throws ModelException
      Description copied from interface: Relation
      Validates the relation.
      Specified by:
      validate in interface Relation
      Throws:
      ModelException - if validation failed
    • getName

      public String getName()
      Gets the name of this relation.
      If no explicit name set, it defaults to the className.
      Specified by:
      getName in interface ModelElement
      Returns:
      the name
    • setName

      public void setName(String name)
    • getSourceLine

      public RelationLine getSourceLine()
      Gets the source line.
      Returns:
      the line
    • setSourceLine

      public void setSourceLine(RelationLine 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
    • createModelException

      public ModelException createModelException(String message, Throwable cause)
      Creates a model exception.

      Refers to the source line if set, otherwise just the message.

      Parameters:
      message - the message
      cause - the cause
      Returns:
      the exception
    • getComment

      public String getComment()
      Description copied from interface: Relation
      Gets the comment.
      Specified by:
      getComment in interface Relation
      Returns:
      the comment
    • getClassName

      public String getClassName()
      Description copied from interface: Relation
      Gets the name of the related class.
      Specified by:
      getClassName in interface Relation
      Returns:
      the classname
    • getRelationType

      public RelationType getRelationType()
      Description copied from interface: Relation
      Gets the relation type.
      Specified by:
      getRelationType in interface Relation
      Returns:
      list or object
    • getAccessScope

      public AccessScope getAccessScope()
      Description copied from interface: Relation
      Gets the access scope for generated methods.
      Specified by:
      getAccessScope in interface Relation
      Returns:
      the scope
    • getAttribute

      public Attribute getAttribute()
      Description copied from interface: Relation
      Gets the associated attribute.
      Specified by:
      getAttribute in interface Relation
      Returns:
      the attribute, null if ID of foreign entity
    • getForeignEntity

      public Entity getForeignEntity()
      Description copied from interface: Relation
      Gets the related entity.
      Specified by:
      getForeignEntity in interface Relation
      Returns:
      the foreign entity
    • getForeignAttribute

      public Attribute getForeignAttribute()
      Description copied from interface: Relation
      Gets the foreign attribute.
      Specified by:
      getForeignAttribute in interface Relation
      Returns:
      the attribute, null if ID of this entity
    • getForeignRelation

      public Relation getForeignRelation()
      Description copied from interface: Relation
      Gets the foreign (opposite) relation.
      Specified by:
      getForeignRelation in interface Relation
      Returns:
      the foreign relation, null if no such relation
    • getNmRelation

      public Relation getNmRelation()
      Description copied from interface: Relation
      Gets the N:M relation of the foreign entity.
      Specified by:
      getNmRelation in interface Relation
      Returns:
      the nm-relation, null if this is no nm-relation
    • getDefiningNmRelation

      public Relation getDefiningNmRelation()
      Description copied from interface: Relation
      Gets the relation of the entity defining the nm-relation.
      Specified by:
      getDefiningNmRelation in interface Relation
      Returns:
      the defining relation
    • isComposite

      public boolean isComposite()
      Description copied from interface: Relation
      Returns whether the relation points to components of a composite.
      Specified by:
      isComposite in interface Relation
      Returns:
      true if composite relation
    • isEmbedding

      public boolean isEmbedding()
      Description copied from interface: Relation
      Returns whether the relation points to an embedded entity.
      Specified by:
      isEmbedding in interface Relation
      Returns:
      true if embedded 1:1 relation
    • isEmbedded

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

      public String getColumnPrefix()
      Description copied from interface: Relation
      Gets the prefix for the column names.
      Only applicable to embedded entities!
      Specified by:
      getColumnPrefix in interface Relation
      Returns:
      the column name prefix
    • isTracked

      public boolean isTracked()
      Description copied from interface: Relation
      Returns whether the modification state of the relation is available.
      Specified by:
      isTracked in interface Relation
      Returns:
      true if tracked object or tracked list
    • isReferenced

      public boolean isReferenced()
      Description copied from interface: Relation
      Returns whether the parent object is referenced by a variable.
      Specified by:
      isReferenced in interface Relation
      Returns:
      true if referenced
    • isProcessed

      public boolean isProcessed()
      Description copied from interface: Relation
      Returns whether a process-method is invoked after initialization, select and before save.
      The method has the same name as the getter with "get" replaced by "process" and must be provided by the application.
      This flag applies to composite relations only.
      Specified by:
      isProcessed in interface Relation
      Returns:
      true if processed
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: Relation
      Returns whether the relation is read only.
      Specified by:
      isReadOnly in interface Relation
      Returns:
      true if no setter method
    • isWriteOnly

      public boolean isWriteOnly()
      Description copied from interface: Relation
      Returns whether the relation is write-only.
      Specified by:
      isWriteOnly in interface Relation
      Returns:
      true if no getter method
    • isSerialized

      public boolean isSerialized()
      Description copied from interface: Relation
      Returns whether the relation is serialized.
      Used for non-composite relations to make them non-transient.
      Specified by:
      isSerialized in interface Relation
      Returns:
      true if serialized, false if transient
    • isClearOnRemoteSave

      public boolean isClearOnRemoteSave()
      Description copied from interface: Relation
      Returns whether the relation should be cleared before save.
      Used for non-composite serialized relations that should not be transmitted to the server.
      Specified by:
      isClearOnRemoteSave in interface Relation
      Returns:
      true if transient on save
    • isReversed

      public boolean isReversed()
      Description copied from interface: Relation
      Returns whether this is list relation with only one element.
      A.k.a. reversed 1:1 object relation.
      Specified by:
      isReversed in interface Relation
      Returns:
      true if reversed
    • isShallow

      public boolean isShallow()
      Description copied from interface: Relation
      Returns whether the relation should be skipped in snapshot and copy operations.
      Specified by:
      isShallow in interface Relation
      Returns:
      true if skip this relation, false to include (default)
    • setShallow

      public void setShallow(boolean shallow)
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: Relation
      Returns whether the relation should be set to immutable after loading.
      Specified by:
      isImmutable in interface Relation
      Returns:
      true if immutable
    • setImmutable

      public void setImmutable(boolean immutable)
    • isPartOfNormText

      public boolean isPartOfNormText()
      Description copied from interface: Relation
      Returns whether the relation becomes part of the normtext.
      Specified by:
      isPartOfNormText in interface Relation
      Returns:
      true if add to normtext
    • setPartOfNormText

      public void setPartOfNormText(boolean partOfNormText)
    • isBluntDeclared

      public boolean isBluntDeclared()
      Description copied from interface: Relation
      Returns whether the blunt-method becomes part if the interface.
      Specified by:
      isBluntDeclared in interface Relation
      Returns:
      true if declared in interface, false if only implementation generated
    • setBluntDeclared

      public void setBluntDeclared(boolean bluntDeclared)
    • getCountAttribute

      public Attribute getCountAttribute()
      Description copied from interface: Relation
      Returns the attribute that holds the number of elements of a 1:N relation.
      Applies only to composite non-reversed list relations.
      If set, this column gets the number of elements in the list when the PDO is persisted. This avoids an initial select when the list is accessed the first time and the list is empty.
      Specified by:
      getCountAttribute in interface Relation
      Returns:
      the counter attribute, null if none
    • getMethodName

      public String getMethodName()
      Description copied from interface: Relation
      Gets the name-part for select- and delete-methods.
      Specified by:
      getMethodName in interface Relation
      Returns:
      the method name, null if default from foreign entity name
    • getMethodArgs

      public List<MethodArgument> getMethodArgs()
      Description copied from interface: Relation
      Gets the effective method arguments for select- and delete-methods.
      Specified by:
      getMethodArgs in interface Relation
      Returns:
      the args, never null, at least 1 element
    • getNmName

      public String getNmName()
      Description copied from interface: Relation
      Gets the name of the nm-relation.
      Specified by:
      getNmName in interface Relation
      Returns:
      the n:m relation name, null if this is not an n:m-relation
    • getNmMethodName

      public String getNmMethodName()
      Description copied from interface: Relation
      Same as Relation.getMethodName() but for nm relation.
      Specified by:
      getNmMethodName in interface Relation
      Returns:
      the list method name, null if default
    • getNmScope

      public AccessScope getNmScope()
      Description copied from interface: Relation
      Gets the access scope for the nm-method.
      Defaults to the access scope of the relation.
      Specified by:
      getNmScope in interface Relation
      Returns:
      the access scope, never null
    • getLinkMethodName

      public String getLinkMethodName()
      Description copied from interface: Relation
      Gets the name for the link method.
      Specified by:
      getLinkMethodName in interface Relation
      Returns:
      the link method, null if default
    • getLinkMethodIndex

      public String getLinkMethodIndex()
      Description copied from interface: Relation
      Returns the optional link method index parameter.
      Specified by:
      getLinkMethodIndex in interface Relation
      Returns:
      the index parameter, null if no index
    • getSelectionType

      public SelectionType getSelectionType()
      Description copied from interface: Relation
      Gets the selection type.
      Specified by:
      getSelectionType in interface Relation
      Returns:
      the selection type
    • isSelectionCached

      public boolean isSelectionCached()
      Description copied from interface: Relation
      Returns whether the select method is a caching one.
      Specified by:
      isSelectionCached in interface Relation
      Returns:
      true if cached
    • getSelectionWurbletArguments

      public String getSelectionWurbletArguments()
      Description copied from interface: Relation
      Gets the optional wurblet arguments.
      Only available for composite list relations.
      Specified by:
      getSelectionWurbletArguments in interface Relation
      Returns:
      the extra wurblet args
    • isDeletionFromMainClass

      public boolean isDeletionFromMainClass()
      Description copied from interface: Relation
      Returns whether delete method is invoked on main class instead of relation class.
      Specified by:
      isDeletionFromMainClass in interface Relation
      Returns:
      true if delete from main class
    • isDeletionCascaded

      public boolean isDeletionCascaded()
      Description copied from interface: Relation
      Returns whether deletion is cascaded to elements in lists.
      Specified by:
      isDeletionCascaded in interface Relation
      Returns:
      true if cascaded
    • setNmRelation

      public void setNmRelation(Relation nmRelation)
    • setDefiningNmRelation

      public void setDefiningNmRelation(Relation definingNmRelation)
    • setAttribute

      public void setAttribute(Attribute attribute)
    • setForeignEntity

      public void setForeignEntity(Entity foreignEntity)
    • setForeignAttribute

      public void setForeignAttribute(Attribute foreignAttribute)
    • setForeignRelation

      public void setForeignRelation(Relation foreignRelation)
    • setClassName

      public void setClassName(String className)
    • setComment

      public void setComment(String comment)
    • setComposite

      public void setComposite(boolean composite)
    • setColumnPrefix

      public void setColumnPrefix(String columnPrefix)
    • setLinkMethodName

      public void setLinkMethodName(String linkMethodName)
    • setMethodArgs

      public void setMethodArgs(List<MethodArgument> methodArgs)
    • setNmName

      public void setNmName(String nmName)
    • setNmMethodName

      public void setNmMethodName(String nmMethodName)
    • setNmScope

      public void setNmScope(AccessScope nmScope)
    • setMethodName

      public void setMethodName(String methodName)
    • setReadOnly

      public void setReadOnly(boolean readOnly)
    • setReferenced

      public void setReferenced(boolean referenced)
    • setProcessed

      public void setProcessed(boolean processed)
    • setRelationType

      public void setRelationType(RelationType relationType)
    • setSerialized

      public void setSerialized(boolean serialized)
    • setClearOnRemoteSave

      public void setClearOnRemoteSave(boolean clearOnRemoteSave)
    • setReversed

      public void setReversed(boolean reversed)
    • setCountAttribute

      public void setCountAttribute(Attribute countAttribute)
    • setTracked

      public void setTracked(boolean tracked)
    • setWriteOnly

      public void setWriteOnly(boolean writeOnly)
    • setSelectionType

      public void setSelectionType(SelectionType selectionType)
    • setSelectionCached

      public void setSelectionCached(boolean selectionCached)
    • setSelectionWurbletArguments

      public void setSelectionWurbletArguments(String selectionWurbletArguments)
    • setAccessScope

      public void setAccessScope(AccessScope accessScope)
    • setDeletionCascaded

      public void setDeletionCascaded(boolean deletionCascaded)
    • setDeletionFromMainClass

      public void setDeletionFromMainClass(boolean deletionFromMainClass)
    • setLinkMethodIndex

      public void setLinkMethodIndex(String linkMethodIndex)
    • getVariableName

      public String getVariableName()
      Gets the variable name.
      Specified by:
      getVariableName in interface Relation
      Returns:
      the variable name
    • getMethodNameSuffix

      public String getMethodNameSuffix()
      Gets the suffix to be used in method names.

      Example:

        "set" + getMethodNameSuffix() would return "setBlah" if the
        classname is "Blah" or the name is "blah".
       
      Specified by:
      getMethodNameSuffix in interface Relation
      Returns:
      the suffix
    • getGetterName

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

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

      public String getDeclaredJavaType(boolean withinForeignEntity)
      Description copied from interface: Relation
      Gets the declared java type of the relation.
      Specified by:
      getDeclaredJavaType in interface Relation
      Parameters:
      withinForeignEntity - true if we need the type from within the foreign entity, else from within the relation's entity
      Returns:
      the declared java type
    • getJavaType

      public String getJavaType()
      Description copied from interface: Relation
      Gets the effective java type of the relation.

      Example: the effective type is ArrayList and the declared type is List.

      Specified by:
      getJavaType in interface Relation
      Returns:
      the effective java type
    • isDeepReference

      public boolean isDeepReference()
      Description copied from interface: Relation
      Returns whether this relation is a deep reference.
      Deep references point to components of another composite entity.
      Specified by:
      isDeepReference in interface Relation
      Returns:
      true if deep reference
    • setDeepReference

      public void setDeepReference(boolean deepReference)