Search in sources :

Example 16 with StatementContext

use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.

the class RowCountResultSet method getNextRowCore.

/**
 * Return the requested values computed from the next row (if any)
 * <p>
 * @exception StandardException thrown on failure.
 * @exception StandardException ResultSetNotOpen thrown if not yet open.
 *
 * @return the next row in the result
 */
public ExecRow getNextRowCore() throws StandardException {
    if (isXplainOnlyMode())
        return null;
    ExecRow result = null;
    beginTime = getCurrentTimeMillis();
    if (virginal) {
        if (offsetMethod != null) {
            DataValueDescriptor offVal = (DataValueDescriptor) offsetMethod.invoke(activation);
            if (offVal.isNotNull().getBoolean()) {
                offset = offVal.getLong();
                if (offset < 0) {
                    throw StandardException.newException(SQLState.LANG_INVALID_ROW_COUNT_OFFSET, Long.toString(offset));
                } else {
                    offset = offVal.getLong();
                }
            } else {
                throw StandardException.newException(SQLState.LANG_ROW_COUNT_OFFSET_FIRST_IS_NULL, "OFFSET");
            }
        } else {
            // not given
            offset = 0;
        }
        if (fetchFirstMethod != null) {
            DataValueDescriptor fetchFirstVal = (DataValueDescriptor) fetchFirstMethod.invoke(activation);
            if (fetchFirstVal.isNotNull().getBoolean()) {
                fetchFirst = fetchFirstVal.getLong();
                // 
                if (hasJDBClimitClause && (fetchFirst == 0)) {
                    fetchFirst = Long.MAX_VALUE;
                }
                if (fetchFirst < 1) {
                    throw StandardException.newException(SQLState.LANG_INVALID_ROW_COUNT_FIRST, Long.toString(fetchFirst));
                }
            } else {
                throw StandardException.newException(SQLState.LANG_ROW_COUNT_OFFSET_FIRST_IS_NULL, "FETCH FIRST/NEXT");
            }
        }
        if (offset > 0) {
            // Only skip rows the first time around
            virginal = false;
            long offsetCtr = offset;
            do {
                result = source.getNextRowCore();
                offsetCtr--;
                if (result != null && offsetCtr >= 0) {
                    rowsFiltered++;
                } else {
                    break;
                }
            } while (true);
        } else {
            if (fetchFirstMethod != null && rowsFetched >= fetchFirst) {
                result = null;
            } else {
                result = source.getNextRowCore();
            }
        }
    } else {
        if (fetchFirstMethod != null && rowsFetched >= fetchFirst) {
            result = null;
        } else {
            result = source.getNextRowCore();
        }
    }
    if (result != null) {
        rowsFetched++;
        rowsSeen++;
    }
    setCurrentRow(result);
    if (runTimeStatsOn) {
        if (!isTopResultSet) {
            // This is simply for RunTimeStats.  We first need to get the
            // subquery tracking array via the StatementContext
            StatementContext sc = activation.getLanguageConnectionContext().getStatementContext();
            subqueryTrackingArray = sc.getSubqueryTrackingArray();
        }
        nextTime += getElapsedMillis(beginTime);
    }
    return result;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 17 with StatementContext

use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.

the class SavepointConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for CREATE TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    // Bug 4507 - savepoint not allowed inside trigger
    StatementContext stmtCtxt = lcc.getStatementContext();
    if (stmtCtxt != null && stmtCtxt.inTrigger())
        throw StandardException.newException(SQLState.NO_SAVEPOINT_IN_TRIGGER);
    if (savepointStatementType == 1) {
        // this is set savepoint
        if (// to enforce DB2 restriction which is savepoint name can't start with SYS
        savepointName.startsWith("SYS"))
            throw StandardException.newException(SQLState.INVALID_SCHEMA_SYS, "SYS");
        lcc.languageSetSavePoint(savepointName, savepointName);
    } else if (savepointStatementType == 2) {
        // this is rollback savepoint
        lcc.internalRollbackToSavepoint(savepointName, true, savepointName);
    } else {
        // this is release savepoint
        lcc.releaseSavePoint(savepointName, savepointName);
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 18 with StatementContext

use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.

the class NoRowsResultSetImpl method setup.

/**
 * Set up the result set for use. Should always be called from
 * <code>open()</code>.
 *
 * @exception StandardException thrown on error
 */
void setup() throws StandardException {
    isOpen = true;
    StatementContext sc = lcc.getStatementContext();
    sc.setTopResultSet(this, subqueryTrackingArray);
    // Pick up any materialized subqueries
    if (subqueryTrackingArray == null) {
        subqueryTrackingArray = sc.getSubqueryTrackingArray();
    }
}
Also used : StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 19 with StatementContext

use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.

the class GenericLanguageConnectionContext method setIsolationLevel.

/**
 * @see LanguageConnectionContext#setIsolationLevel
 */
public void setIsolationLevel(int isolationLevel) throws StandardException {
    StatementContext stmtCtxt = getStatementContext();
    if (stmtCtxt != null && stmtCtxt.inTrigger())
        throw StandardException.newException(SQLState.LANG_NO_XACT_IN_TRIGGER, getTriggerExecutionContext().toString());
    // shouldn't rely on transaction state.
    if (this.isolationLevel != isolationLevel) {
        if (!verifyAllHeldResultSetsAreClosed()) {
            throw StandardException.newException(SQLState.LANG_CANT_CHANGE_ISOLATION_HOLD_CURSOR);
        }
    }
    /* Commit and set to new isolation level.
         * NOTE: We commit first in case there's some kind
         * of error, like can't commit within a server side jdbc call.
         */
    TransactionController tc = getTransactionExecute();
    if (!tc.isIdle()) {
        // transaction.
        if (tc.isGlobal())
            throw StandardException.newException(SQLState.LANG_NO_SET_TRAN_ISO_IN_GLOBAL_CONNECTION);
        userCommit();
    }
    this.isolationLevel = isolationLevel;
    this.isolationLevelExplicitlySet = true;
    this.isolationLevelSetUsingSQLorJDBC = true;
}
Also used : TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 20 with StatementContext

use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.

the class GenericLanguageConnectionContext method doCommit.

/**
 * This is where the work on internalCommit(), userCOmmit() and
 * internalCommitNoSync() actually takes place.
 * <p>
 * When a commit happens, the language connection context
 * will close all open activations/cursors and commit the
 * Store transaction.
 * <p>
 * REVISIT: we talked about having a LanguageTransactionContext,
 * but since store transaction management is currently in flux
 * and our context might want to delegate to that context,
 * for now all commit/rollback actions are handled directly by
 * the language connection context.
 * REVISIT: this may need additional alterations when
 * RELEASE SAVEPOINT/ROLLBACK TO SAVEPOINT show up.
 * <P>
 * Since the access manager's own context takes care of its own
 * resources on commit, and the transaction stays open, there is
 * nothing that this context has to do with the transaction controller.
 * <p>
 * Also, tell the data dictionary that the transaction is finished,
 * if necessary (that is, if the data dictionary was put into
 * DDL mode in this transaction.
 *
 * @param   commitStore true if we should commit the Store transaction
 * @param   sync        true means do a synchronized commit,
 *                      false means do an unsynchronized commit
 * @param   commitflag  if this is an unsynchronized commit, the flags to
 *                      pass to commitNoSync in the store's
 *                      TransactionController.  If this is a synchronized
 *                      commit, this flag is overloaded for xacommit.
 * @param   requestedByUser    False iff the commit is for internal use and
 *                      we should ignore the check to prevent commits
 *                      in an atomic statement.
 *
 * @exception StandardException     Thrown on error
 */
protected void doCommit(boolean commitStore, boolean sync, int commitflag, boolean requestedByUser) throws StandardException {
    StatementContext statementContext = getStatementContext();
    if (requestedByUser && (statementContext != null) && statementContext.inUse() && statementContext.isAtomic()) {
        throw StandardException.newException(SQLState.LANG_NO_COMMIT_IN_NESTED_CONNECTION);
    }
    checkIntegrity();
    // Log commit to error log, if appropriate
    if (logStatementText) {
        if (istream == null) {
            istream = Monitor.getStream();
        }
        String xactId = tran.getTransactionIdString();
        istream.printlnWithHeader(LanguageConnectionContext.xidStr + xactId + "), " + LanguageConnectionContext.lccStr + instanceNumber + "), " + LanguageConnectionContext.dbnameStr + dbname + "), " + LanguageConnectionContext.drdaStr + drdaID + "), Committing");
    }
    endTransactionActivationHandling(false);
    // Do clean up work required for temporary tables at commit time.
    if (allDeclaredGlobalTempTables != null) {
        tempTablesAndCommit(commitflag != NON_XA);
    }
    // reset the current savepoint level for the connection to 0 at the end
    // of commit work for temp tables
    currentSavepointLevel = 0;
    // which could be rolled back in case of a system crash.
    if (sync) {
        finishDDTransaction();
    }
    // before a commit.
    if (SanityManager.DEBUG) {
        if (readOnlyNestedTransaction != null) {
            SanityManager.THROWASSERT("Nested transaction active!");
        }
    }
    // now commit the Store transaction
    TransactionController tc = getTransactionExecute();
    if (tc != null && commitStore) {
        if (sync) {
            if (commitflag == NON_XA) {
                // regular commit
                tc.commit();
            } else {
                if (SanityManager.DEBUG)
                    SanityManager.ASSERT(commitflag == XA_ONE_PHASE || commitflag == XA_TWO_PHASE, "invalid commit flag");
                ((XATransactionController) tc).xa_commit(commitflag == XA_ONE_PHASE);
            }
        } else {
            tc.commitNoSync(commitflag);
        }
        // reset the savepoints to the new
        // location, since any outer nesting
        // levels expect there to be a savepoint
        resetSavepoints();
        // Do post commit XA temp table cleanup if necessary.
        if ((allDeclaredGlobalTempTables != null) && (commitflag != NON_XA)) {
            tempTablesXApostCommit();
        }
    }
}
Also used : XATransactionController(org.apache.derby.iapi.store.access.XATransactionController) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Aggregations

StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)26 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)9 Activation (org.apache.derby.iapi.sql.Activation)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)5 ResultSet (org.apache.derby.iapi.sql.ResultSet)4 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)4 SQLWarning (java.sql.SQLWarning)3 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)3 SQLSessionContext (org.apache.derby.iapi.sql.conn.SQLSessionContext)3 CursorActivation (org.apache.derby.iapi.sql.execute.CursorActivation)3 TransactionController (org.apache.derby.iapi.store.access.TransactionController)3 XATransactionController (org.apache.derby.iapi.store.access.XATransactionController)3 StandardException (org.apache.derby.shared.common.error.StandardException)3 DataTruncation (java.sql.DataTruncation)2 GeneratedClass (org.apache.derby.iapi.services.loader.GeneratedClass)2 ResultDescription (org.apache.derby.iapi.sql.ResultDescription)2 ExecCursorTableReference (org.apache.derby.iapi.sql.execute.ExecCursorTableReference)2 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 UUID (org.apache.derby.catalog.UUID)1