use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class NoRowsResultSetImpl method evaluateGenerationClauses.
/**
* Compute the generation clauses on the current row in order to fill in
* computed columns.
*
* @param generationClauses the generated method which evaluates generation clauses
* @param activation the thread-specific instance of the generated class
* @param source the tuple stream driving this INSERT/UPDATE
* @param newRow the base row being stuffed
* @param isUpdate true if this is an UPDATE. false otherwise.
*/
public void evaluateGenerationClauses(GeneratedMethod generationClauses, Activation activation, NoPutResultSet source, ExecRow newRow, boolean isUpdate) throws StandardException {
if (generationClauses != null) {
ExecRow oldRow = (ExecRow) activation.getCurrentRow(source.resultSetNumber());
//
try {
source.setCurrentRow(newRow);
activation.setCurrentRow(newRow, source.resultSetNumber());
generationClauses.invoke(activation);
//
if (firstColumn < 0) {
firstColumn = NormalizeResultSet.computeStartColumn(isUpdate, activation.getResultDescription());
}
if (generatedColumnPositions == null) {
setupGeneratedColumns(activation, (ValueRow) newRow);
}
ResultDescription resultDescription = activation.getResultDescription();
int count = generatedColumnPositions.length;
for (int i = 0; i < count; i++) {
int position = generatedColumnPositions[i];
DataValueDescriptor normalizedColumn = NormalizeResultSet.normalizeColumn(resultDescription.getColumnDescriptor(position).getType(), newRow, position, normalizedGeneratedValues[i], resultDescription);
newRow.setColumn(position, normalizedColumn);
}
} finally {
//
if (oldRow == null) {
source.clearCurrentRow();
} else {
source.setCurrentRow(oldRow);
}
}
}
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DeleteResultSet method deleteDeferredRows.
// delete the rows that in case deferred case and
// during cascade delete (All deletes are deferred during cascade action)
void deleteDeferredRows() throws StandardException {
DataValueDescriptor rlColumn;
RowLocation baseRowLocation;
ExecRow defRLRow;
deferredBaseCC = tc.openCompiledConglomerate(false, (TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_SECONDARY_LOCKED), lockMode, TransactionController.ISOLATION_SERIALIZABLE, constants.heapSCOCI, heapDCOCI);
CursorResultSet rs = rowHolder.getResultSet();
try {
/*
** We need to do a fetch doing a partial row
** read. We need to shift our 1-based bit
** set to a zero based bit set like the store
** expects.
*/
FormatableBitSet readBitSet = RowUtil.shift(baseRowReadList, 1);
rs.open();
while ((defRLRow = rs.getNextRow()) != null) {
rlColumn = defRLRow.getColumn(rlColumnNumber);
baseRowLocation = (RowLocation) (rlColumn).getObject();
/* Get the base row at the given RowLocation */
boolean row_exists = deferredBaseCC.fetch(baseRowLocation, deferredSparseRow.getRowArray(), readBitSet);
// the rows before the dependent result get a chance to delete
if (cascadeDelete && !row_exists)
continue;
if (SanityManager.DEBUG) {
if (!row_exists) {
SanityManager.THROWASSERT("could not find row " + baseRowLocation);
}
}
rc.deleteRow(deferredBaseRow, baseRowLocation);
source.markRowAsDeleted();
}
} finally {
rs.close();
}
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DeleteVTIResultSet method openCore.
/**
* @exception StandardException Standard Derby error policy
*/
protected void openCore() throws StandardException {
ExecRow row = getNextRowCore(sourceResultSet);
if (row != null) {
rs = activation.getTargetVTI();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(rs != null, "rs expected to be non-null");
}
}
/* The source does not know whether or not we are doing a
* deferred mode delete. If we are, then we must clear the
* index scan info from the activation so that the row changer
* does not re-use that information (which won't be valid for
* a deferred mode delete).
*/
if (constants.deferred) {
activation.clearIndexScanInfo();
if (null == rowHolder)
rowHolder = new TemporaryRowHolderImpl(activation, new Properties(), (ResultDescription) null);
}
try {
while (row != null) {
if (!constants.deferred)
rs.deleteRow();
else {
ExecRow rowId = new ValueRow(1);
rowId.setColumn(1, new SQLInteger(rs.getRow()));
rowHolder.insert(rowId);
}
rowCount++;
// No need to do a next on a single row source
if (constants.singleRowSource) {
row = null;
} else {
row = getNextRowCore(sourceResultSet);
}
}
} catch (StandardException se) {
throw se;
} catch (Throwable t) {
throw StandardException.unexpectedUserException(t);
}
if (constants.deferred) {
CursorResultSet tempRS = rowHolder.getResultSet();
try {
ExecRow deferredRowBuffer = null;
tempRS.open();
while ((deferredRowBuffer = tempRS.getNextRow()) != null) {
int rowNumber = deferredRowBuffer.getColumn(1).getInt();
rs.absolute(rowNumber);
rs.deleteRow();
}
} catch (Throwable t) {
throw StandardException.unexpectedUserException(t);
} finally {
sourceResultSet.clearCurrentRow();
tempRS.close();
}
}
if (rowHolder != null) {
rowHolder.close();
// rowHolder kept across opens
}
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DependentResultSet method getNextParentRow.
// this function will return the rows from the parent result sets
private ExecRow getNextParentRow() throws StandardException {
ExecRow cRow;
TemporaryRowHolder rowHolder;
if (sourceOpened[sArrayIndex] == 0) {
rowHolder = sourceRowHolders[sArrayIndex];
source = (TemporaryRowHolderResultSet) rowHolder.getResultSet();
// open the cursor result set
source.open();
sourceOpened[sArrayIndex] = -1;
sourceResultSets[sArrayIndex] = source;
}
if (sourceOpened[sArrayIndex] == 1) {
source = sourceResultSets[sArrayIndex];
source.reStartScan(sourceRowHolders[sArrayIndex].getTemporaryConglomId(), sourceRowHolders[sArrayIndex].getPositionIndexConglomId());
sourceOpened[sArrayIndex] = -1;
}
if (sVector.size() > sourceRowHolders.length) {
addNewSources();
}
cRow = source.getNextRow();
while (cRow == null && (sArrayIndex + 1) < sourceRowHolders.length) {
// opening the next source;
sArrayIndex++;
if (sourceOpened[sArrayIndex] == 0) {
rowHolder = sourceRowHolders[sArrayIndex];
source = (TemporaryRowHolderResultSet) rowHolder.getResultSet();
// open the cursor result set
source.open();
sourceOpened[sArrayIndex] = -1;
sourceResultSets[sArrayIndex] = source;
}
if (sourceOpened[sArrayIndex] == 1) {
source = sourceResultSets[sArrayIndex];
source.reStartScan(sourceRowHolders[sArrayIndex].getTemporaryConglomId(), sourceRowHolders[sArrayIndex].getPositionIndexConglomId());
sourceOpened[sArrayIndex] = -1;
}
cRow = source.getNextRow();
}
if (cRow == null) {
// which means no source has any more currently rows.
sArrayIndex = 0;
// mark all the sources to restartScan.
for (int i = 0; i < sourceOpened.length; i++) sourceOpened[i] = 1;
}
return cRow;
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class DependentResultSet method getNextRowCore.
// this function will return an index row on dependent table
public ExecRow getNextRowCore() throws StandardException {
if (isXplainOnlyMode())
return null;
beginTime = getCurrentTimeMillis();
if (searchRow == null) {
// we are searching for a row first time
if ((searchRow = getNextParentRow()) != null)
openIndexScan(searchRow);
}
ExecRow currentIndexRow = null;
while (searchRow != null) {
// get if the current search row has more
// than one row in the dependent tables
currentIndexRow = fetchIndexRow();
if (currentIndexRow != null)
break;
if ((searchRow = getNextParentRow()) != null)
openIndexScan(searchRow);
}
nextTime += getElapsedMillis(beginTime);
if (currentIndexRow != null) {
rowsSeen++;
return fetchBaseRow();
} else {
return currentIndexRow;
}
}
Aggregations