Top Description Inners Fields Constructors Methods
org.h2.constraint

public abstract Class Constraint

extends SchemaObject
implements Comparable<Constraint>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
org.h2.constraint.ConstraintCheck, org.h2.constraint.ConstraintDomain, org.h2.constraint.ConstraintReferential, org.h2.constraint.ConstraintUnique
Imports
java.util.HashSet, org.h2.engine.DbObject, .SessionLocal, org.h2.expression.Expression, .ExpressionVisitor, org.h2.index.Index, org.h2.message.Trace, org.h2.result.Row, org.h2.schema.Schema, .SchemaObject, org.h2.table.Column, .Table

The base class for constraint checking.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
protected Table
table

The table for which this constraint is defined.

Constructor Summary

AccessConstructor and Description
pack-priv
Constraint(Schema schema, int id, String name, Table table)

Method Summary

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

Check the existing data.

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

Check if this row fulfils the constraint.

public int
compareTo(Constraint
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public abstract Constraint.Type

Returns:

the name
getConstraintType
()

The constraint type name

public abstract String

Returns:

the SQL statement
getCreateSQLWithoutIndexes
()

Get the SQL statement to create this constraint.

public Expression

Returns:

the CHECK expression or null.
getExpression
()

Returns the CHECK expression or null.

public Index

Returns:

the index
getIndex
()

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

public abstract HashSet<Column>

Returns:

the set of referenced columns
getReferencedColumns
(Table
the table
table
)

Get all referenced columns.

public ConstraintUnique

Returns:

the referenced unique constraint, or null
getReferencedConstraint
()

Returns the referenced unique constraint, or null.

public Table
public Table
public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

public abstract boolean

Returns:

true if it must be checked before updating
isBefore
()

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

public boolean

Returns:

true if every visited expression returned true, or if there are no expressions
isEverything
(ExpressionVisitor
the visitor
visitor
)

Visit all elements in the constraint.

public abstract void
rebuild()

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

public abstract void
setIndexOwner(Index
the index
index
)

This index is now the owner of the specified index.

public abstract boolean

Returns:

true if the index is used
usesIndex
(Index
the index
index
)

Check if this constraint needs the specified index.

Inherited from org.h2.schema.SchemaObject:
getSchemagetSQLgetSQL

Field Detail

tableback to summary
protected Table table

The table for which this constraint is defined.

Constructor Detail

Constraintback to summary
pack-priv Constraint(Schema schema, int id, String name, Table table)

Method Detail

checkExistingDataback to summary
public abstract void checkExistingData(SessionLocal session)

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

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

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

compareToback to summary
public int compareTo(Constraint other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:Constraint

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
getConstraintTypeback to summary
public abstract Constraint.Type getConstraintType()

The constraint type name

Returns:Constraint.Type

the name

getCreateSQLWithoutIndexesback to summary
public abstract String getCreateSQLWithoutIndexes()

Get the SQL statement to create this constraint.

Returns:String

the SQL statement

getExpressionback to summary
public Expression getExpression()

Returns the CHECK expression or null.

Returns:Expression

the CHECK expression or null.

getIndexback to summary
public Index getIndex()

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

Returns:Index

the index

getReferencedColumnsback to summary
public abstract HashSet<Column> getReferencedColumns(Table table)

Get all referenced columns.

Parameters
table:Table

the table

Returns:HashSet<Column>

the set of referenced columns

getReferencedConstraintback to summary
public ConstraintUnique getReferencedConstraint()

Returns the referenced unique constraint, or null.

Returns:ConstraintUnique

the referenced unique constraint, or null

getRefTableback to summary
public Table getRefTable()
getTableback to summary
public Table getTable()
getTypeback to summary
public int getType()

Implements abstract org.h2.engine.DbObject.getType.

Doc from org.h2.engine.DbObject.getType.

Get the object type.

Returns:int

the object type

Annotations
@Override
isBeforeback to summary
public abstract boolean isBefore()

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

Returns:boolean

true if it must be checked before updating

isEverythingback to summary
public boolean isEverything(ExpressionVisitor visitor)

Visit all elements in the constraint.

Parameters
visitor:ExpressionVisitor

the visitor

Returns:boolean

true if every visited expression returned true, or if there are no expressions

rebuildback to summary
public abstract void rebuild()

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

setIndexOwnerback to summary
public abstract void setIndexOwner(Index index)

This index is now the owner of the specified index.

Parameters
index:Index

the index

usesIndexback to summary
public abstract boolean usesIndex(Index index)

Check if this constraint needs the specified index.

Parameters
index:Index

the index

Returns:boolean

true if the index is used

org.h2.constraint back to summary

public final Enum Constraint.Type

extends Enum<Constraint.Type>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Constraint.Type
CHECK

The constraint type for check constraints.

public static final Constraint.Type
DOMAIN

The constraint type for domain constraints.

public static final Constraint.Type
PRIMARY_KEY

The constraint type for primary key constraints.

public static final Constraint.Type
REFERENTIAL

The constraint type for referential constraints.

public static final Constraint.Type
UNIQUE

The constraint type for unique constraints.

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

standard SQL type name
getSqlName
()

Get standard SQL type name.

public boolean

Returns:

true if this type is a check or a domain type, false otherwise
isCheck
()

Tests whether this type is a check or domain type or not.

public boolean

Returns:

true if this type is a primary key or unique type, false otherwise
isUnique
()

Tests whether this type is a primary key or unique or not.

public static Constraint.Type
public static Constraint.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CHECKback to summary
public static final Constraint.Type CHECK

The constraint type for check constraints.

DOMAINback to summary
public static final Constraint.Type DOMAIN

The constraint type for domain constraints.

PRIMARY_KEYback to summary
public static final Constraint.Type PRIMARY_KEY

The constraint type for primary key constraints.

REFERENTIALback to summary
public static final Constraint.Type REFERENTIAL

The constraint type for referential constraints.

UNIQUEback to summary
public static final Constraint.Type UNIQUE

The constraint type for unique constraints.

Constructor Detail

Typeback to summary
private Type()

Method Detail

getSqlNameback to summary
public String getSqlName()

Get standard SQL type name.

Returns:String

standard SQL type name

isCheckback to summary
public boolean isCheck()

Tests whether this type is a check or domain type or not.

Returns:boolean

true if this type is a check or a domain type, false otherwise

isUniqueback to summary
public boolean isUnique()

Tests whether this type is a primary key or unique or not.

Returns:boolean

true if this type is a primary key or unique type, false otherwise

valueOfback to summary
public static Constraint.Type valueOf(String name)
valuesback to summary
public static Constraint.Type[] values()