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

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


    lockTableForDDL(tc, heapId, true);

    /* Drop the triggers */
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
        for (Iterator descIter = tdl.iterator(); descIter.hasNext(); ) {
            TriggerDescriptor trd = (TriggerDescriptor)descIter.next();
            trd.drop(lcc);
    }

    /* Drop all defaults */
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    int           cdlSize = cdl.size();
View Full Code Here


    boolean          referencingOld = false;
    boolean          referencingNew = false;

    if (td != null)
    {
      TriggerDescriptor triggerDescriptor = (TriggerDescriptor)td;
      name = triggerDescriptor.getName();
      uuid = triggerDescriptor.getUUID();
      suuid = triggerDescriptor.getSchemaDescriptor().getUUID();
      createTime = triggerDescriptor.getCreationTimestamp();
      // for now we are assuming that a trigger can only listen to a single event
      event = triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_UPDATE) ? "U" :
          triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_DELETE) ? "D" : "I";
      time = triggerDescriptor.isBeforeTrigger() ? "B" : "A";
      type = triggerDescriptor.isRowTrigger() ? "R" : "S";
      enabled = triggerDescriptor.isEnabled() ? "E" : "D";
      tuuid = triggerDescriptor.getTableDescriptor().getUUID();
      int[] refCols = triggerDescriptor.getReferencedCols();
      int[] refColsInTriggerAction = triggerDescriptor.getReferencedColsInTriggerAction();
      rcd = (refCols != null || refColsInTriggerAction != null) ? new
        ReferencedColumnsDescriptorImpl(refCols, refColsInTriggerAction) : null;

      actionSPSID =  triggerDescriptor.getActionId();
      whenSPSID =  triggerDescriptor.getWhenClauseId();
      triggerDefinition = triggerDescriptor.getTriggerDefinition();
      referencingOld = triggerDescriptor.getReferencingOld();
      referencingNew = triggerDescriptor.getReferencingNew();
      oldReferencingName = triggerDescriptor.getOldReferencingName();
      newReferencingName = triggerDescriptor.getNewReferencingName();
    }

    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSTRIGGERS_COLUMN_COUNT);

