Package org.h2.constraint
Class ConstraintReferential
java.lang.Object
org.h2.engine.DbObject
org.h2.schema.SchemaObject
org.h2.constraint.Constraint
org.h2.constraint.ConstraintReferential
- All Implemented Interfaces:
Comparable<Constraint>
,HasSQL
A referential constraint.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.h2.constraint.Constraint
Constraint.Type
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IndexColumn[]
private ConstraintActionType
private String
private Index
private boolean
private IndexColumn[]
private ConstraintUnique
private Table
private boolean
private ConstraintActionType
private String
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 -
Method Summary
Modifier and TypeMethodDescriptionprivate void
appendUpdate
(StringBuilder builder) private void
appendWhere
(StringBuilder builder) private void
private void
void
checkExistingData
(SessionLocal session) Check the existing data.private void
checkRow
(SessionLocal session, Row oldRow) void
checkRow
(SessionLocal session, Table t, Row oldRow, Row newRow) Check if this row fulfils the constraint.private void
checkRowOwnTable
(SessionLocal session, Row oldRow, Row newRow) private void
checkRowRefTable
(SessionLocal session, Row oldRow, Row newRow) private boolean
existsRow
(SessionLocal session, Index searchIndex, SearchRow check, Row excluding) The constraint type nameConstruct the CREATE ...getCreateSQLForCopy
(Table forTable, String quotedName) Create the SQL statement of this object so a copy of the table can be made.getCreateSQLForCopy
(Table forTable, Table forRefTable, String quotedName, boolean internalIndex) Create the SQL statement of this object so a copy of the table can be made.Get the SQL statement to create this constraint.private Prepared
getDelete
(SessionLocal session) 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.private String
getShortDescription
(Index searchIndex, SearchRow check) Get a short description of the constraint.private Prepared
getUpdate
(SessionLocal session) boolean
isBefore()
Check if this constraint needs to be checked before updating the data.private boolean
private Prepared
prepare
(SessionLocal session, String sql, ConstraintActionType action) 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
setColumns
(IndexColumn[] cols) void
setDeleteAction
(ConstraintActionType action) Set the action to apply (restrict, cascade,...) on a delete.void
Set the index to use for this constraint.void
setIndexOwner
(Index index) This index is now the owner of the specified index.void
setRefColumns
(IndexColumn[] refCols) void
setRefConstraint
(ConstraintUnique refConstraint) Set the unique constraint of the referenced table to use for this constraint.void
setRefTable
(Table refTable) void
setUpdateAction
(ConstraintActionType action) Set the action to apply (restrict, cascade,...) on an update.private void
void
Update the constraint SQL when a referenced column is renamed.private void
updateWithSkipCheck
(Prepared prep) boolean
Check if this constraint needs the specified index.Methods inherited from class org.h2.constraint.Constraint
compareTo, getExpression, getTable, getType, isEverything, 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 Details
-
columns
-
refColumns
-
deleteAction
-
updateAction
-
refTable
-
index
-
refConstraint
-
indexOwner
private boolean indexOwner -
deleteSQL
-
updateSQL
-
skipOwnTable
private boolean skipOwnTable
-
-
Constructor Details
-
ConstraintReferential
-
-
Method Details
-
getConstraintType
Description copied from class:Constraint
The constraint type name- Specified by:
getConstraintType
in classConstraint
- Returns:
- the name
-
getCreateSQLForCopy
Create the SQL statement of this object so a copy of the table can be made.- Specified by:
getCreateSQLForCopy
in classDbObject
- Parameters:
forTable
- the table to create the object forquotedName
- the name of this object (quoted if necessary)- Returns:
- the SQL statement
-
getCreateSQLForCopy
public String getCreateSQLForCopy(Table forTable, Table forRefTable, String quotedName, boolean internalIndex) Create the SQL statement of this object so a copy of the table can be made.- Parameters:
forTable
- the table to create the object forforRefTable
- the referenced tablequotedName
- the name of this object (quoted if necessary)internalIndex
- add the index name to the statement- Returns:
- the SQL statement
-
getShortDescription
Get a short description of the constraint. This includes the constraint name (if set), and the constraint expression.- Parameters:
searchIndex
- the index, or nullcheck
- the row, or null- Returns:
- the description
-
getCreateSQLWithoutIndexes
Description copied from class:Constraint
Get the SQL statement to create this constraint.- Specified by:
getCreateSQLWithoutIndexes
in classConstraint
- Returns:
- the SQL statement
-
getCreateSQL
Description copied from class:DbObject
Construct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQL
in classDbObject
- Returns:
- the SQL statement
-
setColumns
-
getColumns
-
getReferencedColumns
Description copied from class:Constraint
Get all referenced columns.- Specified by:
getReferencedColumns
in classConstraint
- Parameters:
table
- the table- Returns:
- the set of referenced columns
-
setRefColumns
-
getRefColumns
-
setRefTable
-
setIndex
Set the index to use for this constraint.- Parameters:
index
- the indexisOwner
- true if the index is generated by the system and belongs to this constraint
-
setRefConstraint
Set the unique constraint of the referenced table to use for this constraint.- Parameters:
refConstraint
- the unique constraint
-
removeChildrenAndResources
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
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
-
checkRowOwnTable
-
existsRow
-
isEqual
-
checkRow
-
checkRowRefTable
-
updateWithSkipCheck
-
setWhere
-
getDeleteAction
-
setDeleteAction
Set the action to apply (restrict, cascade,...) on a delete.- Parameters:
action
- the action
-
updateOnTableColumnRename
public void updateOnTableColumnRename()Update the constraint SQL when a referenced column is renamed. -
buildDeleteSQL
private void buildDeleteSQL() -
getUpdate
-
getDelete
-
getUpdateAction
-
setUpdateAction
Set the action to apply (restrict, cascade,...) on an update.- Parameters:
action
- the action
-
buildUpdateSQL
private void buildUpdateSQL() -
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
-
prepare
-
appendUpdate
-
appendWhere
-
getRefTable
- Overrides:
getRefTable
in classConstraint
-
usesIndex
Description copied from class:Constraint
Check if this constraint needs the specified index.- Specified by:
usesIndex
in classConstraint
- Parameters:
idx
- the index- Returns:
- true if the index is used
-
setIndexOwner
Description copied from class:Constraint
This index is now the owner of the specified index.- Specified by:
setIndexOwner
in classConstraint
- Parameters:
index
- the index
-
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
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
-
getIndex
Description copied from class:Constraint
Get the index of this constraint in the source table, or null if no index is used.- Overrides:
getIndex
in classConstraint
- Returns:
- the index
-
getReferencedConstraint
Description copied from class:Constraint
Returns the referenced unique constraint, or null.- Overrides:
getReferencedConstraint
in classConstraint
- Returns:
- the referenced unique constraint, or null
-