Package org.h2.constraint
Class Constraint
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.constraint.Constraint
-
- All Implemented Interfaces:
java.lang.Comparable<Constraint>
,HasSQL
- Direct Known Subclasses:
ConstraintCheck
,ConstraintDomain
,ConstraintReferential
,ConstraintUnique
public abstract class Constraint extends SchemaObject implements java.lang.Comparable<Constraint>
The base class for constraint checking.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Constraint.Type
-
Field Summary
Fields Modifier and Type Field Description protected Table
table
The table for which this constraint is defined.-
Fields inherited from class org.h2.engine.DbObject
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER
-
Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS
-
-
Constructor Summary
Constructors Constructor Description Constraint(Schema schema, int id, java.lang.String name, Table table)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
checkExistingData(SessionLocal session)
Check the existing data.abstract void
checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)
Check if this row fulfils the constraint.int
compareTo(Constraint other)
abstract Constraint.Type
getConstraintType()
The constraint type nameabstract java.lang.String
getCreateSQLWithoutIndexes()
Get the SQL statement to create this constraint.Expression
getExpression()
Returns the CHECK expression or null.Index
getIndex()
Get the index of this constraint in the source table, or null if no index is used.abstract java.util.HashSet<Column>
getReferencedColumns(Table table)
Get all referenced columns.ConstraintUnique
getReferencedConstraint()
Returns the referenced unique constraint, or null.Table
getRefTable()
Table
getTable()
int
getType()
Get the object type.abstract boolean
isBefore()
Check if this constraint needs to be checked before updating the data.boolean
isEverything(ExpressionVisitor visitor)
Visit all elements in the constraint.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.SchemaObject
getSchema, getSQL, getSQL
-
Methods inherited from class org.h2.engine.DbObject
checkRename, getChildren, getComment, getCreateSQL, getCreateSQLForCopy, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, 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.util.HasSQL
getTraceSQL
-
-
-
-
Field Detail
-
table
protected Table table
The table for which this constraint is defined.
-
-
Method Detail
-
getConstraintType
public abstract Constraint.Type getConstraintType()
The constraint type name- Returns:
- the name
-
checkRow
public abstract void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)
Check if this row fulfils the constraint. This method throws an exception if not.- Parameters:
session
- the sessiont
- the tableoldRow
- the old rownewRow
- 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
-
getReferencedColumns
public abstract java.util.HashSet<Column> getReferencedColumns(Table table)
Get all referenced columns.- Parameters:
table
- the table- Returns:
- the set of referenced columns
-
getExpression
public Expression getExpression()
Returns the CHECK expression or null.- Returns:
- the CHECK expression or null.
-
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(SessionLocal 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).
-
getIndex
public Index getIndex()
Get the index of this constraint in the source table, or null if no index is used.- Returns:
- the index
-
getReferencedConstraint
public ConstraintUnique getReferencedConstraint()
Returns the referenced unique constraint, or null.- Returns:
- the referenced unique constraint, or null
-
getType
public int getType()
Description copied from class:DbObject
Get the object type.
-
getTable
public Table getTable()
-
getRefTable
public Table getRefTable()
-
compareTo
public int compareTo(Constraint other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Constraint>
-
isHidden
public boolean isHidden()
Description copied from class: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.- Overrides:
isHidden
in classSchemaObject
- Returns:
- true if it is hidden
-
isEverything
public boolean isEverything(ExpressionVisitor visitor)
Visit all elements in the constraint.- Parameters:
visitor
- the visitor- Returns:
- true if every visited expression returned true, or if there are no expressions
-
-