Class CreateTriggerNode

  • All Implemented Interfaces:
    Visitable

    class CreateTriggerNode
    extends DDLStatementNode
    A CreateTriggerNode is the root of a QueryTree that represents a CREATE TRIGGER statement.
    • Field Detail

      • triggerEventMask

        private int triggerEventMask
      • isBefore

        private boolean isBefore
      • isRow

        private boolean isRow
      • isEnabled

        private boolean isEnabled
      • whenText

        private java.lang.String whenText
      • actionText

        private java.lang.String actionText
      • originalWhenText

        private java.lang.String originalWhenText
      • originalActionText

        private java.lang.String originalActionText
      • referencedColInts

        private int[] referencedColInts
      • referencedColsInTriggerAction

        private int[] referencedColsInTriggerAction
      • 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 in the 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 as actionTransformations, 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 trigger
        tableName - name of the table which the trigger is declared upon
        triggerEventMask - TriggerDescriptor.TRIGGER_EVENT_XXX
        triggerCols - 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 statement
        isEnabled - true if enabled
        refClause - the referencing clause
        whenClause - the WHEN clause tree
        whenText - the text of the WHEN clause
        actionNode - the trigger action tree
        actionText - the text of the trigger action
        cm - context manager
        Throws:
        StandardException - Thrown on error
    • Method Detail

      • 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 class QueryTreeNode
        Parameters:
        depth - The depth of this node in the tree
      • 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 statement
        whenNames - 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 state
        tableNames - all the TableName nodes in the transformed text, in the order in which they appear in the SQL text
        originalText - the original SQL text
        transformedText - the transformed SQL text (with VTI calls for transition tables or transition variables)
        replacements - a data structure that describes how originalText was transformed into transformedText
        newOriginal - where to store the normalized version of the original text
        newTransformed - 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 or whenText) to the corresponding position in the original trigger text (originalActionText or originalWhenText).
        Parameters:
        replacements - a data structure that describes the relationship between positions in the original and the transformed text
        transformedPosition - 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 statement
        originalText - the original text of the WHEN clause or the triggered SQL statement
        replacements - 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 FromBaseTables 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 if fbt represents either the old or the new transition table, false otherwise
      • equals

        private boolean equals​(java.lang.String left,
                               java.lang.String right)
      • 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 class DDLStatementNode
        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 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.
        Overrides:
        acceptChildren in class DDLStatementNode
        Parameters:
        v - the visitor
        Throws:
        StandardException - on errors raised by the visitor