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

pack-priv Class CreateTriggerNode

extends DDLStatementNode
Class Inheritance
Imports
java.util.ArrayList, .Comparator, .HashSet, .List, .SortedSet, .TreeSet, org.apache.derby.catalog.UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .Visitable, .Visitor, org.apache.derby.iapi.sql.conn.Authorizer, .LanguageConnectionContext, org.apache.derby.iapi.sql.depend.DependencyManager, .ProviderInfo, .ProviderList, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .ColumnDescriptorList, .DataDictionary, .SchemaDescriptor, .TableDescriptor, .TriggerDescriptor, org.apache.derby.iapi.sql.execute.ConstantAction

A CreateTriggerNode is the root of a QueryTree that represents a CREATE TRIGGER statement.

Field Summary

Modifier and TypeField and Description
private StatementNode
private String
private final ArrayList<int[]>
actionTransformations

A list that describes how the original SQL text of the trigger action statement was modified when transition tables and transition variables were replaced by VTI calls.

private SchemaDescriptor
private boolean
private boolean
private boolean
private boolean
private String
private static final Comparator<FromBaseTable>
OFFSET_COMPARATOR

Comparator that can be used for sorting lists of FromBaseTables on the position they have in the SQL query string.

private boolean
private String
private String
private String
private ProviderInfo[]
private List<TriggerReferencingStruct>
private int[]
private int[]
private TableName
private ResultColumnList
private int
private TableName
private SchemaDescriptor
private TableDescriptor
private ValueNode
private final ArrayList<int[]>
whenClauseTransformations

Structure that has the same shape as actionTransformations, except that it describes the transformations in the WHEN clause.

private String
Inherited from org.apache.derby.impl.sql.compile.DDLStatementNode:
ADD_TYPEDROP_STATISTICSDROP_TYPEimplicitCreateSchemaLOCKING_TYPEMODIFY_TYPEUNKNOWN_TYPEUPDATE_STATISTICS

Constructor Summary

AccessConstructor and Description
pack-priv
CreateTriggerNode(TableName
name of the trigger
triggerName
,
TableName
name of the table which the trigger is declared upon
tableName
,
int
TriggerDescriptor.TRIGGER_EVENT_XXX
triggerEventMask
,
ResultColumnList
columns trigger is to fire upon. Valid for UPDATE case only.
triggerCols
,
boolean
is before trigger (false for after)
isBefore
,
boolean
true for row trigger, false for statement
isRow
,
boolean
true if enabled
isEnabled
,
List<TriggerReferencingStruct>
the referencing clause
refClause
,
ValueNode
the WHEN clause tree
whenClause
,
String
the text of the WHEN clause
whenText
,
StatementNode
the trigger action tree
actionNode
,
String
the text of the trigger action
actionText
,
ContextManager
context manager
cm
)

Constructor for a CreateTriggerNode

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.DDLStatementNode.acceptChildren.

Accept a visitor on all child nodes.

private boolean
public void
private void
private boolean
equals(String left, String right)

private void
private static Integer

Returns:

the position in the original text, or null if there is no corresponding position in the original text (for example if it points to a token that was added to the transformed text and does not exist in the original text)
getOriginalPosition
(List<int[]>
a data structure that describes the relationship between positions in the original and the transformed text
replacements
,
int
the position to translate
transformedPosition
)

Translate a position from the transformed trigger text (actionText or whenText) to the corresponding position in the original trigger text (originalActionText or originalWhenText).

private SortedSet<FromBaseTable>

Returns:

a sorted set of FromBaseTables that represent transition tables
getTransitionTables
(Visitable
the node in which to search for transition tables
node
)

Get all transition tables referenced by a given node, sorted in the order in which they appear in the SQL text.

private boolean

Returns:

true if fbt represents either the old or the new transition table, false otherwise
isTransitionTable
(FromBaseTable
the table to check
fbt
)

Check if a table represents one of the transition tables.

