Search in sources :

Example 1 with TriggerExecutionContext

use of org.apache.derby.iapi.db.TriggerExecutionContext in project derby by apache.

the class TriggerOldTransitionRows method initializeResultSet.

private ResultSet initializeResultSet() throws SQLException {
    if (resultSet != null)
        resultSet.close();
    TriggerExecutionContext tec = Factory.getTriggerExecutionContext();
    if (tec == null) {
        throw new SQLException("There are no active triggers", "38000");
    }
    resultSet = tec.getOldRowSet();
    if (resultSet == null) {
        throw new SQLException("There is no old transition rows result set for this trigger", "38000");
    }
    return resultSet;
}
Also used : SQLException(java.sql.SQLException) TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext)

Example 2 with TriggerExecutionContext

use of org.apache.derby.iapi.db.TriggerExecutionContext in project derby by apache.

the class TriggerGeneralTest method printTriggerChanges.

private static void printTriggerChanges() throws Throwable {
    final TriggerExecutionContext tec = Factory.getTriggerExecutionContext();
    out.println("BEFORE RESULT SET");
    BaseJDBCTestCase.dumpRs(tec.getOldRowSet(), out);
    out.println("\nAFTER RESULT SET");
    BaseJDBCTestCase.dumpRs(tec.getNewRowSet(), out);
}
Also used : TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext)

Example 3 with TriggerExecutionContext

use of org.apache.derby.iapi.db.TriggerExecutionContext in project derby by apache.

the class GenericLanguageConnectionContext method lastAutoincrementValue.

/**
 * lastAutoincrementValue searches for the last autoincrement value inserted
 * into a column specified by the user. The search for the "last" value
 * supports nesting levels caused by triggers (Only triggers cause nesting,
 * not server side JDBC).
 * If lastAutoincrementValue is called from within a trigger, the search
 * space for ai-values are those values that are inserted by this trigger as
 * well as previous triggers;
 * i.e if a SQL statement fires trigger T1, which in turn does something
 * that fires trigger t2, and if lastAutoincrementValue is called from
 * within t2, then autoincrement values genereated by t1 are visible to
 * it. By the same logic, if it is called from within t1, then it does not
 * see values inserted by t2.
 *
 * @see LanguageConnectionContext#lastAutoincrementValue
 */
public Long lastAutoincrementValue(String schemaName, String tableName, String columnName) {
    String aiKey = AutoincrementCounter.makeIdentity(schemaName, tableName, columnName);
    int size = triggerExecutionContexts.size();
    // System.out.println(" searching for " + aiKey);
    for (int i = size - 1; i >= 0; i--) {
        // first loop through triggers.
        TriggerExecutionContext itec = triggerExecutionContexts.get(i);
        Long value = itec.getAutoincrementValue(aiKey);
        if (value == null)
            continue;
        return value;
    }
    if (autoincrementHT == null)
        return null;
    return autoincrementHT.get(aiKey);
}
Also used : TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext)

Example 4 with TriggerExecutionContext

use of org.apache.derby.iapi.db.TriggerExecutionContext in project derby by apache.

the class TriggerGeneralTest method triggerFires.

public static String triggerFires(String string) throws Throwable {
    final TriggerExecutionContext tec = Factory.getTriggerExecutionContext();
    out.println("TRIGGER: " + "<" + string + "> on statement " + tec.getEventStatementText());
    printTriggerChanges();
    return "";
}
Also used : TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext)

Example 5 with TriggerExecutionContext

use of org.apache.derby.iapi.db.TriggerExecutionContext in project derby by apache.

the class TriggerNewTransitionRows method initializeResultSet.

private ResultSet initializeResultSet() throws SQLException {
    if (resultSet != null)
        resultSet.close();
    TriggerExecutionContext tec = Factory.getTriggerExecutionContext();
    if (tec == null) {
        throw new SQLException("There are no active triggers", "38000");
    }
    resultSet = tec.getNewRowSet();
    if (resultSet == null) {
        throw new SQLException("There is no new transition rows result set for this trigger", "38000");
    }
    return resultSet;
}
Also used : SQLException(java.sql.SQLException) TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext)

Aggregations

TriggerExecutionContext (org.apache.derby.iapi.db.TriggerExecutionContext)6 SQLException (java.sql.SQLException)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 EmbedConnection (org.apache.derby.impl.jdbc.EmbedConnection)1