Package org.h2.constraint
Class Constraint
java.lang.Object
org.h2.engine.DbObject
org.h2.schema.SchemaObject
org.h2.constraint.Constraint
- All Implemented Interfaces:
Comparable<Constraint>
,HasSQL
- Direct Known Subclasses:
ConstraintCheck
,ConstraintDomain
,ConstraintReferential
,ConstraintUnique
The base class for constraint checking.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields 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 -
Method Summary
Modifier and TypeMethodDescriptionabstract 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
The constraint type nameabstract String
Get the SQL statement to create this constraint.Returns the CHECK expression or null.getIndex()
Get the index of this constraint in the source table, or null if no index is used.getReferencedColumns
(Table table) Get all referenced columns.Returns the referenced unique constraint, or null.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
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 Details
-
table
The table for which this constraint is defined.
-
-
Constructor Details
-
Constraint
-
-
Method Details
-
getConstraintType
The constraint type name- Returns:
- the name
-
checkRow
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
Check if this constraint needs the specified index.- Parameters:
index
- the index- Returns:
- true if the index is used
-
setIndexOwner
This index is now the owner of the specified index.- Parameters:
index
- the index
-
getReferencedColumns
Get all referenced columns.- Parameters:
table
- the table- Returns:
- the set of referenced columns
-
getExpression
Returns the CHECK expression or null.- Returns:
- the CHECK expression or null.
-
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
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
Get the index of this constraint in the source table, or null if no index is used.- Returns:
- the index
-
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
-
getRefTable
-
compareTo
- Specified by:
compareTo
in interfaceComparable<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
Visit all elements in the constraint.- Parameters:
visitor
- the visitor- Returns:
- true if every visited expression returned true, or if there are no expressions
-