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 SPSDescriptor
actionSPS
private UUID
actionSPSId
private java.sql.Timestamp
creationTimestamp
private int
eventMask
private UUID
id
private boolean
isBefore
private boolean
isEnabled
private boolean
isRow
private java.lang.String
name
private java.lang.String
newReferencingName
private java.lang.String
oldReferencingName
private int[]
referencedCols
private int[]
referencedColsInTriggerAction
private boolean
referencingNew
private boolean
referencingOld
private SchemaDescriptor
sd
static int
SYSTRIGGERS_STATE_FIELD
private TableDescriptor
td
static int
TRIGGER_EVENT_DELETE
static int
TRIGGER_EVENT_INSERT
static int
TRIGGER_EVENT_UPDATE
private java.lang.String
triggerDefinition
private UUID
triggerSchemaId
private UUID
triggerTableId
private java.lang.String
whenClauseText
private SPSDescriptor
whenSPS
private UUID
whenSPSId
-
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 void
drop(LanguageConnectionContext lcc)
UUID
getActionId()
Get the trigger action sps UUIDSPSDescriptor
getActionSPS(LanguageConnectionContext lcc)
Get the trigger action sps from SYSSTATEMENTS.java.lang.String
getClassType()
Get the provider's type.private static Context
getContext(java.lang.String contextID)
Privileged lookup of a Context.java.sql.Timestamp
getCreationTimestamp()
Get the time that this trigger was created.protected DataDictionary
getDataDictionary()
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.java.lang.String
getName()
Get the trigger namejava.lang.String
getNewReferencingName()
Get the new Referencing name, if any, from the REFERENCING clause.UUID
getObjectID()
Get the provider's UUIDjava.lang.String
getObjectName()
Return the name of this Provider.java.lang.String
getOldReferencingName()
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.boolean
getReferencingNew()
Get whether or not NEW was replaced in the REFERENCING clause.boolean
getReferencingOld()
Get whether or not OLD was replaced in the REFERENCING clause.SchemaDescriptor
getSchemaDescriptor()
Get the triggers schema descriptorprivate SPSDescriptor
getSPS(LanguageConnectionContext lcc, boolean isWhenClause)
Get the SPS for the triggered SQL statement or the WHEN clause.TableDescriptor
getTableDescriptor()
Get the trigger table descriptorUUID
getTableId()
java.lang.String
getTriggerDefinition()
Get the original trigger definition.int
getTriggerEventMask()
Get the trigger event mask.int
getTypeFormatId()
Get the formatID which corresponds to this class.UUID
getUUID()
Get the trigger UUIDUUID
getWhenClauseId()
Get the trigger when clause sps UUIDSPSDescriptor
getWhenClauseSPS(LanguageConnectionContext lcc)
Get the trigger when clause spsjava.lang.String
getWhenClauseText()
Get the SQL text of the WHEN clause.boolean
isBeforeTrigger()
Is this a before triggerboolean
isEnabled()
Is this trigger enforcedboolean
isRowTrigger()
Is this a row triggerboolean
isValid()
Check that all of the dependent's dependencies are valid.boolean
listensForEvent(int event)
Indicate whether this trigger listens for this type of event.void
makeInvalid(int action, LanguageConnectionContext lcc)
Mark the dependent as invalid (due to at least one of its dependencies being invalid).boolean
needsToFire(int stmtType, int[] modifiedCols)
Does this trigger 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
readExternal(java.io.ObjectInput in)
Read this object from a stream of stored objects.void
setDisabled()
Mark this trigger as disabledvoid
setEnabled()
Mark this trigger as enforcedvoid
setReferencedCols(int[] newCols)
Update the array of referenced columnsvoid
setReferencedColsInTriggerAction(int[] referencedColsInTriggerAction)
Set the referenced column array for trigger actionsjava.lang.String
toString()
void
writeExternal(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, ornull
if there is no WHEN clause
-
-
Method Detail
-
getUUID
public UUID getUUID()
Get the trigger UUID- Specified by:
getUUID
in classUniqueTupleDescriptor
- Returns:
- the id
-
getName
public java.lang.String getName()
Get the trigger name- Specified by:
getName
in classUniqueSQLObjectDescriptor
- Returns:
- the name
-
getTableId
public UUID getTableId()
-
getSchemaDescriptor
public SchemaDescriptor getSchemaDescriptor() throws StandardException
Get the triggers schema descriptor- Specified by:
getSchemaDescriptor
in 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
-true
if the SPS for the WHEN clause is requested,false
if 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
null
if 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 StandardException
Does 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:
toString
in classjava.lang.Object
-
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 language connection context- 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 trigger -- should never have gotten here.- Specified by:
makeInvalid
in 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.ClassNotFoundException
Read this object from a stream of stored objects.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Parameters:
in
- read this.- Throws:
java.io.IOException
- thrown on errorjava.lang.ClassNotFoundException
- thrown on error
-
getDataDictionary
protected DataDictionary getDataDictionary()
- Overrides:
getDataDictionary
in classTupleDescriptor
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
Write this object to a stream of stored objects.- Specified by:
writeExternal
in 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:
getTypeFormatId
in interfaceTypedFormat
- Returns:
- the formatID of this class
-
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
- See Also:
TupleDescriptor.getDescriptorType()
-
getDescriptorName
public java.lang.String getDescriptorName()
- Overrides:
getDescriptorName
in 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.
-
-