View Full Code Here

    boolean          isRow;
    boolean          isEnabled;
    boolean          referencingOld;
    boolean          referencingNew;
    ReferencedColumns rcd;
    TriggerDescriptor    descriptor;
    DataDescriptorGenerator  ddg = dd.getDataDescriptorGenerator();

    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(row.nColumns() == SYSTRIGGERS_COLUMN_COUNT,
                 "Wrong number of columns for a SYSTRIGGERS row");
    }

    // 1st column is TRIGGERID (UUID - char(36))
    col = row.getColumn(1);
    uuidStr = col.getString();
    uuid = getUUIDFactory().recreateUUID(uuidStr);

    // 2nd column is TRIGGERNAME (varchar(128))
    col = row.getColumn(2);
    name = col.getString();

    // 3rd column is SCHEMAID (UUID - char(36))
    col = row.getColumn(3);
    uuidStr = col.getString();
    suuid = getUUIDFactory().recreateUUID(uuidStr);

    // 4th column is CREATIONTIMESTAMP (TIMESTAMP)
    col = row.getColumn(4);
    createTime = (Timestamp) col.getObject();

    // 5th column is EVENT (char(1))
    col = row.getColumn(5);
    theChar = col.getString().charAt(0);
    switch (theChar)
    {
      case 'U':
            eventMask = TriggerDescriptor.TRIGGER_EVENT_UPDATE;
            break;

      case 'I':
            eventMask = TriggerDescriptor.TRIGGER_EVENT_INSERT;
            break;

      case 'D':
            eventMask = TriggerDescriptor.TRIGGER_EVENT_DELETE;
            break;

      default:
          if (SanityManager.DEBUG
          {
            SanityManager.THROWASSERT("bad event mask: "+theChar);
          }
    }
   
    // 6th column is FIRINGTIME (char(1))
    isBefore = getCharBoolean(row.getColumn(6), 'B', 'A');

    // 7th column is TYPE (char(1))
    isRow = getCharBoolean(row.getColumn(7), 'R', 'S');

    // 8th column is STATE (char(1))
    isEnabled = getCharBoolean(row.getColumn(8), 'E', 'D');

    // 9th column is TABLEID (UUID - char(36))
    col = row.getColumn(9);
    uuidStr = col.getString();
    tuuid = getUUIDFactory().recreateUUID(uuidStr);

    // 10th column is WHENSTMTID (UUID - char(36))
    col = row.getColumn(10);
    uuidStr = col.getString();
    if (uuidStr != null)
      whenSPSID = getUUIDFactory().recreateUUID(uuidStr);

    // 11th column is ACTIONSTMTID (UUID - char(36))
    col = row.getColumn(11);
    uuidStr = col.getString();
    if (uuidStr != null)
      actionSPSID = getUUIDFactory().recreateUUID(uuidStr);

    // 12th column is REFERENCEDCOLUMNS user type org.apache.derby.catalog.ReferencedColumns
    col = row.getColumn(12);
    rcd = (ReferencedColumns) col.getObject();
   
    // 13th column is TRIGGERDEFINITION (longvarhar)
    col = row.getColumn(13);
    triggerDefinition = col.getString();

    // 14th column is REFERENCINGOLD (boolean)
    col = row.getColumn(14);
    referencingOld = col.getBoolean();

    // 15th column is REFERENCINGNEW (boolean)
    col = row.getColumn(15);
    referencingNew = col.getBoolean();

    // 16th column is REFERENCINGNAME (varchar(128))
    col = row.getColumn(16);
    oldReferencingName = col.getString();

    // 17th column is REFERENCINGNAME (varchar(128))
    col = row.getColumn(17);
    newReferencingName = col.getString();

    descriptor = new TriggerDescriptor(
                  dd,
                  dd.getSchemaDescriptor(suuid, null),
                  uuid,
                  name,
                  eventMask,
View Full Code Here

      // go back to the older release if that's what the user chooses
      // after the soft-upgrade.
      boolean in10_9_orHigherVersion = dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_9,null);
            for (Iterator descIter = relevantTriggers.iterator();
                    descIter.hasNext(); ) {
                TriggerDescriptor trd = (TriggerDescriptor) descIter.next();
        if (in10_9_orHigherVersion) {
          // See if we can avoid reading all the columns from the
          // trigger table.
                  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);
                          }
                          //This trigger is not defined on specific columns
                          // so we will have to read all the columns from the
                          // trigger table. Now, there is no need to go
                          // through the rest of the triggers because we are
                          // going to read all the columns anyways.
                          break;
                  } else {
                          if (referencedColsInTriggerAction == null ||
                                          referencedColsInTriggerAction.length == 0) {
                                  //Does this trigger have REFERENCING clause defined on it
                                  if (!trd.getReferencingNew() && !trd.getReferencingOld()) {
                                    //The trigger does not use trigger action columns through
                                    //the REFERENCING clause so we need to read just the
                                    //trigger columns
                                        for (int ix = 0; ix < triggerCols.length; ix++)
                                        {
                                                columnMap.set(triggerCols[ix]);
                                        }
                                  } else {
                                    //The trigger has REFERENCING clause defined on it
                                    // so it might be used them in trigger action.
                                    // We should just go ahead and read all the
                                    // columns from the trigger table. Now, there is
                                    // no need to go through the rest of the triggers
                                    // because we are going to read all the columns
                                    // anyways.
                                    needToIncludeAllColumns = true;
                                    break;
                                  }
                          } else {
                            //This trigger has both trigger columns and
                            // trigger action columns(getting used through
                            // the REFERENCING clause). Read only those
                            // columns because that's all we need from
                            // trigger table for the trigger execution.
                                  for (int ix = 0; ix < triggerCols.length; ix++)
                                  {
                                          columnMap.set(triggerCols[ix]);
                                  }
                                  for (int ix = 0; ix < referencedColsInTriggerAction.length; ix++)
                                  {
                                          columnMap.set(referencedColsInTriggerAction[ix]);
                                  }
                          }
                  }     
              } else {
                //We are in soft upgrade mode working with 10.8 or lower
                // database.
                  //Does this trigger have REFERENCING clause defined on it
                  if (!trd.getReferencingNew() && !trd.getReferencingOld())
                          continue;
                  else
                  {
                          needToIncludeAllColumns = true;
                          break;
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),
                            columnInfo[ix].name, "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

        ** For now, we don't allow bulk insert replace when
        ** there is a trigger.
        */
        if (triggerInfo != null)
        {
          TriggerDescriptor td = triggerInfo.getTriggerArray()[0];
          throw StandardException.newException(SQLState.LANG_NO_BULK_INSERT_REPLACE_WITH_TRIGGER_DURING_EXECUTION, constants.getTableName(), td.getName());
        }
      }
    }

    //System.out.println("new InsertResultSet " + sourceResultSet.getClass());
View Full Code Here

    CompilerContext      cc = getCompilerContext();
    DataDictionary      dd = getDataDictionary();

    SchemaDescriptor sd = getSchemaDescriptor();

    TriggerDescriptor triggerDescriptor = null;
   
    if (sd.getUUID() != null)
      triggerDescriptor = dd.getTriggerDescriptor(getRelativeName(), sd);

    if (triggerDescriptor == null)
    {
      throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "TRIGGER", getFullName());
    }

    /* Get the table descriptor */
    td = triggerDescriptor.getTableDescriptor();
    cc.createDependency(td);
    cc.createDependency(triggerDescriptor);
  }
View Full Code Here

      needsDeferredProcessing[0] = true;
     
      boolean needToIncludeAllColumns = false;
            for (Iterator descIter = relevantTriggers.iterator();
                    descIter.hasNext(); ) {
                TriggerDescriptor trd = (TriggerDescriptor)descIter.next();
        //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

    throws StandardException
  {
    CompilerContext       compilerContext = getCompilerContext();

        for (Iterator descIter = tdl.iterator(); descIter.hasNext() ; ) {
            TriggerDescriptor td = (TriggerDescriptor)descIter.next();
            /*
            ** The dependent now depends on this trigger.
            ** The default dependent is the statement being compiled.
            */
            if (dependent == null) {
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.