java.lang.Object
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.model.UniqueConstraint
All Implemented Interfaces:
Serializable

public class UniqueConstraint extends Object implements Serializable
Represents a named UNIQUE CONSTRAINT on a table. This is intentionally a first-class concept that is distinct from a UniqueIndex. ddlutils historically modeled all uniqueness as a unique index (see UniqueIndex), but some databases (notably Oracle and PostgreSQL) require the referenced columns of a foreign key to be backed by a unique (or primary key) constraint rather than a bare unique index. A unique constraint is therefore modeled, emitted, and read back separately so the database-compare can keep it in sync and so foreign keys can reference it. The columns are reused from IndexColumn so that column comparison logic matches that of indices, but a UniqueConstraint is NOT an Index and is never stored in the table's index collection.
See Also:
  • Field Details

    • _name

      protected String _name
      The name of the constraint.
    • _usingIndexName

      protected String _usingIndexName
      Optional name of an existing unique index that should back this constraint, emitted as a USING INDEX clause. This is an emit-time detail only (it pins the constraint to a specific, separately-named index, e.g. on Oracle) and is deliberately NOT part of the constraint's identity -- a constraint read back from the catalog has no usingIndexName, so it must still compare equal to a declared constraint that does.
    • _columns

      protected ArrayList _columns
      The columns making up the constraint, as IndexColumn entries.
  • Constructor Details

    • UniqueConstraint

      public UniqueConstraint()
  • Method Details

    • getName

      public String getName()
      Returns the name of this constraint.
      Returns:
      the constraint name
    • setName

      public void setName(String name)
      Sets the name of this constraint.
      Parameters:
      name - the constraint name
    • getUsingIndexName

      public String getUsingIndexName()
      Returns the name of the existing index this constraint should be pinned to via a USING INDEX clause, or null to let the database pick/create one.
      Returns:
      the backing index name, or null
    • setUsingIndexName

      public void setUsingIndexName(String usingIndexName)
      Sets the name of the existing index this constraint should be pinned to via a USING INDEX clause.
      Parameters:
      usingIndexName - the backing index name
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns in this constraint.
      Returns:
      the number of columns
    • getColumn

      public IndexColumn getColumn(int idx)
      Returns the column at the given position.
      Parameters:
      idx - the position
      Returns:
      the column
    • getColumns

      public IndexColumn[] getColumns()
      Returns the columns of this constraint.
      Returns:
      the columns
    • hasColumn

      public boolean hasColumn(Column column)
      Determines whether this constraint includes the given column.
      Parameters:
      column - the column to look for
      Returns:
      true if the column is part of this constraint
    • addColumn

      public void addColumn(IndexColumn column)
      Adds a column to this constraint, keeping the columns ordered by ordinal position (mirrors IndexImpBase.addColumn(IndexColumn)).
      Parameters:
      column - the column to add
    • removeColumn

      public void removeColumn(IndexColumn column)
      Removes the given column from this constraint.
      Parameters:
      column - the column to remove
    • removeColumn

      public void removeColumn(int idx)
      Removes the column at the given position.
      Parameters:
      idx - the position of the column to remove
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • equals

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

      public boolean equalsIgnoreCase(UniqueConstraint other)
      Compares this constraint to another, ignoring the case of the name. The column ordering and names must match. Mirrors UniqueIndex.equalsIgnoreCase(Index) so the comparator behaves the same way it does for unique indices.
      Parameters:
      other - the constraint to compare to
      Returns:
      true if they are equal ignoring name case
    • hashCode

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

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

      public String toVerboseString()
      Returns a verbose string representation of this constraint.
      Returns:
      the string representation