Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.impl.sql.execute
Class InternalTriggerExecutionContext  view InternalTriggerExecutionContext download InternalTriggerExecutionContext.java

java.lang.Object
  extended byorg.apache.derby.impl.sql.execute.InternalTriggerExecutionContext
All Implemented Interfaces:
org.apache.derby.iapi.sql.execute.ExecutionStmtValidator, org.apache.derby.iapi.db.TriggerExecutionContext

public class InternalTriggerExecutionContext
extends java.lang.Object
implements org.apache.derby.iapi.db.TriggerExecutionContext, org.apache.derby.iapi.sql.execute.ExecutionStmtValidator

There is one of these beasts per INSERT/DELETE/UPDATE statement. It fulfills the contract for the externally visible trigger execution context and it validates that a statement that is about to be executed doesn't violate the restrictions placed upon what can be executed from a trigger.

Note that it is crucial that cleanup() is called once the DML has completed, cleanup() makes sure that users can't do something invalid on a tec reference that they were holding from when the trigger fired.


Field Summary
protected  org.apache.derby.iapi.sql.execute.CursorResultSet afterResultSet
           
protected  org.apache.derby.iapi.sql.execute.ExecRow afterRow
          used exclusively for InsertResultSets which have autoincrement columns.
private  java.util.Vector aiCounters
          aiCounters is a vector of AutoincrementCounters used to keep state which might be used by the trigger.
private  java.util.Hashtable aiHT
          aiHT is a hashtable of autincrement pairs.
protected  org.apache.derby.iapi.sql.execute.CursorResultSet beforeResultSet
           
protected  org.apache.derby.iapi.jdbc.ConnectionContext cc
           
protected  int[] changedColIds
           
protected  java.lang.String[] changedColNames
           
protected  boolean cleanupCalled
           
protected  int dmlType
           
protected  TriggerEvent event
           
protected  org.apache.derby.iapi.sql.conn.LanguageConnectionContext lcc
           
private  java.util.Vector resultSetVector
           
protected  java.lang.String statementText
           
protected  org.apache.derby.catalog.UUID targetTableId
           
protected  java.lang.String targetTableName
           
protected  org.apache.derby.iapi.sql.dictionary.TriggerDescriptor triggerd
           
 
Fields inherited from interface org.apache.derby.iapi.db.TriggerExecutionContext
DELETE_EVENT, INSERT_EVENT, UPDATE_EVENT
 
Constructor Summary
InternalTriggerExecutionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext lcc, org.apache.derby.iapi.jdbc.ConnectionContext cc, java.lang.String statementText, int dmlType, int[] changedColIds, java.lang.String[] changedColNames, org.apache.derby.catalog.UUID targetTableId, java.lang.String targetTableName, java.util.Vector aiCounters)
          Build me a big old nasty trigger execution context.
 
Method Summary
protected  void cleanup()
          Cleanup the trigger execution context.
(package private)  void clearCurrentTriggerEvent()
           
(package private)  void clearTrigger()
           
 void copyHashtableToAIHT(java.util.Hashtable from)
          Copy a hashtable of autoincrement values into the trigger execution context hashtable of autoincrement values.
private  void ensureProperContext()
          Make sure that the user isn't trying to get a result set after we have cleaned up.
 java.lang.Long getAutoincrementValue(java.lang.String identity)
           
 java.lang.String getEventStatementText()
          Get the text of the statement that caused the trigger to fire.
 int getEventType()
          Get the type for the event that caused the trigger to fire.
 java.lang.String[] getModifiedColumns()
          Get the columns that have been modified by the statement that caused this trigger to fire.
 java.sql.ResultSet getNewRow()
          Like getAfterResultSet(), but returns a result set positioned on the first row of the before result set.
 java.sql.ResultSet getNewRowSet()
          Returns a result set row the new images of the changed rows.
 java.sql.ResultSet getOldRow()
          Like getBeforeResultSet(), but returns a result set positioned on the first row of the before result set.
 java.sql.ResultSet getOldRowSet()
          Returns a result set row the old images of the changed rows.
 org.apache.derby.catalog.UUID getTargetTableId()
          Get the target table UUID upon which the trigger event is declared.
 java.lang.String getTargetTableName()
          Get the target table name upon which the trigger event is declared.
 void resetAICounters(boolean begin)
          Reset Autoincrement counters to the beginning or the end.
