Class ConstraintDescriptor
- java.lang.Object
-
- org.apache.derby.iapi.sql.dictionary.TupleDescriptor
-
- org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor
-
- org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor
-
- All Implemented Interfaces:
Dependable
,Dependent
,Provider
- Direct Known Subclasses:
CheckConstraintDescriptor
,KeyConstraintDescriptor
public abstract class ConstraintDescriptor extends UniqueTupleDescriptor implements Provider, Dependent
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
Fields Modifier and Type Field Description static int
ALL
private ColumnDescriptorList
colDL
(package private) UUID
constraintId
(package private) java.lang.String
constraintName
private boolean
deferrable
static int
DISABLED
static int
ENABLED
private boolean
enforced
private boolean
initiallyDeferred
private int[]
referencedColumns
private SchemaDescriptor
schemaDesc
static int
SYSCONSTRAINTS_STATE_FIELD
(package private) TableDescriptor
table
-
Fields inherited from interface org.apache.derby.catalog.Dependable
ACTIVATION, ALIAS, COLUMNS_IN_TABLE, COLUMNS_PERMISSION, CONGLOMERATE, CONSTRAINT, DEFAULT, FILE, HEAP, INDEX, PERM, PREPARED_STATEMENT, ROLE_GRANT, ROUTINE_PERMISSION, SCHEMA, SEQUENCE, STORED_PREPARED_STATEMENT, TABLE, TABLE_PERMISSION, TRIGGER, VIEW
-
-
Constructor Summary
Constructors Constructor Description ConstraintDescriptor(DataDictionary dataDictionary, TableDescriptor table, java.lang.String constraintName, boolean deferrable, boolean initiallyDeferred, int[] referencedColumns, UUID constraintId, SchemaDescriptor schemaDesc, boolean enforced)
Constructor for a ConstraintDescriptor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
areColumnsComparable(ColumnDescriptorList otherColumns)
Indicates whether the column descriptor list is type comparable with the constraints columns.boolean
columnIntersects(int[] columnArray)
Does a column intersect with our referenced columnsboolean
deferrable()
Returns TRUE if the constraint is deferrable(package private) static boolean
doColumnsIntersect(int[] otherColumns, int[] referencedColumns)
Does a column in the input set intersect with our referenced columns?ConglomerateDescriptor
drop(LanguageConnectionContext lcc, boolean clearDependencies)
Drop the constraint.boolean
enforced()
Is this constraint enforced?java.lang.String
getClassType()
Get the provider's type.ColumnDescriptorList
getColumnDescriptors()
Get the column descriptors for all the columns referenced by this constraint.abstract UUID
getConglomerateId()
java.lang.String
getConstraintName()
Gets the name of the constraint.java.lang.String
getConstraintText()
Get the text of the constraint.abstract int
getConstraintType()
Gets an identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).DependableFinder
getDependableFinder()
Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.java.lang.String
getDescriptorName()
java.lang.String
getDescriptorType()
Each descriptor must identify itself with its type; i.e index, check constraint whatever.int[]
getKeyColumns()
RESOLVE: For now the ConstraintDescriptor code stores the array of key columns in the field 'otherColumns'.UUID
getObjectID()
Get the provider's UUIDjava.lang.String
getObjectName()
Return the name of this Provider.int
getReferenceCount()
Get the number of enforced fks that reference this key.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.SchemaDescriptor
getSchemaDescriptor()
Get the SchemaDescriptor for the schema that this constraint belongs to.TableDescriptor
getTableDescriptor()
Get the table descriptor upon which this constraint is declared.UUID
getTableId()
Gets the UUID of the table the constraint is on.UUID
getUUID()
Gets the UUID of the constraint.abstract boolean
hasBackingIndex()
Does this constraint have a backing index?boolean
initiallyDeferred()
Returns TRUE if the constraint is initially deferredboolean
isReferenced()
Is this constraint referenced?boolean
isValid()
Check that all of the dependent's dependencies are valid.void
makeInvalid(int action, LanguageConnectionContext lcc)
Mark the dependent as invalid (due to at least one of its dependencies being invalid).abstract boolean
needsToFire(int stmtType, int[] modifiedCols)
Does this constraint need to fire on this type of DML?void
prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc)
Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).void
setDeferrable(boolean b)
void
setEnforced(boolean b)
void
setInitiallyDeferred(boolean b)
java.lang.String
toString()
Convert the ColumnDescriptor to a String.-
Methods inherited from class org.apache.derby.iapi.sql.dictionary.TupleDescriptor
getColumnDependableFinder, getDataDictionary, getDependableFinder, isPersistent, setDataDictionary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.derby.catalog.Dependable
isPersistent
-
-
-
-
Field Detail
-
ENABLED
public static final int ENABLED
- See Also:
- Constant Field Values
-
DISABLED
public static final int DISABLED
- See Also:
- Constant Field Values
-
ALL
public static final int ALL
- See Also:
- Constant Field Values
-
SYSCONSTRAINTS_STATE_FIELD
public static final int SYSCONSTRAINTS_STATE_FIELD
- See Also:
- Constant Field Values
-
table
TableDescriptor table
-
constraintName
final java.lang.String constraintName
-
deferrable
private boolean deferrable
-
initiallyDeferred
private boolean initiallyDeferred
-
enforced
private boolean enforced
-
referencedColumns
private final int[] referencedColumns
-
constraintId
final UUID constraintId
-
schemaDesc
private final SchemaDescriptor schemaDesc
-
colDL
private ColumnDescriptorList colDL
-
-
Constructor Detail
-
ConstraintDescriptor
ConstraintDescriptor(DataDictionary dataDictionary, TableDescriptor table, java.lang.String constraintName, boolean deferrable, boolean initiallyDeferred, int[] referencedColumns, UUID constraintId, SchemaDescriptor schemaDesc, boolean enforced)
Constructor for a ConstraintDescriptor- Parameters:
dataDictionary
- The data dictionary that this descriptor lives intable
- The descriptor of the table the constraint is onconstraintName
- The name of the constraint.deferrable
- If the constraint can be deferred.initiallyDeferred
- If the constraint starts life deferred.referencedColumns
- columns that the constraint referencesconstraintId
- UUID of constraintschemaDesc
- SchemaDescriptorenforced
- Is the constraint enforced?
-
-
Method Detail
-
getTableId
public UUID getTableId()
Gets the UUID of the table the constraint is on.- Returns:
- The UUID of the table the constraint is on.
-
getUUID
public UUID getUUID()
Gets the UUID of the constraint.- Specified by:
getUUID
in classUniqueTupleDescriptor
- Returns:
- The UUID of the constraint.
-
getConstraintName
public java.lang.String getConstraintName()
Gets the name of the constraint.- Returns:
- A String containing the name of the constraint.
-
getConstraintType
public abstract int getConstraintType()
Gets an identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).- Returns:
- An identifier telling what type of descriptor it is (UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK).
-
getConglomerateId
public abstract UUID getConglomerateId()
-
getConstraintText
public java.lang.String getConstraintText()
Get the text of the constraint. (Only non-null/meaningful for check constraints.)- Returns:
- The constraint text.
-
deferrable
public boolean deferrable()
Returns TRUE if the constraint is deferrable- Returns:
- TRUE if the constraint is DEFERRABLE, FALSE if it is NOT DEFERRABLE.
-
setDeferrable
public void setDeferrable(boolean b)
-
initiallyDeferred
public boolean initiallyDeferred()
Returns TRUE if the constraint is initially deferred- Returns:
- TRUE if the constraint is initially DEFERRED, FALSE if the constraint is initially IMMEDIATE
-
setInitiallyDeferred
public void setInitiallyDeferred(boolean b)
-
getReferencedColumns
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:
- 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.
-
hasBackingIndex
public abstract boolean hasBackingIndex()
Does this constraint have a backing index?- Returns:
- boolean Whether or not there is a backing index for this constraint.
-
getSchemaDescriptor
public SchemaDescriptor getSchemaDescriptor()
Get the SchemaDescriptor for the schema that this constraint belongs to.- Returns:
- SchemaDescriptor The SchemaDescriptor for this constraint.
-
getKeyColumns
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:
getKeyColumns()
-
enforced
public boolean enforced()
Is this constraint enforced?- Returns:
- true/false
-
setEnforced
public void setEnforced(boolean b)
-
isReferenced
public boolean isReferenced()
Is this constraint referenced? Return false. Overridden by ReferencedKeyConstraints.- Returns:
- false
-
getReferenceCount
public int getReferenceCount()
Get the number of enforced fks that reference this key. Overriden by ReferencedKeyConstraints.- Returns:
- the number of fks
-
needsToFire
public abstract boolean needsToFire(int stmtType, int[] modifiedCols)
Does this constraint need to fire on this type of DML?- Parameters:
stmtType
- the type of DML (StatementType.INSERT|StatementType.UPDATE|StatementType.DELETE)modifiedCols
- the columns modified, or null for all- Returns:
- true/false
-
getTableDescriptor
public TableDescriptor getTableDescriptor()
Get the table descriptor upon which this constraint is declared.- Returns:
- the table descriptor
-
getColumnDescriptors
public ColumnDescriptorList getColumnDescriptors() throws StandardException
Get the column descriptors for all the columns referenced by this constraint.- Returns:
- the column descriptor list
- Throws:
StandardException
- on error
-
areColumnsComparable
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
- the columns to compare- Returns:
- true/false
- Throws:
StandardException
- on error
-
columnIntersects
public boolean columnIntersects(int[] columnArray)
Does a column intersect with our referenced columns- Parameters:
columnArray
- columns to check Note-- this is not a static method.
-
doColumnsIntersect
static boolean doColumnsIntersect(int[] otherColumns, int[] referencedColumns)
Does a column in the input set intersect with our referenced columns?- Parameters:
otherColumns
- the columns to compare. If null, asssumed to mean all columnsreferencedColumns
- the columns referenced by the caller- Returns:
- true/false
-
toString
public java.lang.String toString()
Convert the ColumnDescriptor to a String.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A String representation of this ColumnDescriptor
-
getDependableFinder
public DependableFinder getDependableFinder()
Description copied from interface:Dependable
Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.- Specified by:
getDependableFinder
in interfaceDependable
- Returns:
- the stored form of this provider
- See Also:
Dependable.getDependableFinder()
-
getObjectName
public java.lang.String getObjectName()
Return the name of this Provider. (Useful for errors.)- Specified by:
getObjectName
in interfaceDependable
- Returns:
- String The name of this provider.
-
getObjectID
public UUID getObjectID()
Get the provider's UUID- Specified by:
getObjectID
in interfaceDependable
- Returns:
- The provider's UUID
-
getClassType
public java.lang.String getClassType()
Get the provider's type.- Specified by:
getClassType
in interfaceDependable
- Returns:
- char The provider's type.
-
isValid
public boolean isValid()
Check that all of the dependent's dependencies are valid.
-
prepareToInvalidate
public void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc) throws StandardException
Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).- Specified by:
prepareToInvalidate
in interfaceDependent
- Parameters:
action
- The action causing the invalidationp
- the providerlcc
- The LanguageConnectionContext- Throws:
StandardException
- thrown if unable to make it invalid
-
makeInvalid
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException
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.- Specified by:
makeInvalid
in interfaceDependent
- Parameters:
action
- The action causing the invalidationlcc
- The LanguageConnectionContext- Throws:
StandardException
- thrown if called in sanity mode
-
drop
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:
- 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.
- Throws:
StandardException
-
getDescriptorName
public java.lang.String getDescriptorName()
- Overrides:
getDescriptorName
in classTupleDescriptor
- See Also:
TupleDescriptor.getDescriptorName()
-
getDescriptorType
public java.lang.String getDescriptorType()
Description copied from class:TupleDescriptor
Each descriptor must identify itself with its type; i.e index, check constraint whatever.- Overrides:
getDescriptorType
in classTupleDescriptor
-
-