Package org.apache.derby.iapi.sql.dictionary

Examples of org.apache.derby.iapi.sql.dictionary.TriggerDescriptor


    /*
    ** Create the trigger descriptor first so the trigger action
    ** compilation can pick up the relevant trigger especially in
    ** the case of self triggering.
    */
    TriggerDescriptor triggerd =
        ddg.newTriggerDescriptor(
                  triggerSd,
                  tmpTriggerId,
                  triggerName,
                  eventMask,
View Full Code Here


          if (providerIsTrigger.getSQLObjectType().equals(Dependable.TRIGGER)) {
            //Drop and recreate the trigger after regenerating
            // it's trigger action plan. If the trigger action
            // depends on the column being dropped, it will be
            // caught here.
            TriggerDescriptor trdToBeDropped  = dd.getTriggerDescriptor(depsTriggerDesc.getUUID());

                        // First check for dependencies in the trigger's WHEN
                        // clause, if there is one.
                        UUID whenClauseId = trdToBeDropped.getWhenClauseId();
                        boolean gotDropped = false;
                        if (whenClauseId != null) {
                            gotDropped = columnDroppedAndTriggerDependencies(
                                    trdToBeDropped, whenClauseId, true,
                                    cascade, columnName);
                        }

                        // If no dependencies were found in the WHEN clause,
                        // we have to check if the triggered SQL statement
                        // depends on the column being dropped. But if there
                        // were dependencies and the trigger has already been
                        // dropped, there is no point in looking for more
                        // dependencies.
                        if (!gotDropped) {
                            columnDroppedAndTriggerDependencies(trdToBeDropped,
                                    trdToBeDropped.getActionId(), false,
                                    cascade, columnName);
                        }
          }
        }
      }
View Full Code Here

            executorLists.add(new ArrayList<TriggerDescriptor>());
    }

    for (int i = 0; i < triggerInfo.triggerArray.length; i++)
    {
      TriggerDescriptor td = triggerInfo.triggerArray[i];
      switch (td.getTriggerEventMask())
      {
        case TriggerDescriptor.TRIGGER_EVENT_INSERT:
          if (td.isBeforeTrigger())
          {
                        executorLists.get(TriggerEvent.BEFORE_INSERT).add(td);
          }
          else
          {
                        executorLists.get(TriggerEvent.AFTER_INSERT).add(td);
          }
          break;


        case TriggerDescriptor.TRIGGER_EVENT_DELETE:
          if (td.isBeforeTrigger())
          {
                        executorLists.get(TriggerEvent.BEFORE_DELETE).add(td);
          }
          else
          {
                        executorLists.get(TriggerEvent.AFTER_DELETE).add(td);
          }
          break;

        case TriggerDescriptor.TRIGGER_EVENT_UPDATE:
          if (td.isBeforeTrigger())
          {
                        executorLists.get(TriggerEvent.BEFORE_UPDATE).add(td);
          }
          else
          {
                        executorLists.get(TriggerEvent.AFTER_UPDATE).add(td);
          }
          break;
        default:
          if (SanityManager.DEBUG)
          {
            SanityManager.THROWASSERT("bad trigger event "+td.getTriggerEventMask());
          }
      }
    }

        for (int i = 0; i < executorLists.size(); i++)
    {
            List<TriggerDescriptor> descriptors = executorLists.get(i);
            int size = descriptors.size();
      if (size > 0)
      {
        executors[i] = new GenericTriggerExecutor[size];
        for (int j = 0; j < size; j++)
        {
                    TriggerDescriptor td = descriptors.get(j);
          executors[i][j] (td.isRowTrigger()) ?
                (GenericTriggerExecutor)new RowTriggerExecutor(tec, td, activation, lcc) :
                (GenericTriggerExecutor)new StatementTriggerExecutor(tec, td, activation, lcc);
        }
      }
    }