(package private)  void setAfterResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet rs)
           
(package private)  void setBeforeResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet rs)
           
(package private)  void setCurrentTriggerEvent(TriggerEvent event)
           
(package private)  void setTrigger(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor triggerd)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 void updateAICounters()
          Update Autoincrement Counters from the last row inserted.
 void validateStatement(org.apache.derby.iapi.sql.execute.ConstantAction constantAction)
          Make sure that whatever statement is about to be executed is ok from the context of this trigger.
 boolean wasColumnModified(int columnNumber)
          Find out of a column was changed, by column number
 boolean wasColumnModified(java.lang.String columnName)
          Find out of a column was changed, by column name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

changedColIds

protected int[] changedColIds

changedColNames

protected java.lang.String[] changedColNames

dmlType

protected int dmlType

statementText

protected java.lang.String statementText

cc

protected org.apache.derby.iapi.jdbc.ConnectionContext cc

targetTableId

protected org.apache.derby.catalog.UUID targetTableId

targetTableName

protected java.lang.String targetTableName

lcc

protected org.apache.derby.iapi.sql.conn.LanguageConnectionContext lcc

beforeResultSet

protected org.apache.derby.iapi.sql.execute.CursorResultSet beforeResultSet

afterResultSet

protected org.apache.derby.iapi.sql.execute.CursorResultSet afterResultSet

afterRow

protected org.apache.derby.iapi.sql.execute.ExecRow afterRow
used exclusively for InsertResultSets which have autoincrement columns.


cleanupCalled

protected boolean cleanupCalled

event

protected TriggerEvent event

triggerd

protected org.apache.derby.iapi.sql.dictionary.TriggerDescriptor triggerd

resultSetVector

private java.util.Vector resultSetVector

aiCounters

private java.util.Vector aiCounters
aiCounters is a vector of AutoincrementCounters used to keep state which might be used by the trigger. This is only used by Insert triggers-- Delete and Update triggers do not use this variable.

See Also:
AutoincrementCounter

aiHT

private java.util.Hashtable aiHT
aiHT is a hashtable of autincrement pairs. This is used for ai values generated by the trigger.

Constructor Detail

InternalTriggerExecutionContext

public InternalTriggerExecutionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext lcc,
                                       org.apache.derby.iapi.jdbc.ConnectionContext cc,
                                       java.lang.String statementText,
                                       int dmlType,
                                       int[] changedColIds,
                                       java.lang.String[] changedColNames,
                                       org.apache.derby.catalog.UUID targetTableId,
                                       java.lang.String targetTableName,
                                       java.util.Vector aiCounters)
                                throws org.apache.derby.iapi.error.StandardException
Build me a big old nasty trigger execution context. Damnit.

About the only thing of real interest to outside observers is that it pushes itself as the trigger execution context in the lcc. Be sure to call cleanup() when you are done, or you will be flogged like the reprobate that you are.

Method Detail

setBeforeResultSet

void setBeforeResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet rs)

setAfterResultSet

void setAfterResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet rs)
                 throws org.apache.derby.iapi.error.StandardException

setCurrentTriggerEvent

void setCurrentTriggerEvent(TriggerEvent event)

clearCurrentTriggerEvent

void clearCurrentTriggerEvent()

setTrigger

void setTrigger(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor triggerd)

clearTrigger

void clearTrigger()
            throws org.apache.derby.iapi.error.StandardException

cleanup

protected void cleanup()
                throws org.apache.derby.iapi.error.StandardException
Cleanup the trigger execution context. MUST be called when the caller is done with the trigger execution context.

We go to somewhat exaggerated lengths to free up all our resources here because a user may hold on to a TEC after it is valid, so we clean everything up to be on the safe side.


ensureProperContext

private void ensureProperContext()
                          throws java.sql.SQLException
Make sure that the user isn't trying to get a result set after we have cleaned up.


validateStatement

