Search in sources :

Example 6 with CursorActivation

use of org.apache.derby.iapi.sql.execute.CursorActivation in project derby by apache.

the class BaseActivation method checkPositionedStatement.

/**
 * Check that a positioned statement is executing against a cursor
 * from the same PreparedStatement (plan) that the positioned
 * statement was original compiled against.
 *
 * Only called from generated code for positioned UPDATE and DELETE
 * statements. See CurrentOfNode.
 *
 * @param cursorName Name of the cursor
 * @param psName Object name of the PreparedStatement.
 * @throws StandardException
 */
protected void checkPositionedStatement(String cursorName, String psName) throws StandardException {
    ExecPreparedStatement ps = getPreparedStatement();
    if (ps == null)
        return;
    CursorActivation cursorActivation = lcc.lookupCursorActivation(cursorName);
    if (cursorActivation != null) {
        // check we are compiled against the correct cursor
        if (!psName.equals(cursorActivation.getPreparedStatement().getObjectName())) {
            // our prepared statement is now invalid since there
            // exists another cursor with the same name but a different
            // statement.
            ps.makeInvalid(DependencyManager.CHANGED_CURSOR, lcc);
        }
    }
}
Also used : ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 7 with CursorActivation

use of org.apache.derby.iapi.sql.execute.CursorActivation in project derby by apache.

the class CurrentOfResultSet method getCursor.

// 
// class implementation
// 
/**
 *		Because the positioned operation only gets one location
 *		per execution, and the cursor could be completely different
 *		for each execution (closed and reopened, perhaps), we
 *		determine where caching the cursor could be applied.
 *		<p>
 *		When cached, we check if the cursor was closed'd,
 *		and if so, throw it out and
 *		see if there's one in the cache with our name.
 */
private void getCursor() throws StandardException {
    // need to look again if cursor was closed
    if (cursor != null) {
        if (cursor.isClosed()) {
            cursor = null;
            target = null;
        }
    }
    if (cursor == null) {
        LanguageConnectionContext lcc = getLanguageConnectionContext();
        CursorActivation cursorActivation = lcc.lookupCursorActivation(cursorName);
        if (cursorActivation != null) {
            cursor = cursorActivation.getCursorResultSet();
            target = cursorActivation.getTargetResultSet();
            /* beetle 3865: updateable cursor using index. 2 way communication between
				 * update activation and cursor activation. Cursor passes index scan to
				 * update and update passes heap conglom controller to cursor.
				 */
            activation.setForUpdateIndexScan(cursorActivation.getForUpdateIndexScan());
            if (cursorActivation.getHeapConglomerateController() != null)
                cursorActivation.getHeapConglomerateController().close();
            cursorActivation.setHeapConglomerateController(activation.getHeapConglomerateController());
        }
    }
    if (cursor == null || cursor.isClosed()) {
        throw StandardException.newException(SQLState.LANG_CURSOR_NOT_FOUND, cursorName);
    }
}
Also used : CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Aggregations

CursorActivation (org.apache.derby.iapi.sql.execute.CursorActivation)7 Activation (org.apache.derby.iapi.sql.Activation)5 ResultSet (org.apache.derby.iapi.sql.ResultSet)5 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)4 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)3 SQLWarning (java.sql.SQLWarning)2 ResultDescription (org.apache.derby.iapi.sql.ResultDescription)2 ExecCursorTableReference (org.apache.derby.iapi.sql.execute.ExecCursorTableReference)2 ExecPreparedStatement (org.apache.derby.iapi.sql.execute.ExecPreparedStatement)1