Top Description Fields Constructors Methods
org.apache.derby.iapi.sql.dictionary

public abstract Class ConstraintDescriptor

extends UniqueTupleDescriptor
implements Provider, Dependent
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.depend.Dependent, org.apache.derby.catalog.Dependable, org.apache.derby.iapi.sql.depend.Provider
Known Direct Subclasses
org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor, org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor
Imports
java.util.Arrays, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.sql.depend.Provider, .Dependent, .DependencyManager, org.apache.derby.catalog.UUID, .DependableFinder, .Dependable, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.util.ArrayUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.StoredFormatIds, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.store.access.TransactionController

This class is used to get information from a ConstraintDescriptor. A ConstraintDescriptor can represent a constraint on a table or on a column.
Version
0.1

Field Summary

Modifier and TypeField and Description
public static final int
private ColumnDescriptorList
pack-priv final UUID
pack-priv final String
private boolean
public static final int
public static final int
private boolean
private boolean
private final int[]
private final SchemaDescriptor
public static final int
pack-priv TableDescriptor

Constructor Summary

AccessConstructor and Description
pack-priv
ConstraintDescriptor(DataDictionary
The data dictionary that this descriptor lives in
dataDictionary
,
TableDescriptor
The descriptor of the table the constraint is on
table
,
String
The name of the constraint.
constraintName
,
boolean
If the constraint can be deferred.
deferrable
,
boolean
If the constraint starts life deferred.
initiallyDeferred
,
int[]
columns that the constraint references
referencedColumns
,
UUID
UUID of constraint
constraintId
,
SchemaDescriptor
SchemaDescriptor
schemaDesc
,
boolean
Is the constraint enforced?
enforced
)

Constructor for a ConstraintDescriptor

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true/false
areColumnsComparable
(ColumnDescriptorList
the columns to compare
otherColumns
)

Indicates whether the column descriptor list is type comparable with the constraints columns.

public boolean
columnIntersects(int[]
columns to check Note-- this is not a static method.
columnArray
)

Does a column intersect with our referenced columns

public boolean

Returns:

TRUE if the constraint is DEFERRABLE, FALSE if it is NOT DEFERRABLE.
deferrable
()

Returns TRUE if the constraint is deferrable

pack-priv static boolean

Returns:

true/false
doColumnsIntersect
(int[]
the columns to compare. If null, asssumed to mean all columns
otherColumns
,
int[]
the columns referenced by the caller
referencedColumns
)

Does a column in the input set intersect with our referenced columns?

public ConglomerateDescriptor

Returns:

If the backing conglomerate for this constraint was a) dropped and b) shared by other constraints/indexes, then this method will return a ConglomerateDescriptor that describes what a new backing conglomerate must look like to stay "sharable" across the remaining constraints/indexes. It is then up to the caller to create a corresponding conglomerate. We don't create the conglomerate here because depending on who called us, it might not make sense to create it--ex. if we get here because of a DROP TABLE, the DropTable action doesn't need to create a new backing conglomerate since the table (and all of its constraints/indexes) are going to disappear anyway.
drop
(LanguageConnectionContext lcc, boolean clearDependencies)

Drop the constraint.

public boolean

Returns:

true/false
enforced
()

Is this constraint enforced?

public String

Returns:

char The provider's type.
getClassType
()

Implements org.apache.derby.catalog.Dependable.getClassType.

Get the provider's type.

public ColumnDescriptorList

Returns:

the column descriptor list
getColumnDescriptors
()

Get the column descriptors for all the columns referenced by this constraint.

public abstract UUID
public String

Returns:

A String containing the name of the constraint.
getConstraintName
()

Gets the name of the constraint.

public String

Returns:

The constraint text.
getConstraintText
()

Get the text of the constraint.

public abstract int

Returns:

An identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).
getConstraintType
()

Gets an identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).

public DependableFinder

Returns:

the stored form of this provider
getDependableFinder
()

Implements org.apache.derby.catalog.Dependable.getDependableFinder.

Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.

public String
public String
getDescriptorType()

Overrides org.apache.derby.iapi.sql.dictionary.TupleDescriptor.getDescriptorType.

Each descriptor must identify itself with its type; i.e index, check constraint whatever.

public int[]
getKeyColumns()

Resolve

For now the ConstraintDescriptor code stores the array of key columns in the field 'otherColumns'.

public UUID

Returns:

The provider's UUID
getObjectID
()

Implements org.apache.derby.catalog.Dependable.getObjectID.

Get the provider's UUID

