## org.h2.constraint
Class Constraint

    java.lang.Object
      org.h2.engine.DbObjectBase
          org.h2.schema.SchemaObjectBase
              org.h2.constraint.Constraint

All Implemented Interfaces:
  java.lang.Comparable<Constraint>, DbObject, SchemaObject

Direct Known Subclasses:
  ConstraintCheck, ConstraintReferential, ConstraintUnique

    public abstract class Constraint

extends SchemaObjectBase
implements java.lang.Comparable<Constraint>

The base class for constraint checking.

Field Summary
`static java.lang.String` `CHECK` The constraint type name for check constraints.
`static java.lang.String` `PRIMARY_KEY` The constraint type name for primary key constraints.
`static java.lang.String` `REFERENTIAL` The constraint type name for referential constraints.
`protected Table` `table` The table for which this constraint is defined.
`static java.lang.String` `UNIQUE` The constraint type name for unique constraints.

Fields inherited from class org.h2.engine.DbObjectBase
`comment, database, trace`

Fields inherited from interface org.h2.engine.DbObject
`AGGREGATE, COMMENT, CONSTANT, CONSTRAINT, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, TABLE_OR_VIEW, TRIGGER, USER, USER_DATATYPE`

Constructor Summary
`Constraint(Schema schema, int id, java.lang.String name, Table table)`

Method Summary
`abstract void` `checkExistingData(Session session)` Check the existing data.
`void` `checkRename()` Check if this object can be renamed.
`abstract void` `checkRow(Session session, Table t, Row oldRow, Row newRow)` Check if this row fulfils the constraint.
`int` `compareTo(Constraint other)`
`abstract boolean` `containsColumn(Column col)` Check if this constraint contains the given column.
`abstract java.lang.String` `getConstraintType()` The constraint type name
`abstract java.lang.String` `getCreateSQLWithoutIndexes()` Get the SQL statement to create this constraint.
`java.lang.String` `getDropSQL()` Build a SQL statement to drop this object.
`Table` `getRefTable()`
`Table` `getTable()`
`int` `getType()` Get the object type.
`abstract Index` `getUniqueIndex()` Get the unique index used to enforce this constraint, or null if no index is used.
`abstract boolean` `isBefore()` Check if this constraint needs to be checked before updating the data.
`boolean` `isHidden()` Check whether this is a hidden object that doesn't appear in the meta data and in the script, and is not dropped on DROP ALL OBJECTS.
`abstract void` `rebuild()` This method is called after a related table has changed (the table was renamed, or columns have been renamed).
`abstract void` `setIndexOwner(Index index)` This index is now the owner of the specified index.
`abstract boolean` `usesIndex(Index index)` Check if this constraint needs the specified index.

Methods inherited from class org.h2.schema.SchemaObjectBase
`getSchema, getSQL, initSchemaObjectBase`

Methods inherited from class org.h2.engine.DbObjectBase
`getChildren, getComment, getCreateSQL, getCreateSQLForCopy, getDatabase, getId, getModificationId, getName, initDbObjectBase, invalidate, isTemporary, removeChildrenAndResources, rename, setComment, setModified, setObjectName, setTemporary, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.h2.engine.DbObject
`getChildren, getComment, getCreateSQL, getCreateSQLForCopy, getDatabase, getId, getModificationId, getName, isTemporary, removeChildrenAndResources, rename, setComment, setModified, setTemporary`

Field Detail

### CHECK

    public static final java.lang.String CHECK

  The constraint type name for check constraints.

  See Also:
    Constant Field Values

### REFERENTIAL

    public static final java.lang.String REFERENTIAL

  The constraint type name for referential constraints.

  See Also:
    Constant Field Values

### UNIQUE

    public static final java.lang.String UNIQUE

  The constraint type name for unique constraints.

  See Also:
    Constant Field Values

### PRIMARY_KEY

    public static final java.lang.String PRIMARY_KEY

  The constraint type name for primary key constraints.

  See Also:
    Constant Field Values

### table

    protected Table table

  The table for which this constraint is defined.

Constructor Detail

### Constraint

    public Constraint(Schema schema,
                      int id,
                      java.lang.String name,
                      Table table)

Method Detail

### getConstraintType

    public abstract java.lang.String getConstraintType()

  The constraint type name

  Returns:
    the name

### checkRow

    public abstract void checkRow(Session session,
                                  Table t,
                                  Row oldRow,
                                  Row newRow)

  Check if this row fulfils the constraint. This method throws an exception if not.

  Parameters:
    `session` - the session
    `t` - the table
    `oldRow` - the old row
    `newRow` - the new row

### usesIndex

    public abstract boolean usesIndex(Index index)

  Check if this constraint needs the specified index.

  Parameters:
    `index` - the index
  Returns:
    true if the index is used

### setIndexOwner

    public abstract void setIndexOwner(Index index)

  This index is now the owner of the specified index.

  Parameters:
    `index` - the index

### containsColumn

    public abstract boolean containsColumn(Column col)

  Check if this constraint contains the given column.

  Parameters:
    `col` - the column
  Returns:
    true if it does

### getCreateSQLWithoutIndexes

    public abstract java.lang.String getCreateSQLWithoutIndexes()

  Get the SQL statement to create this constraint.

  Returns:
    the SQL statement

### isBefore

    public abstract boolean isBefore()

  Check if this constraint needs to be checked before updating the data.

  Returns:
    true if it must be checked before updating

### checkExistingData

    public abstract void checkExistingData(Session session)

  Check the existing data. This method is called if the constraint is added after data has been inserted into the table.

  Parameters:
    `session` - the session

### rebuild

    public abstract void rebuild()

  This method is called after a related table has changed (the table was renamed, or columns have been renamed).

### getUniqueIndex

    public abstract Index getUniqueIndex()

  Get the unique index used to enforce this constraint, or null if no index is used.

  Returns:
    the index

### checkRename

    public void checkRename()

  Description copied from class: `DbObjectBase`
  Check if this object can be renamed. System objects may not be renamed.

  Specified by:
    `checkRename` in interface `DbObject`
  Specified by:
    `checkRename` in class `DbObjectBase`

### getType

    public int getType()

  Description copied from class: `DbObjectBase`
  Get the object type.

  Specified by:
    `getType` in interface `DbObject`
  Specified by:
    `getType` in class `DbObjectBase`
  Returns:
    the object type

### getTable

    public Table getTable()

### getRefTable

    public Table getRefTable()

### getDropSQL

    public java.lang.String getDropSQL()

  Description copied from class: `DbObjectBase`
  Build a SQL statement to drop this object.

  Specified by:
    `getDropSQL` in interface `DbObject`
  Specified by:
    `getDropSQL` in class `DbObjectBase`
  Returns:
    the SQL statement

### compareTo

    public int compareTo(Constraint other)

  Specified by:
    `compareTo` in interface `java.lang.Comparable<Constraint>`

### isHidden

    public boolean isHidden()

  Description copied from interface: `SchemaObject`
  Check whether this is a hidden object that doesn't appear in the meta data and in the script, and is not dropped on DROP ALL OBJECTS.

  Specified by:
    `isHidden` in interface `SchemaObject`
  Overrides:
    `isHidden` in class `SchemaObjectBase`
  Returns:
    true if it is hidden