Top Description Fields Constructors Methods
org.h2.constraint

public Class ConstraintReferential

extends Constraint
Class Inheritance
Imports
java.util.ArrayList, .HashSet, org.h2.api.ErrorCode, org.h2.command.Prepared, org.h2.engine.SessionLocal, org.h2.expression.Expression, .Parameter, org.h2.index.Cursor, .Index, org.h2.message.DbException, org.h2.result.ResultInterface, .Row, .SearchRow, org.h2.schema.Schema, org.h2.table.Column, .IndexColumn, .Table, org.h2.util.StringUtils, org.h2.value.Value, .ValueNull

A referential constraint.

Field Summary

Modifier and TypeField and Description
private IndexColumn[]
private ConstraintActionType
private String
private Index
private boolean
private IndexColumn[]
private ConstraintUnique
private Table
private boolean
private ConstraintActionType
private String
Inherited from org.h2.constraint.Constraint:
table

Constructor Summary

AccessConstructor and Description
public
ConstraintReferential(Schema schema, int id, String name, Table table)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
public void
checkExistingData(SessionLocal
the session
session
)

Implements abstract org.h2.constraint.Constraint.checkExistingData.

Check the existing data.

public void
checkRow(SessionLocal
the session
session
,
Table
the table
t
,
Row
the old row
oldRow
,
Row
the new row
newRow
)

Implements abstract org.h2.constraint.Constraint.checkRow.

Check if this row fulfils the constraint.

private void
checkRow(SessionLocal session, Row oldRow)

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)

public IndexColumn[]
public Constraint.Type
getConstraintType()

Implements abstract org.h2.constraint.Constraint.getConstraintType.

The constraint type name

public String
getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ...

public String

Returns:

the SQL statement
getCreateSQLForCopy
(Table
the table to create the object for
forTable
,
String
the name of this object (quoted if necessary)
quotedName
)

Overrides org.h2.engine.DbObject.getCreateSQLForCopy.

Create the SQL statement of this object so a copy of the table can be made.

public String

Returns:

the SQL statement
getCreateSQLForCopy
(Table
the table to create the object for
forTable
,
Table
the referenced table
forRefTable
,
String
the name of this object (quoted if necessary)
quotedName
,
boolean
add the index name to the statement
internalIndex
)

Create the SQL statement of this object so a copy of the table can be made.

public String
getCreateSQLWithoutIndexes()

Implements abstract org.h2.constraint.Constraint.getCreateSQLWithoutIndexes.

Get the SQL statement to create this constraint.

private Prepared
public ConstraintActionType
public Index
getIndex()

Overrides org.h2.constraint.Constraint.getIndex.

Get the index of this constraint in the source table, or null if no index is used.

public IndexColumn[]
public HashSet<Column>
getReferencedColumns(Table
the table
table
)

Implements abstract org.h2.constraint.Constraint.getReferencedColumns.

Get all referenced columns.

public ConstraintUnique
getReferencedConstraint()

Overrides org.h2.constraint.Constraint.getReferencedConstraint.

Returns the referenced unique constraint, or null.

public Table
private String

Returns:

the description
getShortDescription
(Index
the index, or null
searchIndex
,
SearchRow
the row, or null
check
)

Get a short description of the constraint.

private Prepared
public ConstraintActionType
public boolean
isBefore()

Implements abstract org.h2.constraint.Constraint.isBefore.

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

private boolean
isEqual(Row oldRow, Row newRow)

private Prepared
public void
rebuild()

Implements abstract org.h2.constraint.Constraint.rebuild.

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

public void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

public void
public void
setDeleteAction(ConstraintActionType
the action
action
)

Set the action to apply (restrict, cascade,...) on a delete.

public void
setIndex(Index
the index
index
,
boolean
true if the index is generated by the system and belongs to this constraint
isOwner
)

Set the index to use for this constraint.

public void
setIndexOwner(Index
the index
index
)

Implements abstract org.h2.constraint.Constraint.setIndexOwner.

This index is now the owner of the specified index.

public void
public void
setRefConstraint(ConstraintUnique
the unique constraint
refConstraint
)

Set the unique constraint of the referenced table to use for this constraint.

public void
setRefTable(Table refTable)

public void
setUpdateAction(ConstraintActionType
the action
action
)

