Search in sources :

Example 1 with TriggerDescriptorList

use of org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList in project derby by apache.

the class DataDictionaryImpl method getTriggerDescriptors.

/**
 * Load up the trigger descriptor list for this table
 * descriptor and return it.  If the descriptor list
 * is already loaded up, it is retuned without further
 * ado.
 *
 * @param td			The table descriptor.
 *
 * @return The ConstraintDescriptorList for the table
 *
 * @exception StandardException		Thrown on failure
 */
public TriggerDescriptorList getTriggerDescriptors(TableDescriptor td) throws StandardException {
    TriggerDescriptorList gdl;
    /* Build the TableDescriptor's TDL if it is currently empty */
    gdl = td.getTriggerDescriptorList();
    /*
		** Synchronize the building of the TDL.  The TDL itself is created
		** empty when the TD is created, so there is no need to synchronize
		** the getting of the TDL.
		*/
    synchronized (gdl) {
        if (!gdl.getScanned()) {
            getTriggerDescriptorsScan(td, false);
        }
    }
    return gdl;
}
Also used : TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Example 2 with TriggerDescriptorList

use of org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList in project derby by apache.

the class CreateTriggerConstantAction method makeCreationTimestamp.

/**
 * Construct the creation timestamp for the trigger. DERBY-5866: Also make
 * sure the creation timestamp is higher than any timestamp on an existing
 * trigger on the same table. Otherwise, the triggers may not fire in the
 * correct order.
 */
private Timestamp makeCreationTimestamp(DataDictionary dd) throws StandardException {
    Timestamp now = new Timestamp(System.currentTimeMillis());
    // specific scenarios.
    if (SanityManager.DEBUG) {
        String val = PropertyUtil.getSystemProperty("derby.debug.overrideTriggerCreationTimestamp");
        if (val != null) {
            now.setTime(Long.parseLong(val));
        }
    }
    TriggerDescriptorList tdl = dd.getTriggerDescriptors(triggerTable);
    int numTriggers = tdl.size();
    if (numTriggers == 0) {
        // if there are any higher timestamps.
        return now;
    }
    // Get the timestamp of the most recent existing trigger on the table.
    Timestamp highest = tdl.get(numTriggers - 1).getCreationTimestamp();
    if (now.after(highest)) {
        // trigger on the table, so it is OK.
        return now;
    }
    // Otherwise, there is an existing trigger on the table with a
    // timestamp that is at least as high as the current timestamp. Adjust
    // the current timestamp so that it is one millisecond higher than the
    // timestamp of the existing trigger. This ensures that the triggers
    // will fire in the same order as they were created.
    now.setTime(highest.getTime() + 1);
    return now;
}
Also used : Timestamp(java.sql.Timestamp) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Example 3 with TriggerDescriptorList

use of org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList in project derby by apache.

the class UpdateNode method getReadMap.

/**
 * Gets the map of all columns which must be read out of the base table.
 * These are the columns needed to<UL>:
 *		<LI>maintain indices</LI>
 *		<LI>maintain foreign keys</LI>
 *		<LI>maintain generated columns</LI>
 *		<LI>support Replication's Delta Optimization</LI></UL>
 * <p>
 * The returned map is a FormatableBitSet with 1 bit for each column in the
 * table plus an extra, unsued 0-bit. If a 1-based column id must
 * be read from the base table, then the corresponding 1-based bit
 * is turned ON in the returned FormatableBitSet.
 * <p>
 * <B>NOTE</B>: this method is not expected to be called when
 * all columns are being updated (i.e. updateColumnList is null).
 *
 * @param dd				the data dictionary to look in
 * @param baseTable		the base table descriptor
 * @param updateColumnList the rcl for the update. CANNOT BE NULL
 * @param affectedGeneratedColumns columns whose generation clauses mention columns being updated
 *
 * @return a FormatableBitSet of columns to be read out of the base table
 *
 * @exception StandardException		Thrown on error
 */
FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable, ResultColumnList updateColumnList, ColumnDescriptorList affectedGeneratedColumns) throws StandardException {
    boolean[] needsDeferredProcessing = new boolean[1];
    needsDeferredProcessing[0] = requiresDeferredProcessing();
    ArrayList<ConglomerateDescriptor> conglomerates = new ArrayList<ConglomerateDescriptor>();
    relevantCdl = new ConstraintDescriptorList();
    relevantTriggers = new TriggerDescriptorList();
    FormatableBitSet columnMap = getUpdateReadMap(dd, baseTable, updateColumnList, conglomerates, relevantCdl, relevantTriggers, needsDeferredProcessing, affectedGeneratedColumns);
    markAffectedIndexes(conglomerates);
    adjustDeferredFlag(needsDeferredProcessing[0]);
    return columnMap;
}
Also used : ArrayList(java.util.ArrayList) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Example 4 with TriggerDescriptorList

use of org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList in project derby by apache.

the class DMLModStatementNode method getAllRelevantTriggers.

/**
 * Get all the triggers relevant to this DML operation
 *
 * @param dd				The data dictionary
 * @param td				The TableDescriptor
 * @param changedColumnIds	If null, all columns being changed, otherwise array
 *							of 1-based column ids for columns being changed
 * @param includeTriggers	whether we allow trigger processing or not for
 * 							this table
 *
 * @return	the constraint descriptor list
 *
 * @exception StandardException		Thrown on failure
 */
protected TriggerDescriptorList getAllRelevantTriggers(DataDictionary dd, TableDescriptor td, int[] changedColumnIds, boolean includeTriggers) throws StandardException {
    if (relevantTriggers != null) {
        return relevantTriggers;
    }
    relevantTriggers = new TriggerDescriptorList();
    if (!includeTriggers)
        return relevantTriggers;
    td.getAllRelevantTriggers(statementType, changedColumnIds, relevantTriggers);
    adjustDeferredFlag(relevantTriggers.size() > 0);
    return relevantTriggers;
}
Also used : TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Example 5 with TriggerDescriptorList

use of org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList in project derby by apache.

the class DeleteNode method getReadMap.

/**
 *	Gets the map of all columns which must be read out of the base table.
 * These are the columns needed to:
 *
 *		o	maintain indices
 *		o	maintain foreign keys
 *
 *	The returned map is a FormatableBitSet with 1 bit for each column in the
 * table plus an extra, unsued 0-bit. If a 1-based column id must
 * be read from the base table, then the corresponding 1-based bit
 * is turned ON in the returned FormatableBitSet.
 *
 *	@param	dd				the data dictionary to look in
 *	@param	baseTable		the base table descriptor
 *
 *	@return	a FormatableBitSet of columns to be read out of the base table
 *
 * @exception StandardException		Thrown on error
 */
public FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable) throws StandardException {
    boolean[] needsDeferredProcessing = new boolean[1];
    needsDeferredProcessing[0] = requiresDeferredProcessing();
    ArrayList<ConglomerateDescriptor> conglomerates = new ArrayList<ConglomerateDescriptor>();
    relevantTriggers = new TriggerDescriptorList();
    FormatableBitSet columnMap = DeleteNode.getDeleteReadMap(baseTable, conglomerates, relevantTriggers, needsDeferredProcessing);
    markAffectedIndexes(conglomerates);
    adjustDeferredFlag(needsDeferredProcessing[0]);
    return columnMap;
}
Also used : ArrayList(java.util.ArrayList) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Aggregations

TriggerDescriptorList (org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)6 ArrayList (java.util.ArrayList)2 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)2 Timestamp (java.sql.Timestamp)1 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)1 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1