View Full Code Here

   * @exception StandardException    Thrown on failure
   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    TriggerDescriptor       triggerd;

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();

    /*
    ** Inform the data dictionary that we are about to write to it.
    ** There are several calls to data dictionary "get" methods here
    ** that might be done in "read" mode in the data dictionary, but
    ** it seemed safer to do this whole operation in "write" mode.
    **
    ** We tell the data dictionary we're done writing at the end of
    ** the transaction.
    */
    dd.startWriting(lcc);

    TableDescriptor td = dd.getTableDescriptor(tableId);
    if (td == null)
    {
      throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,
                tableId.toString());
    }
    TransactionController tc = lcc.getTransactionExecute();
    lockTableForDDL(tc, td.getHeapConglomerateId(), true);
    // get td again in case table shape is changed before lock is acquired
    td = dd.getTableDescriptor(tableId);
    if (td == null)
    {
      throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,
                tableId.toString());
    }

    /*
    ** Get the trigger descriptor.  We're responsible for raising
    ** the error if it isn't found
    */
    triggerd = dd.getTriggerDescriptor(triggerName, sd);

    if (triggerd == null)
    {
      throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "TRIGGER",
          (sd.getSchemaName() + "." + triggerName));
    }

    /*
     ** Prepare all dependents to invalidate.  (This is there chance
    ** to say that they can't be invalidated.  For example, an open
    ** cursor referencing a table/trigger that the user is attempting to
    ** drop.) If no one objects, then invalidate any dependent objects.
    */
        triggerd.drop(lcc);
  }
View Full Code Here

    // need to deal with triggers if has referencedColumns
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
    Enumeration descs = tdl.elements();
    while (descs.hasMoreElements())
    {
      TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
      int[] referencedCols = trd.getReferencedCols();
      if (referencedCols == null)
        continue;
      int refColLen = referencedCols.length, j;
      boolean changed = false;
      for (j = 0; j < refColLen; j++)
      {
        if (referencedCols[j] > droppedColumnPosition)
                {
          changed = true;
                }
        else if (referencedCols[j] == droppedColumnPosition)
        {
          if (cascade)
          {
                        trd.drop(lcc);
            activation.addWarning(
              StandardException.newWarning(
                                SQLState.LANG_TRIGGER_DROPPED,
                                trd.getName(), td.getName()));
          }
          else
          // we'd better give an error if don't drop it,
            // otherwsie there would be unexpected behaviors
            throw StandardException.newException(
                            SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                            dm.getActionString(DependencyManager.DROP_COLUMN),
                            columnName, "TRIGGER",
                            trd.getName() );
          }
          break;
        }
      }
View Full Code Here

    //truncate is not allowed when there are enabled DELETE triggers
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
    Enumeration descs = tdl.elements();
    while (descs.hasMoreElements())
    {
      TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
      if (trd.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_DELETE) &&
        trd.isEnabled())
      {
        throw
          StandardException.newException(SQLState.LANG_NO_TRUNCATE_ON_ENABLED_DELETE_TRIGGERS,
                           td.getName(),trd.getName())
      }
    }

    //gather information from the existing conglomerate to create new one.
    emptyHeapRow = td.getEmptyExecRow();
View Full Code Here

    /*
    ** Create the trigger descriptor first so the trigger action
    ** compilation can pick up the relevant trigger especially in
    ** the case of self triggering.
    */
    TriggerDescriptor triggerd =
        ddg.newTriggerDescriptor(
                  triggerSd,
                  tmpTriggerId,
                  triggerName,
                  eventMask,
View Full Code Here

     
      boolean needToIncludeAllColumns = false;
      Enumeration descs = relevantTriggers.elements();
      while (descs.hasMoreElements())
      {
        TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
        //Does this trigger have REFERENCING clause defined on it.
        //If yes, then read all the columns from the trigger table.
        if (!trd.getReferencingNew() && !trd.getReferencingOld())
          continue;
        else
        {
          needToIncludeAllColumns = true;
          break;
View Full Code Here

    Enumeration descs = tdl.elements();

    while (descs.hasMoreElements())
    {
      TriggerDescriptor td = (TriggerDescriptor)descs.nextElement();

      /*
      ** The dependent now depends on this trigger.
      ** the default dependent is the statement
      ** being compiled.
View Full Code Here

    {
      needsDeferredProcessing[0] = true;
      Enumeration descs = relevantTriggers.elements();
      while (descs.hasMoreElements())
      {
        TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
       
        int[] referencedColsInTriggerAction = trd.getReferencedColsInTriggerAction();
        int[] triggerCols = trd.getReferencedCols();
        if (triggerCols == null || triggerCols.length == 0) {
          for (int i=0; i < columnCount; i++) {
            columnMap.set(i+1);
          }
          //no need to go through the test of the trigger because
          //we have already decided to read all the columns
          //because no trigger action columns were found for the
          //trigger that we are considering right now.
          break;
        } else {
          if (referencedColsInTriggerAction == null ||
              referencedColsInTriggerAction.length == 0) {
            //Does this trigger have REFERENCING clause defined on it
            if (!trd.getReferencingNew() && !trd.getReferencingOld()) {
              for (int ix = 0; ix < triggerCols.length; ix++)
              {
                columnMap.set(triggerCols[ix]);
              }
            } else {
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.dictionary.TriggerDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.