private int[]
justTheRequiredColumns(int[] columnsArrary)

public ConstantAction
makeConstantAction()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.makeConstantAction.

Create the Constant information that will drive the guts of Execution.

pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object.

private void
qualifyNames(SortedSet<TableName>
all the TableName nodes found in the triggered SQL statement
actionNames
,
SortedSet<TableName>
all the Table Name nodes found in the WHEN clause
whenNames
)

Make sure all references to SQL schema objects (such as tables and functions) in the SQL fragments that will be stored in the SPS and in the trigger descriptor, are fully qualified with a schema name.

private void
qualifyNames(QueryTreeNode
the query tree node for the transformed version of the SQL text, in a bound state
node
,
SortedSet<TableName>
all the TableName nodes in the transformed text, in the order in which they appear in the SQL text
tableNames
,
String
the original SQL text
originalText
,
String
the transformed SQL text (with VTI calls for transition tables or transition variables)
transformedText
,
List<int[]>
a data structure that describes how originalText was transformed into transformedText
replacements
,
StringBuilder
where to store the normalized version of the original text
newOriginal
,
StringBuilder
where to store the normalized version of the transformed text
newTransformed
)

Qualify all names SQL object names in original and transformed SQL text for an action or a WHEN clause.

public boolean

Returns:

true if references SESSION schema tables, else false
referencesSessionSchema
()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

pack-priv String
public String

Returns:

This object as a String
toString
()

Overrides org.apache.derby.impl.sql.compile.DDLStatementNode.toString.

Convert this object to a String.

private String

Returns:

internal syntax for accessing before or after image of the changed rows
transformStatementTriggerText
(QueryTreeNode
the syntax tree of the WHEN clause or the triggered SQL statement
node
,
String
the original text of the WHEN clause or the triggered SQL statement
originalText
,
List<int[]>
list that will be populated with int arrays that describe how the original text was transformed. The int arrays contain the begin (inclusive) and end (exclusive) positions of the original text that got replaced and of the replacement text, so that positions in the transformed text can be mapped to positions in the original text.
replacements
)

Transform the WHEN clause or the triggered SQL statement of a statement trigger from its original shape to internal syntax where references to transition tables are replaced with VTIs that return the before or after image of the changed rows.

private void
Inherited from org.apache.derby.impl.sql.compile.DDLStatementNode:
activationKindgenerategetFullNamegetObjectNamegetRelativeNamegetSchemaDescriptorgetSchemaDescriptorgetTableDescriptorgetTableDescriptorgetTableDescriptorgetTableDescriptorinitAndCheckisAtomicmakeFromList

Field Detail

actionNodeback to summary
private StatementNode actionNode
actionTextback to summary
private String actionText
actionTransformationsback to summary
private final ArrayList<int[]> actionTransformations

A list that describes how the original SQL text of the trigger action statement was modified when transition tables and transition variables were replaced by VTI calls. Each element in the list contains four integers describing positions where modifications have happened. The first two integers are begin and end positions of a transition table or transition variable in the original SQL text. The last two integers are begin and end positions of the corresponding replacement in the transformed SQL text.

Begin positions are inclusive and end positions are exclusive.

compSchemaDescriptorback to summary
private SchemaDescriptor compSchemaDescriptor
isBeforeback to summary
private boolean isBefore
isEnabledback to summary
private boolean isEnabled
isRowback to summary
private boolean isRow
newTableInReferencingClauseback to summary
private boolean newTableInReferencingClause
newTableNameback to summary
private String newTableName
OFFSET_COMPARATORback to summary
private static final Comparator<FromBaseTable> OFFSET_COMPARATOR

Comparator that can be used for sorting lists of FromBaseTables on the position they have in the SQL query string.

