Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

pack-priv Class InternalTriggerExecutionContext

extends Object
implements TriggerExecutionContext, ExecutionStmtValidator
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.execute.ExecutionStmtValidator, org.apache.derby.iapi.db.TriggerExecutionContext
Imports
java.sql.ResultSet, .SQLException, java.util.Hashtable, .Map, .Vector, org.apache.derby.catalog.UUID, org.apache.derby.iapi.db.TriggerExecutionContext, org.apache.derby.shared.common.error.ExceptionSeverity, .PublicAPI, .StandardException, org.apache.derby.iapi.jdbc.ConnectionContext, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.TriggerDescriptor, org.apache.derby.iapi.sql.execute.ConstantAction, .CursorResultSet, .ExecRow, .ExecutionStmtValidator, org.apache.derby.iapi.types.DataValueDescriptor

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

Modifier and TypeField and Description
protected CursorResultSet
protected ExecRow
afterRow

used exclusively for InsertResultSets which have autoincrement columns.

private Vector<AutoincrementCounter>
aiCounters

aiCounters is a vector of AutoincrementCounters used to keep state which might be used by the trigger.

private Hashtable<String, Long>
aiHT

aiHT is a hash table of auto increment (key, value) pairs.

protected CursorResultSet
protected ConnectionContext
protected boolean
protected int
protected TriggerEvent
protected LanguageConnectionContext
private Vector<ResultSet>
protected String
protected UUID
protected String
protected TriggerDescriptor

Constructor Summary

AccessConstructor and Description
pack-priv
InternalTriggerExecutionContext(LanguageConnectionContext
the lcc
lcc
,
ConnectionContext cc, String
the text of the statement that caused the trigger to fire. may be null if we are replicating
statementText
,
int dmlType, UUID
the UUID of the table upon which the trigger fired
targetTableId
,
String
the name of the table upon which the trigger fired
targetTableName
,
Vector<AutoincrementCounter>
A vector of AutoincrementCounters to keep state of the ai columns in this insert trigger.a
aiCounters
)

Build a trigger execution context.

Method Summary

Modifier and TypeMethod and Description
protected void
cleanup()

Cleanup the trigger execution context.

pack-priv void
pack-priv void
public void
copyHashtableToAIHT(Map<String, Long> from)

Copy a map of auto increment values into the trigger execution context hash table of auto increment values.

private void
ensureProperContext()

Make sure that the user isn't trying to get a result set after we have cleaned up.

public Long
getAutoincrementValue(String
the fully qualified name of the identity column
identity
)

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getAutoincrementValue.

Get the last auto-increment value for the specified column.

public String

Returns:

the statement text
getEventStatementText
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getEventStatementText.

Get the text of the statement that caused the trigger to fire.

public int

Returns:

the event type (e.g. UPDATE_EVENT)
getEventType
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getEventType.

Get the type for the event that caused the trigger to fire.

public ResultSet

Returns:

the ResultSet positioned on the new row image.
getNewRow
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getNewRow.

Like getAfterResultSet(), but returns a result set positioned on the first row of the before result set.

public ResultSet

Returns:

the ResultSet containing after images of the rows changed by the triggering event.
getNewRowSet
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getNewRowSet.

Returns a result set row the new images of the changed rows.

public ResultSet

Returns:

the ResultSet positioned on the old row image.
getOldRow
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getOldRow.

Like getBeforeResultSet(), but returns a result set positioned on the first row of the before result set.

public ResultSet

Returns:

the ResultSet containing before images of the rows changed by the triggering event.
getOldRowSet
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getOldRowSet.

Returns a result set row the old images of the changed rows.

public UUID

Returns:

the uuid of the target table
getTargetTableId
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getTargetTableId.

Get the target table UUID upon which the trigger event is declared.

public String

Returns:

the target table
getTargetTableName
()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getTargetTableName.

Get the target table name upon which the trigger event is declared.

public void
resetAICounters(boolean
if True, reset the AutoincremnetCounter to the beginning-- used to reset the counters for the next trigger. If false, reset it to the end-- this sets up the counter appropriately for a AFTER STATEMENT trigger.
begin
)

Reset Autoincrement counters to the beginning or the end.

pack-priv void
pack-priv void
pack-priv void
pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
updateAICounters()

Update auto increment counters from the last row inserted.

public void
validateStatement(ConstantAction
the constant action of the action that we are to validate
constantAction
)

Implements org.apache.derby.iapi.sql.execute.ExecutionStmtValidator.validateStatement.

Make sure that whatever statement is about to be executed is ok from the context of this trigger.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

afterResultSetback to summary
protected CursorResultSet afterResultSet
afterRowback to summary
protected ExecRow afterRow

used exclusively for InsertResultSets which have autoincrement columns.

aiCountersback to summary
private Vector<AutoincrementCounter> 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.

Annotations
@SuppressWarnings:UseOfObsoleteCollectionType
See Also
AutoincrementCounter
aiHTback to summary
private Hashtable<String, Long> aiHT

aiHT is a hash table of auto increment (key, value) pairs. This is used for auto increment values generated by the trigger.

