Class Association

java.lang.Object
net.sf.jailer.datamodel.ModelElement
net.sf.jailer.datamodel.Association

public class Association extends ModelElement
An association between database-tables.
Author:
Ralf Wisser
  • Field Details

    • source

      public final Table source
      The source table.
    • destination

      public final Table destination
      The destination table.
    • reversed

      public final boolean reversed
      true for reversed association.
    • reversalAssociation

      public Association reversalAssociation
      The counterpart of the association for the reversal direction.
    • NULL_FILTER_COMMENT_PREFIX

      public static final String NULL_FILTER_COMMENT_PREFIX
      See Also:
  • Constructor Details

    • Association

      public Association(Table source, Table destination, boolean insertSourceBeforeDestination, boolean insertDestinationBeforeSource, String joinCondition, DataModel dataModel, boolean reversed, Cardinality cardinality)
      Constructor.
      Parameters:
      source - the source table
      destination - the destination table
      insertSourceBeforeDestination - whether or not to insert source-rows before destination rows in order to prevent foreign-key-constraint violation
      insertDestinationBeforeSource - whether or not to insert destination-rows before source-rows in order to prevent foreign-key-constraint violation
      joinCondition - the join-condition for join with destination table
      dataModel - data-model containing this association
      reversed - true for reversed association
      cardinality - the cardinality (optional)
    • Association

      public Association(Table source, Table destination, boolean insertSourceBeforeDestination, boolean insertDestinationBeforeSource, String joinCondition, DataModel dataModel, boolean reversed, Cardinality cardinality, String author)
      Constructor.
      Parameters:
      source - the source table
      destination - the destination table
      insertSourceBeforeDestination - whether or not to insert source-rows before destination rows in order to prevent foreign-key-constraint violation
      insertDestinationBeforeSource - whether or not to insert destination-rows before source-rows in order to prevent foreign-key-constraint violation
      joinCondition - the join-condition for join with destination table
      dataModel - data-model containing this association
      reversed - true for reversed association
      cardinality - the cardinality (optional)
      author - the author
  • Method Details

    • getJoinCondition

      public String getJoinCondition()
      Gets the restricted join-condition for joining source with destination table.
      Returns:
      the restricted join-condition for joining source with destination table, null if association must be ignored
    • isIgnored

      public boolean isIgnored()
      Is this association ignored?
      Returns:
      true iff this association is ignored
    • getCardinality

      public Cardinality getCardinality()
      Gets the cardinality.
      Returns:
      the cardinality. null if cardinality is not known.
    • toString

      public String toString()
      Stringifies the association.
      Overrides:
      toString in class Object
      Returns:
      string representation of the association
    • toString

      public String toString(int maxGab, boolean useDisplayName)
      Stringifies the association.
      Parameters:
      maxGab - minimum width of the destination table name column
      useDisplayName - true to use display names for tables
      Returns:
      string representation of the association
    • renderJoinCondition

      public String renderJoinCondition(String restrictionSeparator)
      Stringifies the join condition.
      Parameters:
      restrictionSeparator - separates join-condition from restriction condition in the result
      Returns:
      the join condition as a string, with any restriction appended after the separator
    • getUnrestrictedJoinCondition

      public String getUnrestrictedJoinCondition()
      Gets join-condition without any restrictions.
      Returns:
      join-condition as defined in data model
    • getRestrictionCondition

      public String getRestrictionCondition()
      Gets restriction-condition.
      Returns:
      restriction-condition, null if association is not restricted
    • setName

      public void setName(String name)
      Sets the name of the association.
      Parameters:
      name - the name of the association
    • getName

      public String getName()
      Gets the name of the association.
      Returns:
      the name of the association
    • isInsertSourceBeforeDestination

      public boolean isInsertSourceBeforeDestination()
      Whether or not to insert source-rows before destination rows in order to prevent foreign-key-constraint violation.
      Returns:
      the insertSourceBeforeDestination
    • isInsertDestinationBeforeSource

      public boolean isInsertDestinationBeforeSource()
      Whether or not to insert destination-rows before source-rows in order to prevent foreign-key-constraint violation.
      Returns:
      the insertDestinationBeforeSource
    • isRestricted

      public boolean isRestricted()
      Whether there is any restriction of this association.
      Returns:
      true if there is a restriction on this association
    • appendCondition

      public void appendCondition(String condition)
      Appends condition to join-condition.
      Parameters:
      condition - the condition
    • getAggregationSchema

      public AggregationSchema getAggregationSchema()
      Gets the XML aggregation schema.
      Returns:
      the XML aggregation schema
    • getAggregationTagName

      public String getAggregationTagName()
      Gets name of XML-tag used for aggregation.
      Returns:
      name of XML-tag used for aggregation
    • setAggregationSchema

      public void setAggregationSchema(AggregationSchema aggregationSchema)
      Sets the XML aggregation schema.
      Parameters:
      aggregationSchema - the XML aggregation schema
    • setAggregationTagName

      public void setAggregationTagName(String aggregationTagName)
      Sets name of XML-tag used for aggregation.
      Parameters:
      aggregationTagName - name of XML-tag used for aggregation
    • getId

      public int getId()
      Gets unique ID.
      Returns:
      unique ID
    • getDataModel

      public DataModel getDataModel()
      Gets data-model to which this association belongs to.
      Returns:
      the data model containing this association
    • createSourceToDestinationKeyMapping

      public Map<Column,Column> createSourceToDestinationKeyMapping()
      Maps source-columns to destination-columns, if this represents an equi-join. Otherwise it returns an empty map.
      Returns:
      map from source-columns to destination-columns, if this represents an equi-join
    • createSourceToDestinationKeyMapping

      public Map<Column,Column> createSourceToDestinationKeyMapping(Set<Pair<Column,Column>> assignments)
      Maps source-columns to destination-columns, if this represents an equi-join. Otherwise it returns an empty map.
      Parameters:
      assignments - if not null, put column assignments into it
      Returns:
      map from source-columns to destination-columns, if this represents an equi-join
    • hasNullableFK

      public boolean hasNullableFK()
      Checks whether this association has a nullable foreign key (i.e. all FK columns on the source side are nullable and have no non-null filter).
      Returns:
      true if the foreign key columns are all nullable
    • fkHasNullFilter

      public boolean fkHasNullFilter()
      Checks whether all foreign key columns on the source side have a null filter.
      Returns:
      true if all FK source columns have a null filter
    • fkHasExcludeFilter

      public boolean fkHasExcludeFilter()
      Checks whether all foreign key columns on the source side have an exclude filter.
      Returns:
      true if all FK source columns have an exclude filter
    • setOrResetFKNullFilter

      public boolean setOrResetFKNullFilter(boolean set)
      Sets or resets null filters on the foreign key columns of the source side.
      Parameters:
      set - true to set null filters, false to remove them
      Returns:
      true if any filter was changed
    • isRestrictedDependencyWithNulledFK

      public boolean isRestrictedDependencyWithNulledFK()
      Checks whether this is a restricted dependency whose FK columns are set to null.
      Returns:
      true if this is a restricted dependency with nulled FK columns