oldTableInReferencingClauseback to summary
private boolean oldTableInReferencingClause
oldTableNameback to summary
private String oldTableName
originalActionTextback to summary
private String originalActionText
originalWhenTextback to summary
private String originalWhenText
providerInfoback to summary
private ProviderInfo[] providerInfo
refClauseback to summary
private List<TriggerReferencingStruct> refClause
referencedColIntsback to summary
private int[] referencedColInts
referencedColsInTriggerActionback to summary
private int[] referencedColsInTriggerAction
tableNameback to summary
private TableName tableName

Hides org.apache.derby.impl.sql.compile.DDLStatementNode.tableName.

triggerColsback to summary
private ResultColumnList triggerCols
triggerEventMaskback to summary
private int triggerEventMask
triggerNameback to summary
private TableName triggerName
triggerSchemaDescriptorback to summary
private SchemaDescriptor triggerSchemaDescriptor
triggerTableDescriptorback to summary
private TableDescriptor triggerTableDescriptor
whenClauseback to summary
private ValueNode whenClause
whenClauseTransformationsback to summary
private final ArrayList<int[]> whenClauseTransformations

Structure that has the same shape as actionTransformations, except that it describes the transformations in the WHEN clause.

whenTextback to summary
private String whenText

Constructor Detail

CreateTriggerNodeback to summary
pack-priv CreateTriggerNode(TableName triggerName, TableName tableName, int triggerEventMask, ResultColumnList triggerCols, boolean isBefore, boolean isRow, boolean isEnabled, List<TriggerReferencingStruct> refClause, ValueNode whenClause, String whenText, StatementNode actionNode, String actionText, ContextManager cm) throws StandardException

Constructor for a CreateTriggerNode

Parameters
triggerName:TableName

name of the trigger

tableName:TableName

name of the table which the trigger is declared upon

triggerEventMask:int

TriggerDescriptor.TRIGGER_EVENT_XXX

triggerCols:ResultColumnList

columns trigger is to fire upon. Valid for UPDATE case only.

isBefore:boolean

is before trigger (false for after)

isRow:boolean

true for row trigger, false for statement

isEnabled:boolean

true if enabled

refClause:List<TriggerReferencingStruct>

the referencing clause

whenClause:ValueNode

the WHEN clause tree

whenText:String

the text of the WHEN clause

actionNode:StatementNode

the trigger action tree

actionText:String

the text of the trigger action

cm:ContextManager

context manager

Exceptions
StandardException:
Thrown on error

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

Overrides org.apache.derby.impl.sql.compile.DDLStatementNode.acceptChildren.

Doc from org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Accept a visitor on all child nodes. All sub-classes that add fields that should be visited, should override this method and call accept(v) on all visitable fields, as well as super.acceptChildren(v) to make sure all visitable fields defined by the super-class are accepted too.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on errors raised by the visitor
bindReferencesClauseback to summary
private boolean bindReferencesClause(DataDictionary dd) throws StandardException
bindStatementback to summary
public void bindStatement() throws StandardException

Overrides org.apache.derby.impl.sql.compile.StatementNode.bindStatement.

Bind this CreateTriggerNode. This means doing any static error checking that can be done before actually creating the table.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
checkInvalidTriggerReferenceback to summary
private void checkInvalidTriggerReference(String tableName) throws StandardException
equalsback to summary
private boolean equals(String left, String right)
forbidActionsOnGenColsback to summary
private void forbidActionsOnGenCols() throws StandardException
getOriginalPositionback to summary
private static Integer getOriginalPosition(List<int[]> replacements, int transformedPosition)

Translate a position from the transformed trigger text (actionText or whenText) to the corresponding position in the original trigger text (originalActionText or originalWhenText).

Parameters
replacements:List<int[]>

a data structure that describes the relationship between positions in the original and the transformed text

transformedPosition:int

the position to translate

Returns:Integer

the position in the original text, or null if there is no corresponding position in the original text (for example if it points to a token that was added to the transformed text and does not exist in the original text)

getTransitionTablesback to summary
private SortedSet<FromBaseTable> getTransitionTables(Visitable node) throws StandardException

