use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.
the class Result method newResult.
public static Result newResult(int type) {
RowSetNavigator navigator = null;
Result result = null;
switch(type) {
case ResultConstants.CALL_RESPONSE:
case ResultConstants.EXECUTE:
navigator = new RowSetNavigatorClient(1);
break;
case ResultConstants.UPDATE_RESULT:
navigator = new RowSetNavigatorClient(1);
break;
case ResultConstants.BATCHEXECUTE:
case ResultConstants.BATCHEXECDIRECT:
navigator = new RowSetNavigatorClient(4);
break;
case ResultConstants.SETSESSIONATTR:
case ResultConstants.PARAM_METADATA:
navigator = new RowSetNavigatorClient(1);
break;
case ResultConstants.BATCHEXECRESPONSE:
navigator = new RowSetNavigatorClient(4);
break;
case ResultConstants.DATA:
case ResultConstants.DATAHEAD:
case ResultConstants.DATAROWS:
break;
case ResultConstants.LARGE_OBJECT_OP:
throw Error.runtimeError(ErrorCode.U_S0500, "Result");
default:
}
result = new Result();
result.mode = (byte) type;
result.navigator = navigator;
return result;
}
use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.
the class LobManager method getNewLobID.
//
private long getNewLobID(Session session) {
Result result = getNextLobId.execute(session);
if (result.isError()) {
return 0;
}
RowSetNavigator navigator = result.getNavigator();
boolean next = navigator.next();
if (!next) {
navigator.close();
return 0;
}
Object[] data = navigator.getCurrent();
return ((Long) data[0]).longValue();
}
use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.
the class StatementDML method executeMergeStatement.
/**
* Executes a MERGE statement. It is assumed that the argument
* is of the correct type.
*
* @return Result object
*/
Result executeMergeStatement(Session session) {
Result resultOut = null;
RowSetNavigator generatedNavigator = null;
PersistentStore store = session.sessionData.getRowStore(baseTable);
if (generatedIndexes != null) {
resultOut = Result.newUpdateCountResult(generatedResultMetaData, 0);
generatedNavigator = resultOut.getChainedResult().getNavigator();
}
int count = 0;
// data generated for non-matching rows
RowSetNavigatorClient newData = new RowSetNavigatorClient(8);
// rowset for update operation
HashMappedList updateRowSet = new HashMappedList();
RangeVariable[] joinRangeIterators = targetRangeVariables;
// populate insert and update lists
RangeIterator[] rangeIterators = new RangeIterator[joinRangeIterators.length];
for (int i = 0; i < joinRangeIterators.length; i++) {
rangeIterators[i] = joinRangeIterators[i].getIterator(session);
}
for (int currentIndex = 0; 0 <= currentIndex; ) {
RangeIterator it = rangeIterators[currentIndex];
boolean beforeFirst = it.isBeforeFirst();
if (it.next()) {
if (currentIndex < joinRangeIterators.length - 1) {
currentIndex++;
continue;
}
} else {
if (currentIndex == 1 && beforeFirst) {
Object[] data = getMergeInsertData(session);
if (data != null) {
newData.add(data);
}
}
it.reset();
currentIndex--;
continue;
}
// row matches!
if (updateExpressions != null) {
// this is always the second iterator
Row row = it.getCurrentRow();
Object[] data = getUpdatedData(session, baseTable, updateColumnMap, updateExpressions, baseTable.getColumnTypes(), row.getData());
updateRowSet.add(row, data);
}
}
// update any matched rows
if (updateRowSet.size() > 0) {
count = update(session, baseTable, updateRowSet);
}
// insert any non-matched rows
newData.beforeFirst();
while (newData.hasNext()) {
Object[] data = newData.getNext();
baseTable.insertRow(session, store, data);
if (generatedNavigator != null) {
Object[] generatedValues = getGeneratedColumns(data);
generatedNavigator.add(generatedValues);
}
}
baseTable.fireAfterTriggers(session, Trigger.INSERT_AFTER, newData);
count += newData.getSize();
if (resultOut == null) {
return Result.getUpdateCountResult(count);
} else {
resultOut.setUpdateCount(count);
return resultOut;
}
}
use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.
the class Session method executeDirectBatchStatement.
private Result executeDirectBatchStatement(Result cmd) {
int[] updateCounts;
int count;
count = 0;
RowSetNavigator nav = cmd.initialiseNavigator();
updateCounts = new int[nav.getSize()];
Result error = null;
isBatch = true;
while (nav.hasNext()) {
Result in;
Object[] data = (Object[]) nav.getNext();
String sql = (String) data[0];
try {
in = executeDirectStatement(sql);
} catch (StackOverflowError caught) {
// in a higher-level caller.
throw caught;
} catch (Throwable t) {
in = Result.newErrorResult(t);
// if (t instanceof OutOfMemoryError) {
// System.gc();
// }
// "in" alread equals "err"
// maybe test for OOME and do a gc() ?
// t.printStackTrace();
}
if (in.isUpdateCount()) {
updateCounts[count++] = in.getUpdateCount();
} else if (in.isData()) {
// FIXME: we don't have what it takes yet
// to differentiate between things like
// stored procedure calls to methods with
// void return type and select statements with
// a single row/column containg null
updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;
} else if (in.isError()) {
updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);
error = in;
break;
} else {
throw Error.runtimeError(ErrorCode.U_S0500, "Session");
}
}
isBatch = false;
sessionData.updateLobUsageForBatch();
return Result.newBatchedExecuteResponse(updateCounts, null, error);
}
use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.
the class Session method executeCompiledBatchStatement.
private Result executeCompiledBatchStatement(Result cmd) {
long csid;
Statement cs;
int[] updateCounts;
int count;
csid = cmd.getStatementID();
cs = database.compiledStatementManager.getStatement(this, csid);
if (cs == null) {
// invalid sql has been removed already
return Result.newErrorResult(Error.error(ErrorCode.X_07501));
}
count = 0;
RowSetNavigator nav = cmd.initialiseNavigator();
updateCounts = new int[nav.getSize()];
Result generatedResult = null;
if (cs.hasGeneratedColumns()) {
generatedResult = Result.newDataResult(cs.generatedResultMetaData());
}
Result error = null;
isBatch = true;
while (nav.hasNext()) {
Object[] pvals = (Object[]) nav.getNext();
Result in = executeCompiledStatement(cs, pvals);
// esultConstants.EXECUTE_FAILED is encountered in the result
if (in.isUpdateCount()) {
if (cs.hasGeneratedColumns()) {
Object generatedRow = in.getNavigator().getNext();
generatedResult.getNavigator().add(generatedRow);
}
updateCounts[count++] = in.getUpdateCount();
} else if (in.isData()) {
// FIXME: we don't have what it takes yet
// to differentiate between things like
// stored procedure calls to methods with
// void return type and select statements with
// a single row/column containg null
updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;
} else if (in.isError()) {
updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);
error = in;
break;
} else {
throw Error.runtimeError(ErrorCode.U_S0500, "Session");
}
}
isBatch = false;
sessionData.updateLobUsageForBatch();
return Result.newBatchedExecuteResponse(updateCounts, generatedResult, error);
}
Aggregations