public String

Returns:

String The name of this provider.
getObjectName
()

Implements org.apache.derby.catalog.Dependable.getObjectName.

Return the name of this Provider.

public int

Returns:

the number of fks
getReferenceCount
()

Get the number of enforced fks that reference this key.

public int[]

Returns:

An array of column ids for those constraints that can be on columns (primary, unique key, referential constraints, and check constraints). For check and unique constraints, it returns an array of columns ids that are referenced in the constraint. For primary key and referential constraints, it returns an array of column ids for the columns in this table (i.e. the primary key columns for a primary key constraint, and the foreign key columns for a foreign key constraint.
getReferencedColumns
()

Returns an array of column ids (i.e. ordinal positions) for the columns referenced in this table for a primary key, unique key, referential, or check constraint.

public SchemaDescriptor

Returns:

SchemaDescriptor The SchemaDescriptor for this constraint.
getSchemaDescriptor
()

Get the SchemaDescriptor for the schema that this constraint belongs to.

public TableDescriptor

Returns:

the table descriptor
getTableDescriptor
()

Get the table descriptor upon which this constraint is declared.

public UUID

Returns:

The UUID of the table the constraint is on.
getTableId
()

Gets the UUID of the table the constraint is on.

public UUID

Returns:

The UUID of the constraint.
getUUID
()

Implements abstract org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor.getUUID.

Gets the UUID of the constraint.

public abstract boolean

Returns:

boolean Whether or not there is a backing index for this constraint.
hasBackingIndex
()

Does this constraint have a backing index?

public boolean

Returns:

TRUE if the constraint is initially DEFERRED, FALSE if the constraint is initially IMMEDIATE
initiallyDeferred
()

Returns TRUE if the constraint is initially deferred

public boolean

Returns:

false
isReferenced
()

Is this constraint referenced?

public synchronized boolean

Returns:

true if the dependent is currently valid
isValid
()

Implements org.apache.derby.iapi.sql.depend.Dependent.isValid.

Check that all of the dependent's dependencies are valid.

public void
makeInvalid(int
The action causing the invalidation
action
,
LanguageConnectionContext
The LanguageConnectionContext
lcc
)

Implements org.apache.derby.iapi.sql.depend.Dependent.makeInvalid.

Mark the dependent as invalid (due to at least one of its dependencies being invalid).

public abstract boolean

Returns:

true/false
needsToFire
(int
the type of DML (StatementType.INSERT|StatementType.UPDATE|StatementType.DELETE)
stmtType
,
int[]
the columns modified, or null for all
modifiedCols
)

Does this constraint need to fire on this type of DML?

public void
prepareToInvalidate(Provider
the provider
p
,
int
The action causing the invalidation
action
,
LanguageConnectionContext
The LanguageConnectionContext
lcc
)

Implements org.apache.derby.iapi.sql.depend.Dependent.prepareToInvalidate.

Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).

public void
setDeferrable(boolean b)

public void
setEnforced(boolean b)

public void
public String

Returns:

A String representation of this ColumnDescriptor
toString
()

Overrides java.lang.Object.toString.

Convert the ColumnDescriptor to a String.

Field Detail

ALLback to summary
public static final int ALL
colDLback to summary
private ColumnDescriptorList colDL
constraintIdback to summary
pack-priv final UUID constraintId
constraintNameback to summary
pack-priv final String constraintName
deferrableback to summary
private boolean deferrable
DISABLEDback to summary
public static final int DISABLED
ENABLEDback to summary
public static final int ENABLED
enforcedback to summary
private boolean enforced
initiallyDeferredback to summary
private boolean initiallyDeferred
referencedColumnsback to summary
private final int[] referencedColumns
schemaDescback to summary
private final SchemaDescriptor schemaDesc
SYSCONSTRAINTS_STATE_FIELDback to summary
public static final int SYSCONSTRAINTS_STATE_FIELD
tableback to summary
pack-priv TableDescriptor table

Constructor Detail

ConstraintDescriptorback to summary
pack-priv ConstraintDescriptor(DataDictionary dataDictionary, TableDescriptor table, String constraintName, boolean deferrable, boolean initiallyDeferred, int[] referencedColumns, UUID constraintId, SchemaDescriptor schemaDesc, boolean enforced)

Constructor for a ConstraintDescriptor

Parameters
dataDictionary:DataDictionary

The data dictionary that this descriptor lives in

table:TableDescriptor

The descriptor of the table the constraint is on

constraintName:String

The name of the constraint.