Get all transition tables referenced by a given node, sorted in the order in which they appear in the SQL text.

Parameters
node:Visitable

the node in which to search for transition tables

Returns:SortedSet<FromBaseTable>

a sorted set of FromBaseTables that represent transition tables

Exceptions
StandardException:
if an error occurs
isTransitionTableback to summary
private boolean isTransitionTable(FromBaseTable fbt)

Check if a table represents one of the transition tables.

Parameters
fbt:FromBaseTable

the table to check

Returns:boolean

true if fbt represents either the old or the new transition table, false otherwise

justTheRequiredColumnsback to summary
private int[] justTheRequiredColumns(int[] columnsArrary)
makeConstantActionback to summary
public ConstantAction makeConstantAction() throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.makeConstantAction.

Create the Constant information that will drive the guts of Execution.

Annotations
@Override
Exceptions
StandardException:
Thrown on failure
printSubNodesback to summary
pack-priv void printSubNodes(int depth)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Parameters
depth:int

The depth of this node in the tree

Annotations
@Override
qualifyNamesback to summary
private void qualifyNames(SortedSet<TableName> actionNames, SortedSet<TableName> whenNames) throws StandardException

Make sure all references to SQL schema objects (such as tables and functions) in the SQL fragments that will be stored in the SPS and in the trigger descriptor, are fully qualified with a schema name.

Parameters
actionNames:SortedSet<TableName>

all the TableName nodes found in the triggered SQL statement

whenNames:SortedSet<TableName>

all the Table Name nodes found in the WHEN clause

qualifyNamesback to summary
private void qualifyNames(QueryTreeNode node, SortedSet<TableName> tableNames, String originalText, String transformedText, List<int[]> replacements, StringBuilder newOriginal, StringBuilder newTransformed) throws StandardException

Qualify all names SQL object names in original and transformed SQL text for an action or a WHEN clause.

Parameters
node:QueryTreeNode

the query tree node for the transformed version of the SQL text, in a bound state

tableNames:SortedSet<TableName>

all the TableName nodes in the transformed text, in the order in which they appear in the SQL text

originalText:String

the original SQL text

transformedText:String

the transformed SQL text (with VTI calls for transition tables or transition variables)

replacements:List<int[]>

a data structure that describes how originalText was transformed into transformedText

newOriginal:StringBuilder

where to store the normalized version of the original text

newTransformed:StringBuilder

where to store the normalized version of the transformed text

referencesSessionSchemaback to summary
public boolean referencesSessionSchema() throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

Returns:boolean

true if references SESSION schema tables, else false

Annotations
@Override
Exceptions
StandardException:
Thrown on error
statementToStringback to summary
pack-priv String statementToString()

Implements abstract org.apache.derby.impl.sql.compile.StatementNode.statementToString.

toStringback to summary
public String toString()

Overrides org.apache.derby.impl.sql.compile.DDLStatementNode.toString.

Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Returns:String

This object as a String

Annotations
@Override
transformStatementTriggerTextback to summary
private String transformStatementTriggerText(QueryTreeNode node, String originalText, List<int[]> replacements) throws StandardException

Transform the WHEN clause or the triggered SQL statement of a statement trigger from its original shape to internal syntax where references to transition tables are replaced with VTIs that return the before or after image of the changed rows.

Parameters
node:QueryTreeNode

the syntax tree of the WHEN clause or the triggered SQL statement

originalText:String

the original text of the WHEN clause or the triggered SQL statement

replacements:List<int[]>

list that will be populated with int arrays that describe how the original text was transformed. The int arrays contain the begin (inclusive) and end (exclusive) positions of the original text that got replaced and of the replacement text, so that positions in the transformed text can be mapped to positions in the original text.

Returns:String

internal syntax for accessing before or after image of the changed rows

Exceptions
StandardException:
if an error happens while performing the transformation
validateReferencesClauseback to summary
private void validateReferencesClause(DataDictionary dd) throws StandardException