use of org.apache.derby.iapi.sql.execute.CursorResultSet in project derby by apache.
the class UpdateResultSet method foundRow.
public static boolean foundRow(ExecRow checkRow, int[] colsToCheck, TemporaryRowHolderImpl rowHolder) throws StandardException {
ExecRow scanRow;
boolean foundMatch = false;
Object[] checkRowArray = checkRow.getRowArray();
DataValueDescriptor checkCol;
DataValueDescriptor scanCol;
CursorResultSet rs = rowHolder.getResultSet();
try {
/*
** For each inserted row
*/
rs.open();
while ((scanRow = rs.getNextRow()) != null) {
Object[] scanRowArray = scanRow.getRowArray();
int i;
for (i = 0; i < colsToCheck.length; i++) {
checkCol = (DataValueDescriptor) checkRowArray[colsToCheck[i] - 1];
scanCol = (DataValueDescriptor) scanRowArray[colsToCheck[i] - 1];
BooleanDataValue result = checkCol.equals(scanCol, // result
checkCol);
if (!result.getBoolean()) {
break;
}
}
if (i == colsToCheck.length) {
foundMatch = true;
break;
}
}
} finally {
rs.close();
}
return foundMatch;
}
use of org.apache.derby.iapi.sql.execute.CursorResultSet in project derby by apache.
the class UpdateVTIResultSet method openCore.
/**
* @exception StandardException Standard Derby error policy
*/
protected void openCore() throws StandardException {
int rowLocationColumn = -1;
boolean firstRow = true;
rs = activation.getTargetVTI();
ExecRow row = getNextRowCore(sourceResultSet);
if (null != row)
rowLocationColumn = row.nColumns();
/* The source does not know whether or not we are doing a
* deferred mode insert. 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 insert).
*/
if (constants.deferred) {
activation.clearIndexScanInfo();
}
if (null == rowHolder && constants.deferred) {
Properties properties = new Properties();
/*
** If deferred we save a copy of the entire row.
*/
rowHolder = new TemporaryRowHolderImpl(activation, properties, resultDescription);
}
try {
while (row != null) {
if (constants.deferred) {
// Add the row number to the row.
if (firstRow) {
row.getColumn(rowLocationColumn).setValue(rs.getRow());
firstRow = false;
} else {
DataValueDescriptor rowLocation = row.cloneColumn(rowLocationColumn);
rowLocation.setValue(rs.getRow());
row.setColumn(rowLocationColumn, rowLocation);
}
rowHolder.insert(row);
} else
updateVTI(rs, row);
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 it's a deferred update, scan the temporary conglomerate and
** insert the rows into the VTI using rowChanger.
*/
if (constants.deferred) {
CursorResultSet tempRS = rowHolder.getResultSet();
try {
tempRS.open();
while ((row = tempRS.getNextRow()) != null) {
int rowNumber = row.getColumn(rowLocationColumn).getInt();
rs.absolute(rowNumber);
updateVTI(rs, row);
}
} 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.CursorResultSet in project derby by apache.
the class MatchingClauseConstantAction method executeConstantAction.
public void executeConstantAction(Activation activation, TemporaryRowHolderImpl thenRows) throws StandardException {
// nothing to do if no rows qualified
if (thenRows == null) {
return;
}
CursorResultSet sourceRS = thenRows.getResultSet();
GeneratedMethod actionGM = ((BaseActivation) activation).getMethod(_actionMethodName);
//
try {
activation.pushConstantAction(_thenAction);
try {
//
// Poke the temporary table into the variable which will be pushed as
// an argument to the INSERT/UPDATE/DELETE action.
//
Field resultSetField = activation.getClass().getField(_resultSetFieldName);
resultSetField.set(activation, sourceRS);
Activation cursorActivation = sourceRS.getActivation();
//
// Now execute the generated method which creates an InsertResultSet,
// UpdateResultSet, or DeleteResultSet.
//
Method actionMethod = activation.getClass().getMethod(_actionMethodName);
_actionRS = (ResultSet) actionMethod.invoke(activation, null);
} catch (Exception e) {
throw StandardException.plainWrapException(e);
}
// this is where the INSERT/UPDATE/DELETE is processed
_actionRS.open();
} finally {
activation.popConstantAction();
}
}
Aggregations