deferrable:boolean

If the constraint can be deferred.

initiallyDeferred:boolean

If the constraint starts life deferred.

referencedColumns:int[]

columns that the constraint references

constraintId:UUID

UUID of constraint

schemaDesc:SchemaDescriptor

SchemaDescriptor

enforced:boolean

Is the constraint enforced?

Method Detail

areColumnsComparableback to summary
public boolean areColumnsComparable(ColumnDescriptorList otherColumns) throws StandardException

Indicates whether the column descriptor list is type comparable with the constraints columns. The types have to be identical AND in the same order to succeed.

Parameters
otherColumns:ColumnDescriptorList

the columns to compare

Returns:boolean

true/false

Exceptions
StandardException:
on error
columnIntersectsback to summary
public boolean columnIntersects(int[] columnArray)

Does a column intersect with our referenced columns

Parameters
columnArray:int[]

columns to check Note-- this is not a static method.

deferrableback to summary
public boolean deferrable()

Returns TRUE if the constraint is deferrable

Returns:boolean

TRUE if the constraint is DEFERRABLE, FALSE if it is NOT DEFERRABLE.

doColumnsIntersectback to summary
pack-priv static boolean doColumnsIntersect(int[] otherColumns, int[] referencedColumns)

Does a column in the input set intersect with our referenced columns?

Parameters
otherColumns:int[]

the columns to compare. If null, asssumed to mean all columns

referencedColumns:int[]

the columns referenced by the caller

Returns:boolean

true/false

dropback to summary
public ConglomerateDescriptor drop(LanguageConnectionContext lcc, boolean clearDependencies) throws StandardException

Drop the constraint. Clears dependencies, drops the backing index and removes the constraint from the list on the table descriptor. Does NOT do an dm.invalidateFor()

Returns:ConglomerateDescriptor

If the backing conglomerate for this constraint was a) dropped and b) shared by other constraints/indexes, then this method will return a ConglomerateDescriptor that describes what a new backing conglomerate must look like to stay "sharable" across the remaining constraints/indexes. It is then up to the caller to create a corresponding conglomerate. We don't create the conglomerate here because depending on who called us, it might not make sense to create it--ex. if we get here because of a DROP TABLE, the DropTable action doesn't need to create a new backing conglomerate since the table (and all of its constraints/indexes) are going to disappear anyway.

enforcedback to summary
public boolean enforced()

Is this constraint enforced?

Returns:boolean

true/false

getClassTypeback to summary
public String getClassType()

Implements org.apache.derby.catalog.Dependable.getClassType.

Get the provider's type.

Returns:String

char The provider's type.

getColumnDescriptorsback to summary
public ColumnDescriptorList getColumnDescriptors() throws StandardException

Get the column descriptors for all the columns referenced by this constraint.

Returns:ColumnDescriptorList

the column descriptor list

Exceptions
StandardException:
on error
getConglomerateIdback to summary
public abstract UUID getConglomerateId()
getConstraintNameback to summary
public String getConstraintName()

Gets the name of the constraint.

Returns:String

A String containing the name of the constraint.

getConstraintTextback to summary
public String getConstraintText()

Get the text of the constraint. (Only non-null/meaningful for check constraints.)

Returns:String

The constraint text.

getConstraintTypeback to summary
public abstract int getConstraintType()

Gets an identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).

Returns:int

An identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).

getDependableFinderback to summary
public DependableFinder getDependableFinder()

Implements org.apache.derby.catalog.Dependable.getDependableFinder.

Doc from org.apache.derby.catalog.Dependable.getDependableFinder.

Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.

Returns:DependableFinder

the stored form of this provider

See Also
Dependable#getDependableFinder
getDescriptorNameback to summary
public String getDescriptorName()

Overrides org.apache.derby.iapi.sql.dictionary.TupleDescriptor.getDescriptorName.

Annotations
@Override
See Also
TupleDescriptor#getDescriptorName
getDescriptorTypeback to summary
public String getDescriptorType()

Overrides org.apache.derby.iapi.sql.dictionary.TupleDescriptor.getDescriptorType.

Doc from org.apache.derby.iapi.sql.dictionary.TupleDescriptor.getDescriptorType.

Each descriptor must identify itself with its type; i.e index, check constraint whatever.

Annotations
@Override
getKeyColumnsback to summary
public int[] getKeyColumns()

Resolve

For now the ConstraintDescriptor code stores the array of key columns in the field 'otherColumns'. Jerry plans to re-organize things. For now to minimize his rototill I've implemented this function on the old structures. All new code should use getKeyColumns to get a constraint's key columns.

