org.apache.derby.iapi.sql.dictionary
Class TriggerDescriptor

java.lang.Object
  extended byorg.apache.derby.iapi.sql.dictionary.TupleDescriptor
      extended byorg.apache.derby.iapi.sql.dictionary.TriggerDescriptor
All Implemented Interfaces:
Dependable, Dependent, java.io.Externalizable, Formatable, Provider, java.io.Serializable, TypedFormat, UniqueSQLObjectDescriptor, UniqueTupleDescriptor

public class TriggerDescriptor
extends TupleDescriptor
implements UniqueSQLObjectDescriptor, 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:

  1. getUUID
  2. getName
  3. getSchemaDescriptor
  4. public boolean listensForEvent(int event);
  5. public int getTriggerEventMask();
  6. public Timestamp getCreationTimestamp();
  7. public boolean isBeforeTrigger();
  8. public boolean isRowTrigger();
  9. public UUID getActionId();
  10. public SPSDescriptor getActionSPS();
  11. public UUID getWhenClauseId();
  12. public SPSDescriptor getWhenClauseSPS()
  13. public TableDescriptor getTableDescriptor()
  14. public ReferencedColumns getReferencedColumnsDescriptor()
  15. public int[] getReferencedCols();
  16. public boolean isEnabled();
  17. public void setEnabled();
  18. public void setDisabled();
  19. public boolean needsToFire(int stmtType, int[] modifiedCols)
  20. public String getTriggerDefinition();
  21. public boolean getReferencingOld();
  22. public boolean getReferencingNew();
  23. public String getOldReferencingName();
  24. public String getNewReferencingName();

Author:
Jamie
See Also:
Serialized Form

Field Summary
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  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  SPSDescriptor whenSPS
           
private  UUID whenSPSId
           
 
Fields inherited from class org.apache.derby.iapi.sql.dictionary.TupleDescriptor
COLUMN_LIST, CONGLOMERATE_LIST, CONSTRAINT_LIST, TRIGGER_LIST
 
Fields inherited from interface org.apache.derby.catalog.Dependable
ALIAS, COLUMNS_IN_TABLE, CONGLOMERATE, CONSTRAINT, DEFAULT, FILE, HEAP, INDEX, PREPARED_STATEMENT, SCHEMA, STORED_PREPARED_STATEMENT, TABLE, TRIGGER, VIEW
 
Constructor Summary
TriggerDescriptor()
          Niladic constructor, for formatable
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, java.lang.String triggerDefinition, boolean referencingOld, boolean referencingNew, java.lang.String oldReferencingName, java.lang.String newReferencingName)
          Constructor.
 
Method Summary
 UUID getActionId()
          Get the trigger action sps UUID
 SPSDescriptor getActionSPS(LanguageConnectionContext lcc)
          Get the trigger action sps
 java.lang.String getClassType()
          Get the provider's type.
 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 name
 java.lang.String getNewReferencingName()
          Get the new Referencing name, if any, from the REFERENCING clause.
 UUID getObjectID()
          Get the provider's UUID
 java.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 it
 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 descriptor
 TableDescriptor getTableDescriptor()
          Get the trigger table descriptor
 UUID 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 UUID
 UUID getWhenClauseId()
          Get the trigger when clause sps UUID
 SPSDescriptor getWhenClauseSPS()
          Get the trigger when clause sps
 boolean isBeforeTrigger()
          Is this a before trigger
 boolean isEnabled()
          Is this trigger enabled
 boolean isRowTrigger()
          Is this a row trigger
 boolean 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).
 void makeValid(LanguageConnectionContext lcc)
          Attempt to revalidate the dependent.
 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 disabled
 void setEnabled()
          Mark this trigger as enabled
 java.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

creationTimestamp

private java.sql.Timestamp creationTimestamp

triggerSchemaId

private UUID triggerSchemaId

triggerTableId

private UUID triggerTableId
Constructor Detail

TriggerDescriptor

public TriggerDescriptor()
Niladic constructor, for formatable


TriggerDescriptor

public 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,
                         java.lang.String triggerDefinition,
                         boolean referencingOld,
                         boolean referencingNew,
                         java.lang.String oldReferencingName,
                         java.lang.String newReferencingName)
Constructor. Used when creating a trigger from SYS.SYSTRIGGERS

Parameters:
dataDictionary - the data dictionary
sd - the schema descriptor for this trigger
id - the trigger id
name - the trigger name
eventMask - TriggerDescriptor.TRIGGER_EVENT_XXXX
isBefore - is this a before (as opposed to after) trigger
isRow - is this a row trigger or statement trigger
isEnabled - is this trigger enabled or disabled
td - the table upon which this trigger is defined
whenSPSId - 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)
triggerDefinition - The original user text of the trigger action
referencingOld - whether or not OLD appears in REFERENCING clause
referencingNew - whether or not NEW appears in REFERENCING clause
oldReferencingName - old referencing table name, if any, that appears in REFERCING clause
newReferencingName - new referencing table name, if any, that appears in REFERCING clause
Method Detail

getUUID

public UUID getUUID()
Get the trigger UUID

Specified by:
getUUID in interface UniqueTupleDescriptor
Returns:
the id

getName

public java.lang.String getName()
Get the trigger name

Specified by:
getName in interface UniqueSQLObjectDescriptor
Returns:
the name

getTableId

public UUID getTableId()

getSchemaDescriptor

public SchemaDescriptor getSchemaDescriptor()
                                     throws StandardException
Get the triggers schema descriptor

Specified by:
getSchemaDescriptor in interface UniqueSQLObjectDescriptor
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

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

getWhenClauseSPS

public SPSDescriptor getWhenClauseSPS()
                               throws StandardException
Get the trigger when clause sps

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

isEnabled

public boolean isEnabled()
Is this trigger enabled

Returns:
true if it is enabled

setEnabled

public void setEnabled()
Mark this trigger as enabled


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:
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()

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 interface Dependable
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 interface Dependable
Returns:
String The name of this provider.

getObjectID

public UUID getObjectID()
Get the provider's UUID

Specified by:
getObjectID in interface Dependable
Returns:
The provider's UUID

getClassType

public java.lang.String getClassType()
Get the provider's type.

Specified by:
getClassType in interface Dependable
Returns:
char The provider's type.

isValid

public boolean isValid()
Check that all of the dependent's dependencies are valid.

Specified by:
isValid in interface Dependent
Returns:
true if the dependent is currently 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 interface Dependent
Parameters:
action - The action causing the invalidation
p - the provider
lcc - 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 interface Dependent
Parameters:
lcc - the language connection context
action - The action causing the invalidation
Throws:
StandardException - thrown if called in sanity mode

makeValid

public void makeValid(LanguageConnectionContext lcc)
Attempt to revalidate the dependent. Meaningless for a trigger.

Specified by:
makeValid in interface Dependent
Parameters:
lcc - the language connection context

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 interface java.io.Externalizable
Parameters:
in - read this.
Throws:
java.io.IOException - thrown on error
java.lang.ClassNotFoundException - thrown on error

getDataDictionary

protected DataDictionary getDataDictionary()
                                    throws StandardException
Overrides:
getDataDictionary in class TupleDescriptor
Throws:
StandardException

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 interface java.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 interface TypedFormat
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 class TupleDescriptor
See Also:
TupleDescriptor.getDescriptorType()

getDescriptorName

public java.lang.String getDescriptorName()
Overrides:
getDescriptorName in class TupleDescriptor
See Also:
TupleDescriptor.getDescriptorName()


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.