Class ConstraintReferential

All Implemented Interfaces:
Comparable<Constraint>, HasSQL

public class ConstraintReferential extends Constraint
A referential constraint.
  • Field Details

  • Constructor Details

    • ConstraintReferential

      public ConstraintReferential(Schema schema, int id, String name, Table table)
  • Method Details

    • getConstraintType

      public Constraint.Type getConstraintType()
      Description copied from class: Constraint
      The constraint type name
      Specified by:
      getConstraintType in class Constraint
      Returns:
      the name
    • getCreateSQLForCopy

      public String getCreateSQLForCopy(Table forTable, String quotedName)
      Create the SQL statement of this object so a copy of the table can be made.
      Specified by:
      getCreateSQLForCopy in class DbObject
      Parameters:
      forTable - the table to create the object for
      quotedName - the name of this object (quoted if necessary)
      Returns:
      the SQL statement
    • getCreateSQLForCopy

      public String getCreateSQLForCopy(Table forTable, Table forRefTable, String quotedName, boolean internalIndex)
      Create the SQL statement of this object so a copy of the table can be made.
      Parameters:
      forTable - the table to create the object for
      forRefTable - the referenced table
      quotedName - the name of this object (quoted if necessary)
      internalIndex - add the index name to the statement
      Returns:
      the SQL statement
    • getShortDescription

      private String getShortDescription(Index searchIndex, SearchRow check)
      Get a short description of the constraint. This includes the constraint name (if set), and the constraint expression.
      Parameters:
      searchIndex - the index, or null
      check - the row, or null
      Returns:
      the description
    • getCreateSQLWithoutIndexes

      public String getCreateSQLWithoutIndexes()
      Description copied from class: Constraint
      Get the SQL statement to create this constraint.
      Specified by:
      getCreateSQLWithoutIndexes in class Constraint
      Returns:
      the SQL statement
    • getCreateSQL

      public String getCreateSQL()
      Description copied from class: DbObject
      Construct the CREATE ... SQL statement for this object.
      Specified by:
      getCreateSQL in class DbObject
      Returns:
      the SQL statement
    • setColumns

      public void setColumns(IndexColumn[] cols)
    • getColumns

      public IndexColumn[] getColumns()
    • getReferencedColumns

      public HashSet<Column> getReferencedColumns(Table table)
      Description copied from class: Constraint
      Get all referenced columns.
      Specified by:
      getReferencedColumns in class Constraint
      Parameters:
      table - the table
      Returns:
      the set of referenced columns
    • setRefColumns

      public void setRefColumns(IndexColumn[] refCols)
    • getRefColumns

      public IndexColumn[] getRefColumns()
    • setRefTable

      public void setRefTable(Table refTable)
    • setIndex

      public void setIndex(Index index, boolean isOwner)
      Set the index to use for this constraint.
      Parameters:
      index - the index
      isOwner - true if the index is generated by the system and belongs to this constraint
    • setRefConstraint

      public void setRefConstraint(ConstraintUnique refConstraint)
      Set the unique constraint of the referenced table to use for this constraint.
      Parameters:
      refConstraint - the unique constraint
    • removeChildrenAndResources

      public void removeChildrenAndResources(SessionLocal session)
      Description copied from class: DbObject
      Delete all dependent children objects and resources of this object.
      Specified by:
      removeChildrenAndResources in class DbObject
      Parameters:
      session - the session
    • checkRow

      public void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)
      Description copied from class: Constraint
      Check if this row fulfils the constraint. This method throws an exception if not.
      Specified by:
      checkRow in class Constraint
      Parameters:
      session - the session
      t - the table
      oldRow - the old row
      newRow - the new row
    • checkRowOwnTable

      private void checkRowOwnTable(SessionLocal session, Row oldRow, Row newRow)
    • existsRow

      private boolean existsRow(SessionLocal session, Index searchIndex, SearchRow check, Row excluding)
    • isEqual

      private boolean isEqual(Row oldRow, Row newRow)
    • checkRow

      private void checkRow(SessionLocal session, Row oldRow)
    • checkRowRefTable

      private void checkRowRefTable(SessionLocal session, Row oldRow, Row newRow)
    • updateWithSkipCheck

      private void updateWithSkipCheck(Prepared prep)
    • setWhere

      private void setWhere(Prepared command, int pos, Row row)
    • getDeleteAction

      public ConstraintActionType getDeleteAction()
    • setDeleteAction

      public void setDeleteAction(ConstraintActionType action)
      Set the action to apply (restrict, cascade,...) on a delete.
      Parameters:
      action - the action
    • updateOnTableColumnRename

      public void updateOnTableColumnRename()
      Update the constraint SQL when a referenced column is renamed.
    • buildDeleteSQL

      private void buildDeleteSQL()
    • getUpdate

      private Prepared getUpdate(SessionLocal session)
    • getDelete

      private Prepared getDelete(SessionLocal session)
    • getUpdateAction

      public ConstraintActionType getUpdateAction()
    • setUpdateAction

      public void setUpdateAction(ConstraintActionType action)
      Set the action to apply (restrict, cascade,...) on an update.
      Parameters:
      action - the action
    • buildUpdateSQL

      private void buildUpdateSQL()
    • rebuild

      public void rebuild()
      Description copied from class: Constraint
      This method is called after a related table has changed (the table was renamed, or columns have been renamed).
      Specified by:
      rebuild in class Constraint
    • prepare

      private Prepared prepare(SessionLocal session, String sql, ConstraintActionType action)
    • appendUpdate

      private void appendUpdate(StringBuilder builder)
    • appendWhere

      private void appendWhere(StringBuilder builder)
    • getRefTable

      public Table getRefTable()
      Overrides:
      getRefTable in class Constraint
    • usesIndex

      public boolean usesIndex(Index idx)
      Description copied from class: Constraint
      Check if this constraint needs the specified index.
      Specified by:
      usesIndex in class Constraint
      Parameters:
      idx - the index
      Returns:
      true if the index is used
    • setIndexOwner

      public void setIndexOwner(Index index)
      Description copied from class: Constraint
      This index is now the owner of the specified index.
      Specified by:
      setIndexOwner in class Constraint
      Parameters:
      index - the index
    • isBefore

      public boolean isBefore()
      Description copied from class: Constraint
      Check if this constraint needs to be checked before updating the data.
      Specified by:
      isBefore in class Constraint
      Returns:
      true if it must be checked before updating
    • checkExistingData

      public void checkExistingData(SessionLocal session)
      Description copied from class: Constraint
      Check the existing data. This method is called if the constraint is added after data has been inserted into the table.
      Specified by:
      checkExistingData in class Constraint
      Parameters:
      session - the session
    • getIndex

      public Index getIndex()
      Description copied from class: Constraint
      Get the index of this constraint in the source table, or null if no index is used.
      Overrides:
      getIndex in class Constraint
      Returns:
      the index
    • getReferencedConstraint

      public ConstraintUnique getReferencedConstraint()
      Description copied from class: Constraint
      Returns the referenced unique constraint, or null.
      Overrides:
      getReferencedConstraint in class Constraint
      Returns:
      the referenced unique constraint, or null