Set the action to apply (restrict, cascade,...) on an update.

private void
setWhere(Prepared command, int pos, Row row)

public void
updateOnTableColumnRename()

Update the constraint SQL when a referenced column is renamed.

private void
public boolean
usesIndex(Index
the index
idx
)

Implements abstract org.h2.constraint.Constraint.usesIndex.

Check if this constraint needs the specified index.

Inherited from org.h2.constraint.Constraint:
compareTogetExpressiongetTablegetTypeisEverything

Field Detail

columnsback to summary
private IndexColumn[] columns
deleteActionback to summary
private ConstraintActionType deleteAction
deleteSQLback to summary
private String deleteSQL
indexback to summary
private Index index
indexOwnerback to summary
private boolean indexOwner
refColumnsback to summary
private IndexColumn[] refColumns
refConstraintback to summary
private ConstraintUnique refConstraint
refTableback to summary
private Table refTable
skipOwnTableback to summary
private boolean skipOwnTable
updateActionback to summary
private ConstraintActionType updateAction
updateSQLback to summary
private String updateSQL

Constructor Detail

ConstraintReferentialback to summary
public ConstraintReferential(Schema schema, int id, String name, Table table)

Method Detail

appendUpdateback to summary
private void appendUpdate(StringBuilder builder)
appendWhereback to summary
private void appendWhere(StringBuilder builder)
buildDeleteSQLback to summary
private void buildDeleteSQL()
buildUpdateSQLback to summary
private void buildUpdateSQL()
checkExistingDataback to summary
public void checkExistingData(SessionLocal session)

Implements abstract org.h2.constraint.Constraint.checkExistingData.

Doc from org.h2.constraint.Constraint.checkExistingData.

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

Parameters
session:SessionLocal

the session

Annotations
@Override
checkRowback to summary
public void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow)

Implements abstract org.h2.constraint.Constraint.checkRow.

Doc from org.h2.constraint.Constraint.checkRow.

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

Parameters
session:SessionLocal

the session

t:Table

the table

oldRow:Row

the old row

newRow:Row

the new row

Annotations
@Override
checkRowback to summary
private void checkRow(SessionLocal session, Row oldRow)
checkRowOwnTableback to summary
private void checkRowOwnTable(SessionLocal session, Row oldRow, Row newRow)
checkRowRefTableback to summary
private void checkRowRefTable(SessionLocal session, Row oldRow, Row newRow)
existsRowback to summary
private boolean existsRow(SessionLocal session, Index searchIndex, SearchRow check, Row excluding)
getColumnsback to summary
public IndexColumn[] getColumns()
getConstraintTypeback to summary
public Constraint.Type getConstraintType()

Implements abstract org.h2.constraint.Constraint.getConstraintType.

Doc from org.h2.constraint.Constraint.getConstraintType.

The constraint type name

Returns:Constraint.Type

the name

Annotations
@Override
getCreateSQLback to summary
public String getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Doc from org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getCreateSQLForCopyback to summary
public String getCreateSQLForCopy(Table forTable, String quotedName)

Overrides org.h2.engine.DbObject.getCreateSQLForCopy.

Create the SQL statement of this object so a copy of the table can be made.

Parameters
forTable:Table

the table to create the object for

quotedName:String

the name of this object (quoted if necessary)

Returns:String

the SQL statement

Annotations
@Override
getCreateSQLForCopyback to summary
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:Table

the table to create the object for

forRefTable:Table

the referenced table

quotedName:String

the name of this object (quoted if necessary)

internalIndex:boolean

add the index name to the statement

Returns:String

the SQL statement

getCreateSQLWithoutIndexesback to summary
public String getCreateSQLWithoutIndexes()

Implements abstract org.h2.constraint.Constraint.getCreateSQLWithoutIndexes.

Doc from org.h2.constraint.Constraint.getCreateSQLWithoutIndexes.

Get the SQL statement to create this constraint.

Returns:String

the SQL statement

Annotations
@Override
getDeleteback to summary
private Prepared getDelete(SessionLocal session)
getDeleteActionback to summary
public ConstraintActionType getDeleteAction()
getIndexback to summary
public Index getIndex()

Overrides org.h2.constraint.Constraint.getIndex.

Doc from org.h2.constraint.Constraint.getIndex.

