synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
final ExecRow newRow;
try {
/* Push and pop a StatementContext around a next call
* so that the ResultSet will get correctly closed down
* on an error.
* (Cache the LanguageConnectionContext)
*/
StatementContext statementContext =
lcc.pushStatementContext(isAtomic,
concurrencyOfThisResultSet==java.sql.ResultSet.CONCUR_READ_ONLY,
getSQLText(),
getParameterValueSet(),
false, timeoutMillis);
switch (position)
{
case BEFOREFIRST:
newRow = theResults.setBeforeFirstRow();
break;
case FIRST:
newRow = theResults.getFirstRow();
break;
case NEXT:
newRow = theResults.getNextRow();
break;
case LAST:
newRow = theResults.getLastRow();
break;
case AFTERLAST:
newRow = theResults.setAfterLastRow();
break;
case PREVIOUS:
newRow = theResults.getPreviousRow();
break;
case ABSOLUTE:
newRow = theResults.getAbsoluteRow(row);
break;
case RELATIVE:
newRow = theResults.getRelativeRow(row);
break;
default:
newRow = null;
if (SanityManager.DEBUG)
{
SanityManager.THROWASSERT(
"Unexpected value for position - " + position);
}
}
lcc.popStatementContext(statementContext, null);
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (Throwable t) {
/*
* Need to close the result set here because the error might
* cause us to lose the current connection if this is an XA
* connection and we won't be able to do the close later
*/
throw closeOnTransactionError(t);
}
SQLWarning w = theResults.getWarnings();
if (w != null) {
if (topWarning == null)
topWarning = w;
else
topWarning.setNextWarning(w);
}
boolean onRow = (currentRow = newRow) != null;
//if (onRow && !(currentRow instanceof org.apache.derby.impl.sql.execute.ValueRow))
// System.out.println(currentRow.getClass());
// The ResultSet may implicitly close when when the ResultSet type
// is TYPE_FORWARD_ONLY and the next method of ResultSet returns
// false. This will cause a commit if autocommit = true.
if (!onRow && (position == NEXT)) {
// In case of resultset for MetaData, we will only commit
// if we are the only statement currently opened for this
// connection; otherwise we don't want to affect other
// resultSet's by committing the MetaData one.
// There is no internal xact (xact isolation) for MetaData type
// of resultSet; therefore committing (to release locks) would end
// up committing all the other resultSet for this connection.
//
// We do synchronize on the connection, therefore Activation count
// should be valid and protected.
//
//LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
if (forMetaData && (lcc.getActivationCount() > 1)) {
// we do not want to commit here as there seems to be other
// statements/resultSets currently opened for this connection.
} else if (owningStmt != null &&
owningStmt.getResultSetType() == TYPE_FORWARD_ONLY) {
// allow the satement to commit if required.