Class CreateTriggerNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.StatementNode
-
- org.apache.derby.impl.sql.compile.DDLStatementNode
-
- org.apache.derby.impl.sql.compile.CreateTriggerNode
-
- All Implemented Interfaces:
Visitable
class CreateTriggerNode extends DDLStatementNode
A CreateTriggerNode is the root of a QueryTree that represents a CREATE TRIGGER statement.
-
-
Field Summary
Fields Modifier and Type Field Description private StatementNode
actionNode
private java.lang.String
actionText
private java.util.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
compSchemaDescriptor
private boolean
isBefore
private boolean
isEnabled
private boolean
isRow
private boolean
newTableInReferencingClause
private java.lang.String
newTableName
private static java.util.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
oldTableInReferencingClause
private java.lang.String
oldTableName
private java.lang.String
originalActionText
private java.lang.String
originalWhenText
private ProviderInfo[]
providerInfo
private java.util.List<TriggerReferencingStruct>
refClause
private int[]
referencedColInts
private int[]
referencedColsInTriggerAction
private TableName
tableName
private ResultColumnList
triggerCols
private int
triggerEventMask
private TableName
triggerName
private SchemaDescriptor
triggerSchemaDescriptor
private TableDescriptor
triggerTableDescriptor
private ValueNode
whenClause
private java.util.ArrayList<int[]>
whenClauseTransformations
Structure that has the same shape asactionTransformations
, except that it describes the transformations in the WHEN clause.private java.lang.String
whenText
-
Fields inherited from class org.apache.derby.impl.sql.compile.DDLStatementNode
ADD_TYPE, DROP_STATISTICS, DROP_TYPE, implicitCreateSchema, LOCKING_TYPE, MODIFY_TYPE, UNKNOWN_TYPE, UPDATE_STATISTICS
-
Fields inherited from class org.apache.derby.impl.sql.compile.StatementNode
EMPTY_TD_LIST, NEED_CURSOR_ACTIVATION, NEED_DDL_ACTIVATION, NEED_NOTHING_ACTIVATION, NEED_PARAM_ACTIVATION, NEED_ROW_ACTIVATION
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description CreateTriggerNode(TableName triggerName, TableName tableName, int triggerEventMask, ResultColumnList triggerCols, boolean isBefore, boolean isRow, boolean isEnabled, java.util.List<TriggerReferencingStruct> refClause, ValueNode whenClause, java.lang.String whenText, StatementNode actionNode, java.lang.String actionText, ContextManager cm)
Constructor for a CreateTriggerNode
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
acceptChildren(Visitor v)
Accept a visitor on all child nodes.private boolean
bindReferencesClause(DataDictionary dd)
void
bindStatement()
Bind this CreateTriggerNode.private void
checkInvalidTriggerReference(java.lang.String tableName)
private boolean
equals(java.lang.String left, java.lang.String right)
private void
forbidActionsOnGenCols()
private static java.lang.Integer
getOriginalPosition(java.util.List<int[]> replacements, int transformedPosition)
Translate a position from the transformed trigger text (actionText
orwhenText
) to the corresponding position in the original trigger text (originalActionText
ororiginalWhenText
).private java.util.SortedSet<FromBaseTable>
getTransitionTables(Visitable node)
Get all transition tables referenced by a given node, sorted in the order in which they appear in the SQL text.private boolean
isTransitionTable(FromBaseTable fbt)
Check if a table represents one of the transition tables.private int[]
justTheRequiredColumns(int[] columnsArrary)
ConstantAction
makeConstantAction()
Create the Constant information that will drive the guts of Execution.(package private) void
printSubNodes(int depth)
Prints the sub-nodes of this object.private void
qualifyNames(java.util.SortedSet<TableName> actionNames, java.util.SortedSet<TableName> 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 node, java.util.SortedSet<TableName> tableNames, java.lang.String originalText, java.lang.String transformedText, java.util.List<int[]> replacements, java.lang.StringBuilder newOriginal, java.lang.StringBuilder newTransformed)
Qualify all names SQL object names in original and transformed SQL text for an action or a WHEN clause.boolean
referencesSessionSchema()
Return true if the node references SESSION schema tables (temporary or permanent)(package private) java.lang.String
statementToString()
java.lang.String
toString()
Convert this object to a String.private java.lang.String
transformStatementTriggerText(QueryTreeNode node, java.lang.String originalText, java.util.List<int[]> 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
validateReferencesClause(DataDictionary dd)
-
Methods inherited from class org.apache.derby.impl.sql.compile.DDLStatementNode
activationKind, generate, getFullName, getObjectName, getRelativeName, getSchemaDescriptor, getSchemaDescriptor, getTableDescriptor, getTableDescriptor, getTableDescriptor, getTableDescriptor, initAndCheck, isAtomic, makeFromList
-
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
executeSchemaName, executeStatementName, generate, getCursorInfo, getSPSName, lockTableForCompilation, makeResultDescription, needsSavepoint, optimizeStatement, updateIndexStatisticsFor
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
triggerName
private TableName triggerName
-
tableName
private TableName tableName
-
triggerEventMask
private int triggerEventMask
-
triggerCols
private ResultColumnList triggerCols
-
isBefore
private boolean isBefore
-
isRow
private boolean isRow
-
isEnabled
private boolean isEnabled
-
refClause
private java.util.List<TriggerReferencingStruct> refClause
-
whenClause
private ValueNode whenClause
-
whenText
private java.lang.String whenText
-
actionNode
private StatementNode actionNode
-
actionText
private java.lang.String actionText
-
originalWhenText
private java.lang.String originalWhenText
-
originalActionText
private java.lang.String originalActionText
-
providerInfo
private ProviderInfo[] providerInfo
-
triggerSchemaDescriptor
private SchemaDescriptor triggerSchemaDescriptor
-
compSchemaDescriptor
private SchemaDescriptor compSchemaDescriptor
-
referencedColInts
private int[] referencedColInts
-
referencedColsInTriggerAction
private int[] referencedColsInTriggerAction
-
triggerTableDescriptor
private TableDescriptor triggerTableDescriptor
-
oldTableName
private java.lang.String oldTableName
-
newTableName
private java.lang.String newTableName
-
oldTableInReferencingClause
private boolean oldTableInReferencingClause
-
newTableInReferencingClause
private boolean newTableInReferencingClause
-
actionTransformations
private final java.util.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 inthe transformed SQL text
.Begin positions are inclusive and end positions are exclusive.
-
whenClauseTransformations
private final java.util.ArrayList<int[]> whenClauseTransformations
Structure that has the same shape asactionTransformations
, except that it describes the transformations in the WHEN clause.
-
OFFSET_COMPARATOR
private static final java.util.Comparator<FromBaseTable> OFFSET_COMPARATOR
Comparator that can be used for sorting lists of FromBaseTables on the position they have in the SQL query string.
-
-
Constructor Detail
-
CreateTriggerNode
CreateTriggerNode(TableName triggerName, TableName tableName, int triggerEventMask, ResultColumnList triggerCols, boolean isBefore, boolean isRow, boolean isEnabled, java.util.List<TriggerReferencingStruct> refClause, ValueNode whenClause, java.lang.String whenText, StatementNode actionNode, java.lang.String actionText, ContextManager cm) throws StandardException
Constructor for a CreateTriggerNode- Parameters:
triggerName
- name of the triggertableName
- name of the table which the trigger is declared upontriggerEventMask
- TriggerDescriptor.TRIGGER_EVENT_XXXtriggerCols
- columns trigger is to fire upon. Valid for UPDATE case only.isBefore
- is before trigger (false for after)isRow
- true for row trigger, false for statementisEnabled
- true if enabledrefClause
- the referencing clausewhenClause
- the WHEN clause treewhenText
- the text of the WHEN clauseactionNode
- the trigger action treeactionText
- the text of the trigger actioncm
- context manager- Throws:
StandardException
- Thrown on error
-
-
Method Detail
-
statementToString
java.lang.String statementToString()
- Specified by:
statementToString
in classStatementNode
-
printSubNodes
void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodes
in classQueryTreeNode
- Parameters:
depth
- The depth of this node in the tree
-
bindStatement
public void bindStatement() throws StandardException
Bind this CreateTriggerNode. This means doing any static error checking that can be done before actually creating the table.- Overrides:
bindStatement
in classStatementNode
- Throws:
StandardException
- Thrown on error
-
referencesSessionSchema
public boolean referencesSessionSchema() throws StandardException
Return true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchema
in classQueryTreeNode
- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException
- Thrown on error
-
bindReferencesClause
private boolean bindReferencesClause(DataDictionary dd) throws StandardException
- Throws:
StandardException
-
qualifyNames
private void qualifyNames(java.util.SortedSet<TableName> actionNames, java.util.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
- all the TableName nodes found in the triggered SQL statementwhenNames
- all the Table Name nodes found in the WHEN clause- Throws:
StandardException
-
qualifyNames
private void qualifyNames(QueryTreeNode node, java.util.SortedSet<TableName> tableNames, java.lang.String originalText, java.lang.String transformedText, java.util.List<int[]> replacements, java.lang.StringBuilder newOriginal, java.lang.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
- the query tree node for the transformed version of the SQL text, in a bound statetableNames
- all the TableName nodes in the transformed text, in the order in which they appear in the SQL textoriginalText
- the original SQL texttransformedText
- the transformed SQL text (with VTI calls for transition tables or transition variables)replacements
- a data structure that describes howoriginalText
was transformed intotransformedText
newOriginal
- where to store the normalized version of the original textnewTransformed
- where to store the normalized version of the transformed text- Throws:
StandardException
-
getOriginalPosition
private static java.lang.Integer getOriginalPosition(java.util.List<int[]> replacements, int transformedPosition)
Translate a position from the transformed trigger text (actionText
orwhenText
) to the corresponding position in the original trigger text (originalActionText
ororiginalWhenText
).- Parameters:
replacements
- a data structure that describes the relationship between positions in the original and the transformed texttransformedPosition
- the position to translate- 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)
-
justTheRequiredColumns
private int[] justTheRequiredColumns(int[] columnsArrary)
-
transformStatementTriggerText
private java.lang.String transformStatementTriggerText(QueryTreeNode node, java.lang.String originalText, java.util.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
- the syntax tree of the WHEN clause or the triggered SQL statementoriginalText
- the original text of the WHEN clause or the triggered SQL statementreplacements
- 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:
- internal syntax for accessing before or after image of the changed rows
- Throws:
StandardException
- if an error happens while performing the transformation
-
getTransitionTables
private java.util.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
- the node in which to search for transition tables- Returns:
- a sorted set of
FromBaseTable
s that represent transition tables - Throws:
StandardException
- if an error occurs
-
isTransitionTable
private boolean isTransitionTable(FromBaseTable fbt)
Check if a table represents one of the transition tables.- Parameters:
fbt
- the table to check- Returns:
true
iffbt
represents either the old or the new transition table,false
otherwise
-
forbidActionsOnGenCols
private void forbidActionsOnGenCols() throws StandardException
- Throws:
StandardException
-
equals
private boolean equals(java.lang.String left, java.lang.String right)
-
checkInvalidTriggerReference
private void checkInvalidTriggerReference(java.lang.String tableName) throws StandardException
- Throws:
StandardException
-
validateReferencesClause
private void validateReferencesClause(DataDictionary dd) throws StandardException
- Throws:
StandardException
-
makeConstantAction
public ConstantAction makeConstantAction() throws StandardException
Create the Constant information that will drive the guts of Execution.- Overrides:
makeConstantAction
in classQueryTreeNode
- Throws:
StandardException
- Thrown on failure
-
toString
public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.- Overrides:
toString
in classDDLStatementNode
- Returns:
- This object as a String
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Description copied from class:QueryTreeNode
Accept a visitor on all child nodes. All sub-classes that add fields that should be visited, should override this method and callaccept(v)
on all visitable fields, as well assuper.acceptChildren(v)
to make sure all visitable fields defined by the super-class are accepted too.- Overrides:
acceptChildren
in classDDLStatementNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on errors raised by the visitor
-
-