Get the index of this constraint in the source table, or null if no index is used.

Returns:Index

the index

Annotations
@Override
getRefColumnsback to summary
public IndexColumn[] getRefColumns()
getReferencedColumnsback to summary
public HashSet<Column> getReferencedColumns(Table table)

Implements abstract org.h2.constraint.Constraint.getReferencedColumns.

Doc from org.h2.constraint.Constraint.getReferencedColumns.

Get all referenced columns.

Parameters
table:Table

the table

Returns:HashSet<Column>

the set of referenced columns

Annotations
@Override
getReferencedConstraintback to summary
public ConstraintUnique getReferencedConstraint()

Overrides org.h2.constraint.Constraint.getReferencedConstraint.

Doc from org.h2.constraint.Constraint.getReferencedConstraint.

Returns the referenced unique constraint, or null.

Returns:ConstraintUnique

the referenced unique constraint, or null

Annotations
@Override
getRefTableback to summary
public Table getRefTable()

Overrides org.h2.constraint.Constraint.getRefTable.

Annotations
@Override
getShortDescriptionback to summary
private String getShortDescription(Index searchIndex, SearchRow check)

Get a short description of the constraint. This includes the constraint name (if set), and the constraint expression.

Parameters
searchIndex:Index

the index, or null

check:SearchRow

the row, or null

Returns:String

the description

getUpdateback to summary
private Prepared getUpdate(SessionLocal session)
getUpdateActionback to summary
public ConstraintActionType getUpdateAction()
isBeforeback to summary
public boolean isBefore()

Implements abstract org.h2.constraint.Constraint.isBefore.

Doc from org.h2.constraint.Constraint.isBefore.

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

Returns:boolean

true if it must be checked before updating

Annotations
@Override
isEqualback to summary
private boolean isEqual(Row oldRow, Row newRow)
prepareback to summary
private Prepared prepare(SessionLocal session, String sql, ConstraintActionType action)
rebuildback to summary
public void rebuild()

Implements abstract org.h2.constraint.Constraint.rebuild.

Doc from org.h2.constraint.Constraint.rebuild.

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

Annotations
@Override
removeChildrenAndResourcesback to summary
public void removeChildrenAndResources(SessionLocal session)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Doc from org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

Parameters
session:SessionLocal

the session

Annotations
@Override
setColumnsback to summary
public void setColumns(IndexColumn[] cols)
setDeleteActionback to summary
public void setDeleteAction(ConstraintActionType action)

Set the action to apply (restrict, cascade,...) on a delete.

Parameters
action:ConstraintActionType

the action

setIndexback to summary
public void setIndex(Index index, boolean isOwner)

Set the index to use for this constraint.

Parameters
index:Index

the index

isOwner:boolean

true if the index is generated by the system and belongs to this constraint

setIndexOwnerback to summary
public void setIndexOwner(Index index)

Implements abstract org.h2.constraint.Constraint.setIndexOwner.

Doc from org.h2.constraint.Constraint.setIndexOwner.

This index is now the owner of the specified index.

Parameters
index:Index

the index

Annotations
@Override
setRefColumnsback to summary
public void setRefColumns(IndexColumn[] refCols)
setRefConstraintback to summary
public void setRefConstraint(ConstraintUnique refConstraint)

Set the unique constraint of the referenced table to use for this constraint.

Parameters
refConstraint:ConstraintUnique

the unique constraint

setRefTableback to summary
public void setRefTable(Table refTable)
setUpdateActionback to summary
public void setUpdateAction(ConstraintActionType action)

Set the action to apply (restrict, cascade,...) on an update.

Parameters
action:ConstraintActionType

the action

setWhereback to summary
private void setWhere(Prepared command, int pos, Row row)
updateOnTableColumnRenameback to summary
public void updateOnTableColumnRename()

Update the constraint SQL when a referenced column is renamed.

updateWithSkipCheckback to summary
private void updateWithSkipCheck(Prepared prep)
usesIndexback to summary
public boolean usesIndex(Index idx)

Implements abstract org.h2.constraint.Constraint.usesIndex.

Doc from org.h2.constraint.Constraint.usesIndex.

Check if this constraint needs the specified index.

Parameters
idx:Index

the index

Returns:boolean

true if the index is used

Annotations
@Override