Annotations
@SuppressWarnings:UseOfObsoleteCollectionType
beforeResultSetback to summary
protected CursorResultSet beforeResultSet
ccback to summary
protected ConnectionContext cc
cleanupCalledback to summary
protected boolean cleanupCalled
dmlTypeback to summary
protected int dmlType
eventback to summary
protected TriggerEvent event
lccback to summary
protected LanguageConnectionContext lcc
resultSetVectorback to summary
private Vector<ResultSet> resultSetVector
Annotations
@SuppressWarnings:UseOfObsoleteCollectionType
statementTextback to summary
protected String statementText
targetTableIdback to summary
protected UUID targetTableId
targetTableNameback to summary
protected String targetTableName
triggerdback to summary
protected TriggerDescriptor triggerd

Constructor Detail

InternalTriggerExecutionContextback to summary
pack-priv InternalTriggerExecutionContext(LanguageConnectionContext lcc, ConnectionContext cc, String statementText, int dmlType, UUID targetTableId, String targetTableName, Vector<AutoincrementCounter> aiCounters) throws StandardException

Build a trigger execution context.

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.

Parameters
lcc:LanguageConnectionContext

the lcc

statementText:String

the text of the statement that caused the trigger to fire. may be null if we are replicating

targetTableId:UUID

the UUID of the table upon which the trigger fired

targetTableName:String

the name of the table upon which the trigger fired

aiCounters:Vector<AutoincrementCounter>

A vector of AutoincrementCounters to keep state of the ai columns in this insert trigger.a

Annotations
@SuppressWarnings:UseOfObsoleteCollectionType, LeakingThisInConstructor
Exceptions
StandardException:
on error

Method Detail

cleanupback to summary
protected void cleanup() throws 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.

Exceptions
StandardException:
on unexpected error
clearCurrentTriggerEventback to summary
pack-priv void clearCurrentTriggerEvent()
clearTriggerback to summary
pack-priv void clearTrigger() throws StandardException
copyHashtableToAIHTback to summary
public void copyHashtableToAIHT(Map<String, Long> from)

Copy a map of auto increment values into the trigger execution context hash table of auto increment values.

Annotations
@SuppressWarnings:UseOfObsoleteCollectionType
ensureProperContextback to summary
private void ensureProperContext() throws SQLException

Make sure that the user isn't trying to get a result set after we have cleaned up.

getAutoincrementValueback to summary
public Long getAutoincrementValue(String identity)

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getAutoincrementValue.

Doc from org.apache.derby.iapi.db.TriggerExecutionContext.getAutoincrementValue.

Get the last auto-increment value for the specified column.

Parameters
identity:String

the fully qualified name of the identity column

Returns:Long

the last auto-increment value, or null if not found

getEventStatementTextback to summary
public String getEventStatementText()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getEventStatementText.

Get the text of the statement that caused the trigger to fire.

Returns:String

the statement text

getEventTypeback to summary
public int getEventType()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getEventType.

Get the type for the event that caused the trigger to fire.

Returns:int

the event type (e.g. UPDATE_EVENT)

getNewRowback to summary
public ResultSet getNewRow() throws SQLException

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getNewRow.

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

Returns:ResultSet

the ResultSet positioned on the new row image.

Exceptions
SQLException:
if called after the triggering event has completed
getNewRowSetback to summary
public ResultSet getNewRowSet() throws SQLException

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getNewRowSet.

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).

Returns:ResultSet

the ResultSet containing after images of the rows changed by the triggering event.

Exceptions
SQLException:
if called after the triggering event has completed
getOldRowback to summary
public ResultSet getOldRow() throws SQLException

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getOldRow.

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

Returns:ResultSet

the ResultSet positioned on the old row image.

Exceptions
SQLException:
if called after the triggering event has completed
getOldRowSetback to summary
public ResultSet getOldRowSet() throws SQLException

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getOldRowSet.

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).

Returns:ResultSet

the ResultSet containing before images of the rows changed by the triggering event.

Exceptions
SQLException:
if called after the triggering event has completed
getTargetTableIdback to summary
public UUID getTargetTableId()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getTargetTableId.

Get the target table UUID upon which the trigger event is declared.

Returns:UUID

the uuid of the target table

getTargetTableNameback to summary
public String getTargetTableName()

Implements org.apache.derby.iapi.db.TriggerExecutionContext.getTargetTableName.

Get the target table name upon which the trigger event is declared.

Returns:String

the target table

resetAICountersback to summary
public void resetAICounters(boolean begin)

Reset Autoincrement counters to the beginning or the end.

Parameters
begin:boolean

if True, reset the AutoincremnetCounter to the beginning-- used to reset the counters for the next trigger. If false, reset it to the end-- this sets up the counter appropriately for a AFTER STATEMENT trigger.

setAfterResultSetback to summary
pack-priv void setAfterResultSet(CursorResultSet rs) throws StandardException
setBeforeResultSetback to summary
pack-priv void setBeforeResultSet(CursorResultSet rs)
setCurrentTriggerEventback to summary
pack-priv void setCurrentTriggerEvent(TriggerEvent event)
setTriggerback to summary
pack-priv void setTrigger(TriggerDescriptor triggerd)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateAICountersback to summary
public void updateAICounters() throws StandardException

Update auto increment counters from the last row inserted.

validateStatementback to summary
public void validateStatement(ConstantAction constantAction) throws StandardException

Implements org.apache.derby.iapi.sql.execute.ExecutionStmtValidator.validateStatement.

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.

Parameters
constantAction:ConstantAction

the constant action of the action that we are to validate

Exceptions
StandardException:
on error