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;
}
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);
}
}
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();
}
}
use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.
the class HashTableResultSet method getNextRowCore.
/**
* Return the requested values computed
* from the next row (if any) for which
* the restriction evaluates to true.
* <p>
* restriction and projection parameters
* are evaluated for each row.
*
* @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;
DataValueDescriptor[] columns = null;
beginTime = getCurrentTimeMillis();
if (isOpen) {
/* We use a do/while loop to ensure that we continue down
* the duplicate chain, if one exists, until we find a
* row that matches on all probe predicates (or the
* duplicate chain is exhausted.)
*/
do {
if (firstNext) {
firstNext = false;
/* Hash key could be either a single column or multiple
* columns. If a single column, then it is the datavalue
* wrapper, otherwise it is a KeyHasher.
*/
Object hashEntry;
if (keyColumns.length == 1) {
hashEntry = ht.get(nextQualifiers[0][0].getOrderable());
} else {
KeyHasher mh = new KeyHasher(keyColumns.length);
for (int index = 0; index < keyColumns.length; index++) {
// RESOLVE (mikem) - will need to change when we
// support OR's in qualifiers.
mh.setObject(index, nextQualifiers[0][index].getOrderable());
}
hashEntry = ht.get(mh);
}
if (hashEntry instanceof List) {
entryVector = (List) hashEntry;
entryVectorSize = entryVector.size();
columns = (DataValueDescriptor[]) entryVector.get(0);
} else {
entryVector = null;
entryVectorSize = 0;
columns = (DataValueDescriptor[]) hashEntry;
}
} else if (numFetchedOnNext < entryVectorSize) {
// We are walking a list and there are more rows left.
columns = (DataValueDescriptor[]) entryVector.get(numFetchedOnNext);
}
if (columns != null) {
if (SanityManager.DEBUG) {
// Columns is really a Storable[]
for (int i = 0; i < columns.length; i++) {
if (!(columns[i] instanceof Storable)) {
SanityManager.THROWASSERT("columns[" + i + "] expected to be Storable, not " + columns[i].getClass().getName());
}
}
}
// See if the entry satisfies all of the other qualifiers
boolean qualifies = true;
if (SanityManager.DEBUG) {
// we don't support 2 d qualifiers yet.
SanityManager.ASSERT(nextQualifiers.length == 1);
}
for (int index = 0; index < nextQualifiers[0].length; index++) {
Qualifier q = nextQualifiers[0][index];
qualifies = columns[q.getColumnId()].compare(q.getOperator(), q.getOrderable(), q.getOrderedNulls(), q.getUnknownRV());
if (q.negateCompareResult()) {
qualifies = !(qualifies);
}
// Stop if any predicate fails
if (!qualifies) {
break;
}
}
if (qualifies) {
for (int index = 0; index < columns.length; index++) {
nextCandidate.setColumn(index + 1, columns[index]);
}
result = doProjection(nextCandidate);
} else {
result = null;
}
numFetchedOnNext++;
} else {
result = null;
}
} while (result == null && numFetchedOnNext < entryVectorSize);
}
setCurrentRow(result);
nextTime += getElapsedMillis(beginTime);
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;
}
use of org.apache.derby.iapi.sql.conn.StatementContext in project derby by apache.
the class ProjectRestrictResultSet method getNextRowCore.
/**
* Return the requested values computed
* from the next row (if any) for which
* the restriction evaluates to true.
* <p>
* restriction and projection parameters
* are evaluated for each row.
*
* @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 candidateRow = null;
ExecRow result = null;
boolean restrict = false;
DataValueDescriptor restrictBoolean;
long beginRT = 0;
/* Return null if open was short circuited by false constant expression */
if (shortCircuitOpen) {
return result;
}
beginTime = getCurrentTimeMillis();
do {
if (validatingCheckConstraint) {
candidateRow = null;
while (rowLocations.hasMoreElements() && candidateRow == null) {
DataValueDescriptor[] row = (DataValueDescriptor[]) rowLocations.nextElement();
RowLocation rl = (RowLocation) ((SQLRef) row[0]).getObject();
((ValidateCheckConstraintResultSet) source).positionScanAtRowLocation(rl);
candidateRow = source.getNextRowCore();
// if null (deleted), we move to next
}
} else {
candidateRow = source.getNextRowCore();
}
if (candidateRow != null) {
beginRT = getCurrentTimeMillis();
/* If restriction is null, then all rows qualify */
if (restriction == null) {
restrict = true;
} else {
setCurrentRow(candidateRow);
restrictBoolean = (DataValueDescriptor) restriction.invoke(activation);
restrictionTime += getElapsedMillis(beginRT);
// if the result is null, we make it false --
// so the row won't be returned.
restrict = ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
if (!restrict) {
rowsFiltered++;
}
}
/* Update the run time statistics */
rowsSeen++;
}
} while ((candidateRow != null) && (!restrict));
if (candidateRow != null) {
beginRT = getCurrentTimeMillis();
result = doProjection(candidateRow);
projectionTime += getElapsedMillis(beginRT);
} else /* Clear the current row, if null */
{
clearCurrentRow();
}
currentRow = 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;
}
Aggregations