Top Description Inners Fields Constructors Methods
org.hsqldb

public final Class Constraint

extends Object
implements SchemaObject
Class Inheritance
All Implemented Interfaces
org.hsqldb.SchemaObject
Imports
org.hsqldb.HsqlNameManager.HsqlName, org.hsqldb.error.Error, .ErrorCode, org.hsqldb.index.Index, org.hsqldb.lib.ArrayUtil, .List, .OrderedHashSet, org.hsqldb.map.ValuePool, org.hsqldb.navigator.RangeIterator, .RowIterator, org.hsqldb.persist.PersistentStore, org.hsqldb.result.Result, org.hsqldb.rights.Grantee, org.hsqldb.types.Type

Implementation of a table constraint with references to the indexes used by the constraint.

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.6.0
Version
2.7.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Constraint.ConstraintCore

This class consists of the data structure for a Constraint.

Field Summary

Modifier and TypeField and Description
pack-priv Expression
pack-priv int
pack-priv Constraint.ConstraintCore
public static final Constraint[]
pack-priv boolean
private boolean
pack-priv boolean
pack-priv OrderedHashSet<String>
private HsqlNameManager.HsqlName
pack-priv int
pack-priv RangeVariable
pack-priv OrderedHashSet<String>

Constructor Summary

AccessConstructor and Description
private
public
Constraint(HsqlNameManager.HsqlName name, Table t, Index index, int type)

Constructor declaration for PK and UNIQUE

public
Constraint(HsqlNameManager.HsqlName name, Table table, int[] cols, int type)

public
Constraint(HsqlNameManager.HsqlName name, Constraint fkconstraint)

Constructor for main constraints (foreign key references in PK table)

public
Constraint(HsqlNameManager.HsqlName
name of constraint
name
,
HsqlNameManager.HsqlName refTableName, OrderedHashSet<String>
list of referencing columns
refCols
,
HsqlNameManager.HsqlName
referenced table
mainTableName
,
OrderedHashSet<String>
list of referenced columns
mainCols
,
int
constraint type
type
,
int
triggered action on delete
deleteAction
,
int
triggered action on update
updateAction
,
int matchType)

General constructor for foreign key constraints.

public
public
Constraint(HsqlNameManager.HsqlName uniqueName, HsqlNameManager.HsqlName mainName, HsqlNameManager.HsqlName refName, Table mainTable, Table refTable, int[] mainCols, int[] refCols, Index mainIndex, Index refIndex, int deleteAction, int updateAction)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
checkCheckConstraint(Session session, Table table, Object[] data)

pack-priv void
checkCheckConstraint(Session session, Table table, ColumnSchema column, Object data)

pack-priv void
pack-priv void
checkInsert(Session session, Table table, Object[] data, Object[] oldData)

Checks for foreign key or check constraint violation when inserting a row into the child table.

pack-priv void
checkReferencedRows(Session session, Table table)

Check used before creating a new foreign key cosntraint, this method checks all rows of a table to ensure they all have a corresponding row in the main table.

pack-priv Constraint
public void
extendFKIndexColumns(Session session, int[] colIndexExt)

pack-priv RowIterator

Returns:

iterator
findFkRef
(Session
Session
session
,
Object[]
array of objects for a database row
row
)

New method to find any referencing row for a foreign key (finds row in child table).

pack-priv RowIterator
findUniqueRows(Session session, Object[] row)

Finds a row matching the values in UNIQUE columns.

private static String
getActionString(int action)

Returns the foreign key action rule.

public String
public HsqlNameManager.HsqlName
public long
public OrderedHashSet<Expression>
public Expression
public String
getCheckSQL()

Returns the SQL for the expression in CHECK clause

public int
getConstraintType()

Returns the type of constraint

public int
public int
getDeleteAction()

The ON DELETE triggered action of (foreign key) constraint

public String
public HsqlException
private void
getFKStatement(StringBuilder sb)

Generates the foreign key declaration for a given Constraint object.

public Table
getMain()

Returns the main table

public int[]
getMainColumns()

Returns the main table column index array

public Index
getMainIndex()

Returns the main index

public HsqlNameManager.HsqlName
public HsqlNameManager.HsqlName
public HsqlNameManager.HsqlName
getName()

Implements org.hsqldb.SchemaObject.getName.