public void validateStatement(org.apache.derby.iapi.sql.execute.ConstantAction constantAction)
                       throws org.apache.derby.iapi.error.StandardException
Make sure that whatever statement is about to be executed is ok from the context of this trigger.

Note that we are sub classed in replication for checks for replication specific language.

Specified by:
validateStatement in interface org.apache.derby.iapi.sql.execute.ExecutionStmtValidator

getTargetTableName

public java.lang.String getTargetTableName()
Get the target table name upon which the trigger event is declared.

Specified by:
getTargetTableName in interface org.apache.derby.iapi.db.TriggerExecutionContext

getTargetTableId

public org.apache.derby.catalog.UUID getTargetTableId()
Get the target table UUID upon which the trigger event is declared.

Specified by:
getTargetTableId in interface org.apache.derby.iapi.db.TriggerExecutionContext

getEventType

public int getEventType()
Get the type for the event that caused the trigger to fire.

Specified by:
getEventType in interface org.apache.derby.iapi.db.TriggerExecutionContext

getEventStatementText

public java.lang.String getEventStatementText()
Get the text of the statement that caused the trigger to fire.

Specified by:
getEventStatementText in interface org.apache.derby.iapi.db.TriggerExecutionContext

getModifiedColumns

public java.lang.String[] getModifiedColumns()
Get the columns that have been modified by the statement that caused this trigger to fire. If all columns are modified, will return null (e.g. for INSERT or DELETE will return null).

Specified by:
getModifiedColumns in interface org.apache.derby.iapi.db.TriggerExecutionContext

wasColumnModified

public boolean wasColumnModified(java.lang.String columnName)
Find out of a column was changed, by column name

Specified by:
wasColumnModified in interface org.apache.derby.iapi.db.TriggerExecutionContext

wasColumnModified

public boolean wasColumnModified(int columnNumber)
Find out of a column was changed, by column number

Specified by:
wasColumnModified in interface org.apache.derby.iapi.db.TriggerExecutionContext

getOldRowSet

public java.sql.ResultSet getOldRowSet()
                                throws java.sql.SQLException
Returns a result set row the old images of the changed rows. For a row trigger, the result set will have a single row. For a statement trigger, this result set has every row that has changed or will change. If a statement trigger does not affect a row, then the result set will be empty (i.e. ResultSet.next() will return false).

Specified by:
getOldRowSet in interface org.apache.derby.iapi.db.TriggerExecutionContext

getNewRowSet

public java.sql.ResultSet getNewRowSet()
                                throws java.sql.SQLException
Returns a result set row the new images of the changed rows. For a row trigger, the result set will have a single row. For a statement trigger, this result set has every row that has changed or will change. If a statement trigger does not affect a row, then the result set will be empty (i.e. ResultSet.next() will return false).

Specified by:
getNewRowSet in interface org.apache.derby.iapi.db.TriggerExecutionContext

getOldRow

public java.sql.ResultSet getOldRow()
                             throws java.sql.SQLException
Like getBeforeResultSet(), but returns a result set positioned on the first row of the before result set. Used as a convenience to get a column for a row trigger. Equivalent to getBeforeResultSet() followed by next().

Specified by:
getOldRow in interface org.apache.derby.iapi.db.TriggerExecutionContext

getNewRow

public java.sql.ResultSet getNewRow()
                             throws java.sql.SQLException
Like getAfterResultSet(), but returns a result set positioned on the first row of the before result set. Used as a convenience to get a column for a row trigger. Equivalent to getAfterResultSet() followed by next().

Specified by:
getNewRow in interface org.apache.derby.iapi.db.TriggerExecutionContext

getAutoincrementValue

public java.lang.Long getAutoincrementValue(java.lang.String identity)

copyHashtableToAIHT

public void copyHashtableToAIHT(java.util.Hashtable from)
Copy a hashtable of autoincrement values into the trigger execution context hashtable of autoincrement values.


resetAICounters

public void resetAICounters(boolean begin)
Reset Autoincrement counters to the beginning or the end.


updateAICounters

public void updateAICounters()
                      throws org.apache.derby.iapi.error.StandardException
Update Autoincrement Counters from the last row inserted.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).