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 Details

    • 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 List<TriggerReferencingStruct> refClause
    • whenClause

      private ValueNode whenClause
    • whenText

      private String whenText
    • actionNode

      private StatementNode actionNode
    • actionText

      private String actionText
    • originalWhenText

      private String originalWhenText
    • originalActionText

      private 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 String oldTableName
    • newTableName

      private String newTableName
    • oldTableInReferencingClause

      private boolean oldTableInReferencingClause
    • newTableInReferencingClause

      private boolean newTableInReferencingClause
    • actionTransformations

      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.

    • whenClauseTransformations

      private final 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 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 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 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 Details

    • statementToString

      String statementToString()
      Specified by:
      statementToString in class StatementNode
    • 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
    • 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 class StatementNode
      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 class QueryTreeNode
      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(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 statement
      whenNames - 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 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 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 - 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 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 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 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
    • forbidActionsOnGenCols

      private void forbidActionsOnGenCols() throws StandardException
      Throws:
      StandardException
    • equals

      private boolean equals(String left, String right)
    • checkInvalidTriggerReference

      private void checkInvalidTriggerReference(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 class QueryTreeNode
      Throws:
      StandardException - Thrown on failure
    • toString

      public 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