Returns the HsqlName.

private Expression
public Grantee
public Table
getRef()

Returns the reference table

public int[]
getRefColumns()

Returns the reference table column index array

public OrderedHashSet<HsqlNameManager.HsqlName>
public Index
getRefIndex()

Returns the reference index

public HsqlNameManager.HsqlName
public HsqlNameManager.HsqlName
public String
public int
public HsqlNameManager.HsqlName
public int
getUpdateAction()

The ON UPDATE triggered action of (foreign key) constraint

public String
pack-priv boolean
hasColumn(int colIndex)

pack-priv boolean
hasColumnOnly(int colIndex)

pack-priv boolean
hasColumnPlus(int colIndex)

public boolean
public boolean
pack-priv boolean
isEquivalent(Table mainTable, int[] mainCols, Table refTable, int[] refCols)

Compares this with another constraint column set.

public boolean
isNotNull()

Returns true if the expression in CHECK is a simple IS NOT NULL

public boolean
pack-priv boolean
isUniqueWithColumns(int[] cols)

Compares this with another constraint column set.

pack-priv void
pack-priv void
pack-priv void
recompile(Session session, Table newTable)

pack-priv void
pack-priv void
pack-priv void
updateTable(Session
Session
session
,
Table
reference to the old version of the table
oldTable
,
Table
reference to the new version of the table
newTable
,
int[]
indexes at which table column is added or removed
colIndex
,
int
-1, 0, +1 to indicate if column is added or removed
adjust
)

Used to update constrains to reflect structural changes in a table.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkback to summary
pack-priv Expression check
constTypeback to summary
pack-priv int constType
coreback to summary
pack-priv Constraint.ConstraintCore core
emptyArrayback to summary
public static final Constraint[] emptyArray

Hides org.hsqldb.SchemaObject.emptyArray.

isForwardback to summary
pack-priv boolean isForward
isNotNullback to summary
private boolean isNotNull
isSimpleIdentityPKback to summary
pack-priv boolean isSimpleIdentityPK
mainColSetback to summary
pack-priv OrderedHashSet<String> mainColSet
nameback to summary
private HsqlNameManager.HsqlName name
notNullColumnIndexback to summary
pack-priv int notNullColumnIndex
rangeVariableback to summary
pack-priv RangeVariable rangeVariable
refColSetback to summary
pack-priv OrderedHashSet<String> refColSet

Constructor Detail

Constraintback to summary
private Constraint()
Constraintback to summary
public Constraint(HsqlNameManager.HsqlName name, Table t, Index index, int type)

Constructor declaration for PK and UNIQUE

Constraintback to summary
public Constraint(HsqlNameManager.HsqlName name, Table table, int[] cols, int type)
Constraintback to summary
public Constraint(HsqlNameManager.HsqlName name, Constraint fkconstraint)

Constructor for main constraints (foreign key references in PK table)

Constraintback to summary
public Constraint(HsqlNameManager.HsqlName name, HsqlNameManager.HsqlName refTableName, OrderedHashSet<String> refCols, HsqlNameManager.HsqlName mainTableName, OrderedHashSet<String> mainCols, int type, int deleteAction, int updateAction, int matchType)

General constructor for foreign key constraints.

Parameters
name:HsqlNameManager.HsqlName

name of constraint

refCols:OrderedHashSet<String>

list of referencing columns

mainTableName:HsqlNameManager.HsqlName

referenced table

mainCols:OrderedHashSet<String>

list of referenced columns

type:int

constraint type

deleteAction:int

triggered action on delete

updateAction:int

triggered action on update

Constraintback to summary
public Constraint(HsqlNameManager.HsqlName name, OrderedHashSet<String> mainCols, int type)
Constraintback to summary
public Constraint(HsqlNameManager.HsqlName uniqueName, HsqlNameManager.HsqlName mainName, HsqlNameManager.HsqlName refName, Table mainTable, Table refTable, int[] mainCols, int[] refCols, Index mainIndex, Index refIndex, int deleteAction, int updateAction)

Method Detail

checkCheckConstraintback to summary
pack-priv void checkCheckConstraint(Session session, Table table, Object[] data)
checkCheckConstraintback to summary
pack-priv void checkCheckConstraint(Session session, Table table, ColumnSchema column, Object data)
checkCheckConstraintback to summary
pack-priv void checkCheckConstraint(Session session, Table table)
checkInsertback to summary
pack-priv void checkInsert(Session session, Table table, Object[] data, Object[] oldData)