See Also
org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor#getKeyColumns
getObjectIDback to summary
public UUID getObjectID()

Implements org.apache.derby.catalog.Dependable.getObjectID.

Get the provider's UUID

Returns:UUID

The provider's UUID

getObjectNameback to summary
public String getObjectName()

Implements org.apache.derby.catalog.Dependable.getObjectName.

Return the name of this Provider. (Useful for errors.)

Returns:String

String The name of this provider.

getReferenceCountback to summary
public int getReferenceCount()

Get the number of enforced fks that reference this key. Overriden by ReferencedKeyConstraints.

Returns:int

the number of fks

getReferencedColumnsback to summary
public int[] getReferencedColumns()

Returns an array of column ids (i.e. ordinal positions) for the columns referenced in this table for a primary key, unique key, referential, or check constraint.

Returns:int[]

An array of column ids for those constraints that can be on columns (primary, unique key, referential constraints, and check constraints). For check and unique constraints, it returns an array of columns ids that are referenced in the constraint. For primary key and referential constraints, it returns an array of column ids for the columns in this table (i.e. the primary key columns for a primary key constraint, and the foreign key columns for a foreign key constraint.

getSchemaDescriptorback to summary
public SchemaDescriptor getSchemaDescriptor()

Get the SchemaDescriptor for the schema that this constraint belongs to.

Returns:SchemaDescriptor

SchemaDescriptor The SchemaDescriptor for this constraint.

getTableDescriptorback to summary
public TableDescriptor getTableDescriptor()

Get the table descriptor upon which this constraint is declared.

Returns:TableDescriptor

the table descriptor

getTableIdback to summary
public UUID getTableId()

Gets the UUID of the table the constraint is on.

Returns:UUID

The UUID of the table the constraint is on.

getUUIDback to summary
public UUID getUUID()

Implements abstract org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor.getUUID.

Gets the UUID of the constraint.

Returns:UUID

The UUID of the constraint.

hasBackingIndexback to summary
public abstract boolean hasBackingIndex()

Does this constraint have a backing index?

Returns:boolean

boolean Whether or not there is a backing index for this constraint.

initiallyDeferredback to summary
public boolean initiallyDeferred()

Returns TRUE if the constraint is initially deferred

Returns:boolean

TRUE if the constraint is initially DEFERRED, FALSE if the constraint is initially IMMEDIATE

isReferencedback to summary
public boolean isReferenced()

Is this constraint referenced? Return false. Overridden by ReferencedKeyConstraints.

Returns:boolean

false

isValidback to summary
public synchronized boolean isValid()

Implements org.apache.derby.iapi.sql.depend.Dependent.isValid.

Check that all of the dependent's dependencies are valid.

Returns:boolean

true if the dependent is currently valid

makeInvalidback to summary
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException

Implements org.apache.derby.iapi.sql.depend.Dependent.makeInvalid.

Mark the dependent as invalid (due to at least one of its dependencies being invalid). Always an error for a constraint -- should never have gotten here.

Parameters
action:int

The action causing the invalidation

lcc:LanguageConnectionContext

Doc from org.apache.derby.iapi.sql.depend.Dependent.makeInvalid.

The LanguageConnectionContext

Exceptions
StandardException:
thrown if called in sanity mode
needsToFireback to summary
public abstract boolean needsToFire(int stmtType, int[] modifiedCols)

Does this constraint need to fire on this type of DML?

Parameters
stmtType:int

the type of DML (StatementType.INSERT|StatementType.UPDATE|StatementType.DELETE)

modifiedCols:int[]

the columns modified, or null for all

Returns:boolean

true/false

prepareToInvalidateback to summary
public void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc) throws StandardException

Implements org.apache.derby.iapi.sql.depend.Dependent.prepareToInvalidate.

Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).

Parameters
p:Provider

the provider

action:int

The action causing the invalidation

lcc:LanguageConnectionContext

Doc from org.apache.derby.iapi.sql.depend.Dependent.prepareToInvalidate.

The LanguageConnectionContext

Exceptions
StandardException:
thrown if unable to make it invalid
setDeferrableback to summary
public void setDeferrable(boolean b)
setEnforcedback to summary
public void setEnforced(boolean b)
setInitiallyDeferredback to summary
public void setInitiallyDeferred(boolean b)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert the ColumnDescriptor to a String.

Returns:String

A String representation of this ColumnDescriptor

Annotations
@Override