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 Description private SPSDescriptoractionSPSprivate UUIDactionSPSIdprivate java.sql.TimestampcreationTimestampprivate inteventMaskprivate UUIDidprivate booleanisBeforeprivate booleanisEnabledprivate booleanisRowprivate java.lang.Stringnameprivate java.lang.StringnewReferencingNameprivate java.lang.StringoldReferencingNameprivate int[]referencedColsprivate int[]referencedColsInTriggerActionprivate booleanreferencingNewprivate booleanreferencingOldprivate SchemaDescriptorsdstatic intSYSTRIGGERS_STATE_FIELDprivate TableDescriptortdstatic intTRIGGER_EVENT_DELETEstatic intTRIGGER_EVENT_INSERTstatic intTRIGGER_EVENT_UPDATEprivate java.lang.StringtriggerDefinitionprivate UUIDtriggerSchemaIdprivate UUIDtriggerTableIdprivate java.lang.StringwhenClauseTextprivate SPSDescriptorwhenSPSprivate UUIDwhenSPSId-
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 TriggerDescriptor()Niladic constructor, for formatableTriggerDescriptor(DataDictionary dataDictionary, SchemaDescriptor sd, UUID id, java.lang.String name, int eventMask, boolean isBefore, boolean isRow, boolean isEnabled, TableDescriptor td, UUID whenSPSId, UUID actionSPSId, java.sql.Timestamp creationTimestamp, int[] referencedCols, int[] referencedColsInTriggerAction, java.lang.String triggerDefinition, boolean referencingOld, boolean referencingNew, java.lang.String oldReferencingName, java.lang.String newReferencingName, java.lang.String whenClauseText)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.private static ContextgetContext(java.lang.String contextID)Privileged lookup of a Context.java.sql.TimestampgetCreationTimestamp()Get the time that this trigger was created.protected DataDictionarygetDataDictionary()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 descriptorprivate SPSDescriptorgetSPS(LanguageConnectionContext lcc, boolean isWhenClause)Get the SPS for the triggered SQL statement or the WHEN clause.TableDescriptorgetTableDescriptor()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
getColumnDependableFinder, 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
-
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
-
id
private UUID id
-
name
private java.lang.String name
-
oldReferencingName
private java.lang.String oldReferencingName
-
newReferencingName
private java.lang.String newReferencingName
-
triggerDefinition
private java.lang.String triggerDefinition
-
sd
private SchemaDescriptor sd
-
eventMask
private int eventMask
-
isBefore
private boolean isBefore
-
isRow
private boolean isRow
-
referencingOld
private boolean referencingOld
-
referencingNew
private boolean referencingNew
-
td
private TableDescriptor td
-
actionSPSId
private UUID actionSPSId
-
actionSPS
private SPSDescriptor actionSPS
-
whenSPSId
private UUID whenSPSId
-
whenSPS
private SPSDescriptor whenSPS
-
isEnabled
private boolean isEnabled
-
referencedCols
private int[] referencedCols
-
referencedColsInTriggerAction
private int[] referencedColsInTriggerAction
-
creationTimestamp
private java.sql.Timestamp creationTimestamp
-
triggerSchemaId
private UUID triggerSchemaId
-
triggerTableId
private UUID triggerTableId
-
whenClauseText
private java.lang.String whenClauseText
-
-
Constructor Detail
-
TriggerDescriptor
public TriggerDescriptor()
Niladic constructor, for formatable
-
TriggerDescriptor
TriggerDescriptor(DataDictionary dataDictionary, SchemaDescriptor sd, UUID id, java.lang.String name, int eventMask, boolean isBefore, boolean isRow, boolean isEnabled, TableDescriptor td, UUID whenSPSId, UUID actionSPSId, java.sql.Timestamp creationTimestamp, int[] referencedCols, int[] referencedColsInTriggerAction, java.lang.String triggerDefinition, boolean referencingOld, boolean referencingNew, java.lang.String oldReferencingName, java.lang.String newReferencingName, java.lang.String whenClauseText)
Constructor. Used when creating a trigger from SYS.SYSTRIGGERS- Parameters:
dataDictionary- the data dictionarysd- the schema descriptor for this triggerid- the trigger idname- the trigger nameeventMask- TriggerDescriptor.TRIGGER_EVENT_XXXXisBefore- is this a before (as opposed to after) triggerisRow- is this a row trigger or statement triggerisEnabled- is this trigger enabled or disabledtd- the table upon which this trigger is definedwhenSPSId- the sps id for the when clause (may be null)actionSPSId- the spsid for the trigger action (may be null)creationTimestamp- when was this trigger created?referencedCols- what columns does this trigger reference (may be null)referencedColsInTriggerAction- what columns does the trigger action reference through old/new transition variables (may be null)triggerDefinition- The original user text of the trigger actionreferencingOld- whether or not OLD appears in REFERENCING clausereferencingNew- whether or not NEW appears in REFERENCING clauseoldReferencingName- old referencing table name, if any, that appears in REFERCING clausenewReferencingName- new referencing table name, if any, that appears in REFERCING clausewhenClauseText- the SQL text of the WHEN clause, ornullif there is no WHEN clause
-
-
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
-
getSPS
private SPSDescriptor getSPS(LanguageConnectionContext lcc, boolean isWhenClause) throws StandardException
Get the SPS for the triggered SQL statement or the WHEN clause.- Parameters:
lcc- the LanguageConnectionContext to useisWhenClause-trueif the SPS for the WHEN clause is requested,falseif it is the triggered SQL statement- Returns:
- the requested SPS
- Throws:
StandardException- if an error occurs
-
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
-
getDataDictionary
protected DataDictionary getDataDictionary()
- Overrides:
getDataDictionaryin classTupleDescriptor
-
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()
-
getContext
private static Context getContext(java.lang.String contextID)
Privileged lookup of a Context. Must be private so that user code can't call this entry point.
-
-