Checks for foreign key or check constraint violation when inserting a row into the child table.

checkReferencedRowsback to summary
pack-priv void checkReferencedRows(Session session, Table table)

Check used before creating a new foreign key cosntraint, this method checks all rows of a table to ensure they all have a corresponding row in the main table.

duplicateback to summary
pack-priv Constraint duplicate()
extendFKIndexColumnsback to summary
public void extendFKIndexColumns(Session session, int[] colIndexExt)
findFkRefback to summary
pack-priv RowIterator findFkRef(Session session, Object[] row)

New method to find any referencing row for a foreign key (finds row in child table). If ON DELETE CASCADE is specified for this constraint, then the method finds the first row among the rows of the table ordered by the index and doesn't throw. Without ON DELETE CASCADE, the method attempts to find any row that exists. If no row is found, null is returned. (fredt@users)

Parameters
session:Session

Session

row:Object[]

array of objects for a database row

Returns:RowIterator

iterator

findUniqueRowsback to summary
pack-priv RowIterator findUniqueRows(Session session, Object[] row)

Finds a row matching the values in UNIQUE columns.

getActionStringback to summary
private static String getActionString(int action)

Returns the foreign key action rule.

getAlterSQLback to summary
public String getAlterSQL()
getCatalogNameback to summary
public HsqlNameManager.HsqlName getCatalogName()

Implements org.hsqldb.SchemaObject.getCatalogName.

getChangeTimestampback to summary
public long getChangeTimestamp()

Implements org.hsqldb.SchemaObject.getChangeTimestamp.

getCheckColumnExpressionsback to summary
public OrderedHashSet<Expression> getCheckColumnExpressions()
getCheckExpressionback to summary
public Expression getCheckExpression()
getCheckSQLback to summary
public String getCheckSQL()

Returns the SQL for the expression in CHECK clause

getConstraintTypeback to summary
public int getConstraintType()

Returns the type of constraint

getDeferabilityback to summary
public int getDeferability()
getDeleteActionback to summary
public int getDeleteAction()

The ON DELETE triggered action of (foreign key) constraint

getDeleteActionStringback to summary
public String getDeleteActionString()
getExceptionback to summary
public HsqlException getException(Object[] data)
getFKStatementback to summary
private void getFKStatement(StringBuilder sb)

Generates the foreign key declaration for a given Constraint object.

getMainback to summary
public Table getMain()

Returns the main table

getMainColumnsback to summary
public int[] getMainColumns()

Returns the main table column index array

getMainIndexback to summary
public Index getMainIndex()

Returns the main index

getMainNameback to summary
public HsqlNameManager.HsqlName getMainName()
getMainTableNameback to summary
public HsqlNameManager.HsqlName getMainTableName()
getNameback to summary
public HsqlNameManager.HsqlName getName()

Implements org.hsqldb.SchemaObject.getName.

Returns the HsqlName.

getNewCheckExpressionback to summary
private Expression getNewCheckExpression(Session session)
getOwnerback to summary
public Grantee getOwner()

Implements org.hsqldb.SchemaObject.getOwner.

getRefback to summary
public Table getRef()

Returns the reference table

getRefColumnsback to summary
public int[] getRefColumns()

Returns the reference table column index array

getReferencesback to summary
public OrderedHashSet<HsqlNameManager.HsqlName> getReferences()

Overrides default org.hsqldb.SchemaObject.getReferences.

getRefIndexback to summary
public Index getRefIndex()

Returns the reference index

getRefNameback to summary
public HsqlNameManager.HsqlName getRefName()
getSchemaNameback to summary
public HsqlNameManager.HsqlName getSchemaName()

Implements org.hsqldb.SchemaObject.getSchemaName.

getSQLback to summary
public String getSQL()

Implements org.hsqldb.SchemaObject.getSQL.

getTypeback to summary
public int getType()

Implements org.hsqldb.SchemaObject.getType.

getUniqueNameback to summary
public HsqlNameManager.HsqlName getUniqueName()
getUpdateActionback to summary
public int getUpdateAction()

The ON UPDATE triggered action of (foreign key) constraint

getUpdateActionStringback to summary
public String getUpdateActionString()
hasColumnback to summary
pack-priv boolean hasColumn(int colIndex)
hasColumnOnlyback to summary
pack-priv boolean hasColumnOnly(int colIndex)
hasColumnPlusback to summary
pack-priv boolean hasColumnPlus(int colIndex)
hasCoreTriggeredActionback to summary
public boolean hasCoreTriggeredAction()
hasTriggeredActionback to summary
public boolean hasTriggeredAction()
isEquivalentback to summary
pack-priv boolean isEquivalent(Table mainTable, int[] mainCols, Table refTable, int[] refCols)

Compares this with another constraint column set. This implementation only checks FOREIGN KEY constraints.

isNotNullback to summary
public boolean isNotNull()

Returns true if the expression in CHECK is a simple IS NOT NULL

isUniqueOrPKback to summary
public boolean isUniqueOrPK()
isUniqueWithColumnsback to summary
pack-priv boolean isUniqueWithColumns(int[] cols)

Compares this with another constraint column set. This is used only for UNIQUE constraints.

prepareCheckConstraintback to summary
pack-priv void prepareCheckConstraint(Session session, Table table)
prepareDomainCheckConstraintback to summary
pack-priv void prepareDomainCheckConstraint(Session session)
recompileback to summary
pack-priv void recompile(Session session, Table newTable)
setColumnsIndexesback to summary
pack-priv void setColumnsIndexes(Table table)
setSimpleIdentityPKback to summary
pack-priv void setSimpleIdentityPK()
updateTableback to summary
pack-priv void updateTable(Session session, Table oldTable, Table newTable, int[] colIndex, int adjust)

Used to update constrains to reflect structural changes in a table. Prior checks must ensure that this method does not throw.

Parameters
session:Session

Session

oldTable:Table

reference to the old version of the table

newTable:Table

reference to the new version of the table

colIndex:int[]

indexes at which table column is added or removed

adjust:int

-1, 0, +1 to indicate if column is added or removed

org.hsqldb back to summary

pack-priv Class Constraint.ConstraintCore

extends Object
Class Inheritance

This class consists of the data structure for a Constraint. This structure is shared between two Constraint Objects that together form a foreign key constraint. This simplifies structural modifications to a table. When changes to the column indexes are applied to the table's Constraint Objects, they are reflected in the Constraint Objects of any other table that shares a foreign key constraint with the modified table.
Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.1
Version
1.9.0

Field Summary

Modifier and TypeField and Description
pack-priv int[]
pack-priv int
pack-priv boolean
pack-priv boolean
pack-priv int[]
pack-priv Index
pack-priv HsqlNameManager.HsqlName
pack-priv Table
pack-priv HsqlNameManager.HsqlName
pack-priv int
pack-priv int[]
pack-priv Index
pack-priv HsqlNameManager.HsqlName
pack-priv Table
pack-priv HsqlNameManager.HsqlName
pack-priv HsqlNameManager.HsqlName
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Constraint.ConstraintCore
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addedRefColsback to summary
pack-priv int[] addedRefCols
deleteActionback to summary
pack-priv int deleteAction
hasDeleteActionback to summary
pack-priv boolean hasDeleteAction
hasUpdateActionback to summary
pack-priv boolean hasUpdateAction
mainColsback to summary
pack-priv int[] mainCols
mainIndexback to summary
pack-priv Index mainIndex
mainNameback to summary
pack-priv HsqlNameManager.HsqlName mainName
mainTableback to summary
pack-priv Table mainTable
mainTableNameback to summary
pack-priv HsqlNameManager.HsqlName mainTableName
matchTypeback to summary
pack-priv int matchType
refColsback to summary
pack-priv int[] refCols
refIndexback to summary
pack-priv Index refIndex
refNameback to summary
pack-priv HsqlNameManager.HsqlName refName
refTableback to summary
pack-priv Table refTable
refTableNameback to summary
pack-priv HsqlNameManager.HsqlName refTableName
uniqueNameback to summary
pack-priv HsqlNameManager.HsqlName uniqueName
updateActionback to summary
pack-priv int updateAction

Constructor Detail

ConstraintCoreback to summary
pack-priv ConstraintCore()

Method Detail

duplicateback to summary
pack-priv Constraint.ConstraintCore duplicate()