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
A CreateTriggerNode is the root of a QueryTree
that represents a CREATE TRIGGER
statement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StatementNode
private String
private final ArrayList
<int[]> 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> 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[]> Structure that has the same shape asactionTransformations
, except that it describes the transformations in the WHEN clause.private String
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
ConstructorsConstructorDescriptionCreateTriggerNode
(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) Constructor for a CreateTriggerNode -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept a visitor on all child nodes.private boolean
void
Bind this CreateTriggerNode.private void
checkInvalidTriggerReference
(String tableName) private boolean
private void
private static Integer
getOriginalPosition
(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 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
Check if a table represents one of the transition tables.private int[]
justTheRequiredColumns
(int[] columnsArrary) 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
(SortedSet<TableName> actionNames, 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, SortedSet<TableName> tableNames, String originalText, String transformedText, List<int[]> replacements, StringBuilder newOriginal, StringBuilder newTransformed) Qualify all names SQL object names in original and transformed SQL text for an action or a WHEN clause.boolean
Return true if the node references SESSION schema tables (temporary or permanent)(package private) String
toString()
Convert this object to a String.private String
transformStatementTriggerText
(QueryTreeNode node, String originalText, 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
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 Details
-
triggerName
-
tableName
-
triggerEventMask
private int triggerEventMask -
triggerCols
-
isBefore
private boolean isBefore -
isRow
private boolean isRow -
isEnabled
private boolean isEnabled -
refClause
-
whenClause
-
whenText
-
actionNode
-
actionText
-
originalWhenText
-
originalActionText
-
providerInfo
-
triggerSchemaDescriptor
-
compSchemaDescriptor
-
referencedColInts
private int[] referencedColInts -
referencedColsInTriggerAction
private int[] referencedColsInTriggerAction -
triggerTableDescriptor
-
oldTableName
-
newTableName
-
oldTableInReferencingClause
private boolean oldTableInReferencingClause -
newTableInReferencingClause
private boolean newTableInReferencingClause -
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
Structure that has the same shape asactionTransformations
, except that it describes the transformations in the WHEN clause. -
OFFSET_COMPARATOR
Comparator that can be used for sorting lists of FromBaseTables on the position they have in the SQL query string.
-
-
Constructor Details
-
CreateTriggerNode
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
- 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 Details
-
statementToString
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
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
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
- Throws:
StandardException
-
qualifyNames
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
- 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, 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
- 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
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 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
- 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
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
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
- Throws:
StandardException
-
equals
-
checkInvalidTriggerReference
- Throws:
StandardException
-
validateReferencesClause
- Throws:
StandardException
-
makeConstantAction
Create the Constant information that will drive the guts of Execution.- Overrides:
makeConstantAction
in classQueryTreeNode
- Throws:
StandardException
- Thrown on failure
-
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
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
-