Class UniqueConstraint
java.lang.Object
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.model.UniqueConstraint
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected ArrayListThe columns making up the constraint, asIndexColumnentries.protected StringThe name of the constraint.protected StringOptional name of an existing unique index that should back this constraint, emitted as aUSING INDEXclause. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColumn(IndexColumn column) Adds a column to this constraint, keeping the columns ordered by ordinal position (mirrorsIndexImpBase.addColumn(IndexColumn)).clone()booleanbooleanequalsIgnoreCase(UniqueConstraint other) Compares this constraint to another, ignoring the case of the name.getColumn(int idx) Returns the column at the given position.intReturns the number of columns in this constraint.Returns the columns of this constraint.getName()Returns the name of this constraint.Returns the name of the existing index this constraint should be pinned to via aUSING INDEXclause, or null to let the database pick/create one.booleanDetermines whether this constraint includes the given column.inthashCode()voidremoveColumn(int idx) Removes the column at the given position.voidremoveColumn(IndexColumn column) Removes the given column from this constraint.voidSets the name of this constraint.voidsetUsingIndexName(String usingIndexName) Sets the name of the existing index this constraint should be pinned to via aUSING INDEXclause.toString()Returns a verbose string representation of this constraint.
-
Field Details
-
_name
The name of the constraint. -
_usingIndexName
Optional name of an existing unique index that should back this constraint, emitted as aUSING INDEXclause. 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
The columns making up the constraint, asIndexColumnentries.
-
-
Constructor Details
-
UniqueConstraint
public UniqueConstraint()
-
-
Method Details
-
getName
Returns the name of this constraint.- Returns:
- the constraint name
-
setName
Sets the name of this constraint.- Parameters:
name- the constraint name
-
getUsingIndexName
Returns the name of the existing index this constraint should be pinned to via aUSING INDEXclause, or null to let the database pick/create one.- Returns:
- the backing index name, or null
-
setUsingIndexName
Sets the name of the existing index this constraint should be pinned to via aUSING INDEXclause.- Parameters:
usingIndexName- the backing index name
-
getColumnCount
public int getColumnCount()Returns the number of columns in this constraint.- Returns:
- the number of columns
-
getColumn
Returns the column at the given position.- Parameters:
idx- the position- Returns:
- the column
-
getColumns
Returns the columns of this constraint.- Returns:
- the columns
-
hasColumn
Determines whether this constraint includes the given column.- Parameters:
column- the column to look for- Returns:
trueif the column is part of this constraint
-
addColumn
Adds a column to this constraint, keeping the columns ordered by ordinal position (mirrorsIndexImpBase.addColumn(IndexColumn)).- Parameters:
column- the column to add
-
removeColumn
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
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
equals
-
equalsIgnoreCase
Compares this constraint to another, ignoring the case of the name. The column ordering and names must match. MirrorsUniqueIndex.equalsIgnoreCase(Index)so the comparator behaves the same way it does for unique indices.- Parameters:
other- the constraint to compare to- Returns:
trueif they are equal ignoring name case
-
hashCode
public int hashCode() -
toString
-
toVerboseString
Returns a verbose string representation of this constraint.- Returns:
- the string representation
-