org.apache.derby.iapi.sql.dictionary
Class TriggerDescriptor
- java.lang.Object
-
- org.apache.derby.iapi.sql.dictionary.TupleDescriptor
-
- org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor
-
- org.apache.derby.iapi.sql.dictionary.UniqueSQLObjectDescriptor
-
- org.apache.derby.iapi.sql.dictionary.TriggerDescriptor
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable, Dependable, Formatable, TypedFormat, Dependent, Provider
public class TriggerDescriptor extends UniqueSQLObjectDescriptor implements Provider, Dependent, Formatable
A trigger.We are dependent on TableDescriptors, SPSDescriptors (for our WHEN clause and our action). Note that we don't strictly need to be dependent on out SPSes because we could just disallow anyone from dropping an sps of type 'T', but to keep dependencies uniform, we'll do be dependent.
We are a provider for DML (PreparedStatements or SPSes) The public methods for this class are:
- getUUID
- getName
- getSchemaDescriptor
- public boolean listensForEvent(int event);
- public int getTriggerEventMask();
- public Timestamp getCreationTimestamp();
- public boolean isBeforeTrigger();
- public boolean isRowTrigger();
- public UUID getActionId();
- public SPSDescriptor getActionSPS();
- public UUID getWhenClauseId();
- public SPSDescriptor getWhenClauseSPS()
- public String getWhenClauseText();
- public TableDescriptor getTableDescriptor()
- public ReferencedColumns getReferencedColumnsDescriptor()
- public int[] getReferencedCols();
- public int[] getReferencedColsInTriggerAction();
- public boolean enforced();
- public void setEnabled();
- public void setDisabled();
- public boolean needsToFire(int stmtType, int[] modifiedCols)
- public String getTriggerDefinition();
- public boolean getReferencingOld();
- public boolean getReferencingNew();
- public String getOldReferencingName();
- public String getNewReferencingName();
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intSYSTRIGGERS_STATE_FIELDstatic intTRIGGER_EVENT_DELETEstatic intTRIGGER_EVENT_INSERTstatic intTRIGGER_EVENT_UPDATE-
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 and Description TriggerDescriptor()Niladic constructor, for formatable
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voiddrop(LanguageConnectionContext lcc)UUIDgetActionId()Get the trigger action sps UUIDSPSDescriptorgetActionSPS(LanguageConnectionContext lcc)Get the trigger action sps from SYSSTATEMENTS.java.lang.StringgetClassType()Get the provider's type.java.sql.TimestampgetCreationTimestamp()Get the time that this trigger was created.DependableFindergetDependableFinder()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.StringgetDescriptorName()java.lang.StringgetDescriptorType()Each descriptor must identify itself with its type; i.e index, check constraint whatever.java.lang.StringgetName()Get the trigger namejava.lang.StringgetNewReferencingName()Get the new Referencing name, if any, from the REFERENCING clause.UUIDgetObjectID()Get the provider's UUIDjava.lang.StringgetObjectName()Return the name of this Provider.java.lang.StringgetOldReferencingName()Get the old Referencing name, if any, from the REFERENCING clause.int[]getReferencedCols()Get the referenced column array for this trigger, used in "alter table drop column", we get the handle and change itint[]getReferencedColsInTriggerAction()Get the referenced column array for the trigger action columns.booleangetReferencingNew()Get whether or not NEW was replaced in the REFERENCING clause.booleangetReferencingOld()Get whether or not OLD was replaced in the REFERENCING clause.SchemaDescriptorgetSchemaDescriptor()Get the triggers schema descriptorTableDescriptorgetTableDescriptor()Get the trigger table descriptorUUIDgetTableId()java.lang.StringgetTriggerDefinition()Get the original trigger definition.intgetTriggerEventMask()Get the trigger event mask.intgetTypeFormatId()Get the formatID which corresponds to this class.UUIDgetUUID()Get the trigger UUIDUUIDgetWhenClauseId()Get the trigger when clause sps UUIDSPSDescriptorgetWhenClauseSPS(LanguageConnectionContext lcc)Get the trigger when clause spsjava.lang.StringgetWhenClauseText()Get the SQL text of the WHEN clause.booleanisBeforeTrigger()Is this a before triggerbooleanisEnabled()Is this trigger enforcedbooleanisRowTrigger()Is this a row triggerbooleanisValid()Check that all of the dependent's dependencies are valid.booleanlistensForEvent(int event)Indicate whether this trigger listens for this type of event.voidmakeInvalid(int action, LanguageConnectionContext lcc)Mark the dependent as invalid (due to at least one of its dependencies being invalid).booleanneedsToFire(int stmtType, int[] modifiedCols)Does this trigger need to fire on this type of DML?voidprepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc)Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).voidreadExternal(java.io.ObjectInput in)Read this object from a stream of stored objects.voidsetDisabled()Mark this trigger as disabledvoidsetEnabled()Mark this trigger as enforcedvoidsetReferencedCols(int[] newCols)Update the array of referenced columnsvoidsetReferencedColsInTriggerAction(int[] referencedColsInTriggerAction)Set the referenced column array for trigger actionsjava.lang.StringtoString()voidwriteExternal(java.io.ObjectOutput out)Write this object to a stream of stored objects.-
Methods inherited from class org.apache.derby.iapi.sql.dictionary.TupleDescriptor
isPersistent
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.derby.catalog.Dependable
isPersistent
-
-
-
-
Field Detail
-
SYSTRIGGERS_STATE_FIELD
public static final int SYSTRIGGERS_STATE_FIELD
- See Also:
- Constant Field Values
-
TRIGGER_EVENT_UPDATE
public static final int TRIGGER_EVENT_UPDATE
- See Also:
- Constant Field Values
-
TRIGGER_EVENT_DELETE
public static final int TRIGGER_EVENT_DELETE
- See Also:
- Constant Field Values
-
TRIGGER_EVENT_INSERT
public static final int TRIGGER_EVENT_INSERT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getUUID
public UUID getUUID()
Get the trigger UUID- Specified by:
getUUIDin classUniqueTupleDescriptor- Returns:
- the id
-
getName
public java.lang.String getName()
Get the trigger name- Specified by:
getNamein classUniqueSQLObjectDescriptor- Returns:
- the name
-
getTableId
public UUID getTableId()
-
getSchemaDescriptor
public SchemaDescriptor getSchemaDescriptor() throws StandardException
Get the triggers schema descriptor- Specified by:
getSchemaDescriptorin classUniqueSQLObjectDescriptor- Returns:
- the schema descriptor
- Throws:
StandardException- on error
-
listensForEvent
public boolean listensForEvent(int event)
Indicate whether this trigger listens for this type of event.- Parameters:
event- TRIGGER_EVENT_XXXX- Returns:
- true if it listens to the specified event.
-
getTriggerEventMask
public int getTriggerEventMask()
Get the trigger event mask. Currently, a trigger may only listen for a single event, though it may OR multiple events in the future.- Returns:
- the trigger event mask
-
getCreationTimestamp
public java.sql.Timestamp getCreationTimestamp()
Get the time that this trigger was created.- Returns:
- the time the trigger was created
-
isBeforeTrigger
public boolean isBeforeTrigger()
Is this a before trigger- Returns:
- true if it is a before trigger
-
isRowTrigger
public boolean isRowTrigger()
Is this a row trigger- Returns:
- true if it is a before trigger
-
getActionId
public UUID getActionId()
Get the trigger action sps UUID- Returns:
- the uuid of the sps action
-
getActionSPS
public SPSDescriptor getActionSPS(LanguageConnectionContext lcc) throws StandardException
Get the trigger action sps from SYSSTATEMENTS. If we find that the sps is invalid and the trigger is defined at row level and it has OLD/NEW transient variables through REFERENCES clause, then the sps from SYSSTATEMENTS may not be valid anymore. In such a case, we regenerate the trigger action sql and use that for the sps and update SYSSTATEMENTS using this new sps. This update of SYSSTATEMENTS was introduced with DERBY-4874- Parameters:
lcc- The LanguageConnectionContext to use.- Returns:
- the trigger action sps
- Throws:
StandardException- on error
-
getWhenClauseId
public UUID getWhenClauseId()
Get the trigger when clause sps UUID- Returns:
- the uuid of the sps action
-
getWhenClauseText
public java.lang.String getWhenClauseText()
Get the SQL text of the WHEN clause.- Returns:
- SQL text for the WHEN clause, or
nullif there is no WHEN clause
-
getWhenClauseSPS
public SPSDescriptor getWhenClauseSPS(LanguageConnectionContext lcc) throws StandardException
Get the trigger when clause sps- Parameters:
lcc- the LanguageConnectionContext to use- Returns:
- the sps of the when clause
- Throws:
StandardException- on error
-
getTableDescriptor
public TableDescriptor getTableDescriptor() throws StandardException
Get the trigger table descriptor- Returns:
- the table descripor upon which this trigger is declared
- Throws:
StandardException- on error
-
getReferencedCols
public int[] getReferencedCols()
Get the referenced column array for this trigger, used in "alter table drop column", we get the handle and change it- Returns:
- the referenced column array
-
setReferencedCols
public void setReferencedCols(int[] newCols)
Update the array of referenced columns
-
getReferencedColsInTriggerAction
public int[] getReferencedColsInTriggerAction()
Get the referenced column array for the trigger action columns.- Returns:
- the referenced column array
-
setReferencedColsInTriggerAction
public void setReferencedColsInTriggerAction(int[] referencedColsInTriggerAction)
Set the referenced column array for trigger actions
-
isEnabled
public boolean isEnabled()
Is this trigger enforced- Returns:
- true if it is enforced
-
setEnabled
public void setEnabled()
Mark this trigger as enforced
-
setDisabled
public void setDisabled()
Mark this trigger as disabled
-
needsToFire
public boolean needsToFire(int stmtType, int[] modifiedCols) throws StandardExceptionDoes this trigger 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
- Throws:
StandardException- on error
-
getTriggerDefinition
public java.lang.String getTriggerDefinition()
Get the original trigger definition.- Returns:
- The trigger definition.
-
getReferencingOld
public boolean getReferencingOld()
Get whether or not OLD was replaced in the REFERENCING clause.- Returns:
- Whether or not OLD was replaced in the REFERENCING clause.
-
getReferencingNew
public boolean getReferencingNew()
Get whether or not NEW was replaced in the REFERENCING clause.- Returns:
- Whether or not NEW was replaced in the REFERENCING clause.
-
getOldReferencingName
public java.lang.String getOldReferencingName()
Get the old Referencing name, if any, from the REFERENCING clause.- Returns:
- The old Referencing name, if any, from the REFERENCING clause.
-
getNewReferencingName
public java.lang.String getNewReferencingName()
Get the new Referencing name, if any, from the REFERENCING clause.- Returns:
- The new Referencing name, if any, from the REFERENCING clause.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDependableFinder
public DependableFinder getDependableFinder()
Description copied from interface:DependableGet an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.- Specified by:
getDependableFinderin 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:
getObjectNamein interfaceDependable- Returns:
- String The name of this provider.
-
getObjectID
public UUID getObjectID()
Get the provider's UUID- Specified by:
getObjectIDin interfaceDependable- Returns:
- The provider's UUID
-
getClassType
public java.lang.String getClassType()
Get the provider's type.- Specified by:
getClassTypein 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:
prepareToInvalidatein interfaceDependent- Parameters:
action- The action causing the invalidationp- the providerlcc- the language connection context- Throws:
StandardException- thrown if unable to make it invalid
-
makeInvalid
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardExceptionMark the dependent as invalid (due to at least one of its dependencies being invalid). Always an error for a trigger -- should never have gotten here.- Specified by:
makeInvalidin interfaceDependent- Parameters:
lcc- the language connection contextaction- The action causing the invalidation- Throws:
StandardException- thrown if called in sanity mode
-
drop
public void drop(LanguageConnectionContext lcc) throws StandardException
- Throws:
StandardException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this object from a stream of stored objects.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- read this.- Throws:
java.io.IOException- thrown on errorjava.lang.ClassNotFoundException- thrown on error
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this object to a stream of stored objects.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- write bytes here.- Throws:
java.io.IOException- thrown on error
-
getTypeFormatId
public int getTypeFormatId()
Get the formatID which corresponds to this class.- Specified by:
getTypeFormatIdin interfaceTypedFormat- Returns:
- the formatID of this class
-
getDescriptorType
public java.lang.String getDescriptorType()
Description copied from class:TupleDescriptorEach descriptor must identify itself with its type; i.e index, check constraint whatever.- Overrides:
getDescriptorTypein classTupleDescriptor- See Also:
TupleDescriptor.getDescriptorType()
-
getDescriptorName
public java.lang.String getDescriptorName()
- Overrides:
getDescriptorNamein classTupleDescriptor- See Also:
TupleDescriptor.getDescriptorName()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG