Package org.h2.constraint
Class ConstraintDomain
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.constraint.Constraint
-
- org.h2.constraint.ConstraintDomain
-
- All Implemented Interfaces:
java.lang.Comparable<Constraint>
,HasSQL
public class ConstraintDomain extends Constraint
A domain constraint.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ConstraintDomain.CheckExistingData
-
Nested classes/interfaces inherited from class org.h2.constraint.Constraint
Constraint.Type
-
-
Field Summary
Fields Modifier and Type Field Description private Domain
domain
private Expression
expr
private DomainColumnResolver
resolver
-
Fields inherited from class org.h2.constraint.Constraint
table
-
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 ConstraintDomain(Schema schema, int id, java.lang.String name, Domain domain)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
check(SessionLocal session, Value value)
Check the specified value.void
checkExistingData(SessionLocal session)
Check the existing data.void
checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)
Check if this row fulfils the constraint.Expression
getCheckConstraint(SessionLocal session, java.lang.String columnName)
Get the check constraint expression for this column.Constraint.Type
getConstraintType()
The constraint type namejava.lang.String
getCreateSQL()
Construct the CREATE ...java.lang.String
getCreateSQLForCopy(Table forTable, java.lang.String quotedName)
Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different tablejava.lang.String
getCreateSQLWithoutIndexes()
Get the SQL statement to create this constraint.Domain
getDomain()
Returns the domain of this constraint.Expression
getExpression()
Returns the CHECK expression or null.java.util.HashSet<Column>
getReferencedColumns(Table table)
Get all referenced columns.boolean
isBefore()
Check if this constraint needs to be checked before updating the data.boolean
isEverything(ExpressionVisitor visitor)
Visit all elements in the constraint.void
rebuild()
This method is called after a related table has changed (the table was renamed, or columns have been renamed).void
removeChildrenAndResources(SessionLocal session)
Delete all dependent children objects and resources of this object.void
setExpression(SessionLocal session, Expression expr)
Set the expression.void
setIndexOwner(Index index)
This index is now the owner of the specified index.boolean
usesIndex(Index index)
Check if this constraint needs the specified index.-
Methods inherited from class org.h2.constraint.Constraint
compareTo, getIndex, getReferencedConstraint, getRefTable, getTable, getType, isHidden
-
Methods inherited from class org.h2.schema.SchemaObject
getSchema, getSQL, getSQL
-
Methods inherited from class org.h2.engine.DbObject
checkRename, getChildren, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, 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
-
domain
private Domain domain
-
expr
private Expression expr
-
resolver
private DomainColumnResolver resolver
-
-
Method Detail
-
getConstraintType
public Constraint.Type getConstraintType()
Description copied from class:Constraint
The constraint type name- Specified by:
getConstraintType
in classConstraint
- Returns:
- the name
-
getDomain
public Domain getDomain()
Returns the domain of this constraint.- Returns:
- the domain
-
setExpression
public void setExpression(SessionLocal session, Expression expr)
Set the expression.- Parameters:
session
- the sessionexpr
- the expression
-
getCreateSQLForCopy
public java.lang.String getCreateSQLForCopy(Table forTable, java.lang.String quotedName)
Description copied from class:DbObject
Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table- Specified by:
getCreateSQLForCopy
in classDbObject
- Parameters:
forTable
- the new tablequotedName
- the quoted name- Returns:
- the SQL statement
-
getCreateSQLWithoutIndexes
public java.lang.String getCreateSQLWithoutIndexes()
Description copied from class:Constraint
Get the SQL statement to create this constraint.- Specified by:
getCreateSQLWithoutIndexes
in classConstraint
- Returns:
- the SQL statement
-
getCreateSQL
public java.lang.String getCreateSQL()
Description copied from class:DbObject
Construct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQL
in classDbObject
- Returns:
- the SQL statement
-
removeChildrenAndResources
public void removeChildrenAndResources(SessionLocal session)
Description copied from class:DbObject
Delete all dependent children objects and resources of this object.- Specified by:
removeChildrenAndResources
in classDbObject
- Parameters:
session
- the session
-
checkRow
public void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)
Description copied from class:Constraint
Check if this row fulfils the constraint. This method throws an exception if not.- Specified by:
checkRow
in classConstraint
- Parameters:
session
- the sessiont
- the tableoldRow
- the old rownewRow
- the new row
-
check
public void check(SessionLocal session, Value value)
Check the specified value.- Parameters:
session
- the sessionvalue
- the value to check
-
getCheckConstraint
public Expression getCheckConstraint(SessionLocal session, java.lang.String columnName)
Get the check constraint expression for this column.- Parameters:
session
- the sessioncolumnName
- the column name- Returns:
- the expression
-
usesIndex
public boolean usesIndex(Index index)
Description copied from class:Constraint
Check if this constraint needs the specified index.- Specified by:
usesIndex
in classConstraint
- Parameters:
index
- the index- Returns:
- true if the index is used
-
setIndexOwner
public void setIndexOwner(Index index)
Description copied from class:Constraint
This index is now the owner of the specified index.- Specified by:
setIndexOwner
in classConstraint
- Parameters:
index
- the index
-
getReferencedColumns
public java.util.HashSet<Column> getReferencedColumns(Table table)
Description copied from class:Constraint
Get all referenced columns.- Specified by:
getReferencedColumns
in classConstraint
- Parameters:
table
- the table- Returns:
- the set of referenced columns
-
getExpression
public Expression getExpression()
Description copied from class:Constraint
Returns the CHECK expression or null.- Overrides:
getExpression
in classConstraint
- Returns:
- the CHECK expression or null.
-
isBefore
public boolean isBefore()
Description copied from class:Constraint
Check if this constraint needs to be checked before updating the data.- Specified by:
isBefore
in classConstraint
- Returns:
- true if it must be checked before updating
-
checkExistingData
public void checkExistingData(SessionLocal session)
Description copied from class:Constraint
Check the existing data. This method is called if the constraint is added after data has been inserted into the table.- Specified by:
checkExistingData
in classConstraint
- Parameters:
session
- the session
-
rebuild
public void rebuild()
Description copied from class:Constraint
This method is called after a related table has changed (the table was renamed, or columns have been renamed).- Specified by:
rebuild
in classConstraint
-
isEverything
public boolean isEverything(ExpressionVisitor visitor)
Description copied from class:Constraint
Visit all elements in the constraint.- Overrides:
isEverything
in classConstraint
- Parameters:
visitor
- the visitor- Returns:
- true if every visited expression returned true, or if there are no expressions
-
-