use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class StatementProcedure method getProcedureResult.
Result getProcedureResult(Session session) {
Object[] data = ValuePool.emptyObjectArray;
if (arguments.length > 0) {
data = new Object[arguments.length];
}
for (int i = 0; i < arguments.length; i++) {
Expression e = arguments[i];
if (e != null) {
data[i] = e.getValue(session, e.dataType);
}
}
int variableCount = procedure.getVariableCount();
session.sessionContext.push();
session.sessionContext.routineArguments = data;
session.sessionContext.routineVariables = ValuePool.emptyObjectArray;
if (variableCount > 0) {
session.sessionContext.routineVariables = new Object[variableCount];
}
// fixed? temp until assignment of dynamicArguments in materialiseSubqueries is fixed
// Object[] args = session.sessionContext.dynamicArguments;
Result result = procedure.statement.execute(session);
// session.sessionContext.dynamicArguments = args;
if (!result.isError()) {
result = Result.updateZeroResult;
}
Object[] callArguments = session.sessionContext.routineArguments;
session.sessionContext.pop();
if (result.isError()) {
return result;
}
boolean returnParams = false;
for (int i = 0; i < procedure.getParameterCount(); i++) {
ColumnSchema param = procedure.getParameter(i);
int mode = param.getParameterMode();
if (mode != SchemaObject.ParameterModes.PARAM_IN) {
if (this.arguments[i].isParam) {
int paramIndex = arguments[i].parameterIndex;
session.sessionContext.dynamicArguments[paramIndex] = callArguments[i];
returnParams = true;
} else {
int varIndex = arguments[i].getColumnIndex();
session.sessionContext.routineVariables[varIndex] = callArguments[i];
}
}
}
if (returnParams) {
result = Result.newCallResponse(this.getParametersMetaData().getParameterTypes(), this.id, session.sessionContext.dynamicArguments);
}
return result;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class JDBCStatementBase method performPostExecute.
/**
* processes chained warnings and any generated columns result set
*/
void performPostExecute() throws SQLException {
resultOut.clearLobResults();
generatedResult = null;
if (resultIn == null) {
return;
}
Result current = resultIn;
while (current.getChainedResult() != null) {
current = current.getUnlinkChainedResult();
if (current.getType() == ResultConstants.WARNING) {
SQLWarning w = Util.sqlWarning(current);
if (rootWarning == null) {
rootWarning = w;
} else {
rootWarning.setNextWarning(w);
}
} else if (current.getType() == ResultConstants.ERROR) {
errorResult = current;
} else if (current.getType() == ResultConstants.DATA) {
generatedResult = current;
}
}
if (resultIn.isData()) {
currentResultSet = new JDBCResultSet(connection.sessionProxy, this, resultIn, resultIn.metaData, connection.connProperties);
}
}
use of org.hsqldb_voltpatches.result.Result 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.result.Result in project voltdb by VoltDB.
the class StatementDMQL method execute.
@Override
public Result execute(Session session) {
Result result = getAccessRightsResult(session);
if (result != null) {
return result;
}
if (this.isExplain) {
return Result.newSingleColumnStringResult("OPERATION", describe(session));
}
if (session.sessionContext.dynamicArguments.length != parameters.length) {
// return Result.newErrorResult(Error.error(ErrorCode.X_42575));
}
try {
materializeSubQueries(session);
result = getResult(session);
} catch (Throwable t) {
String commandString = sql;
if (session.database.getProperties().getErrorLevel() == HsqlDatabaseProperties.NO_MESSAGE) {
commandString = null;
}
result = Result.newErrorResult(t, commandString);
result.getException().setStatementType(group, type);
}
session.sessionContext.clearStructures(this);
return result;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class Session method executeCompiledStatement.
public Result executeCompiledStatement(Statement cs, Object[] pvals) {
Result r;
if (abortTransaction) {
// tempActionHistory.add("beginAction aborts" + actionTimestamp);
rollback(false);
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
currentStatement = cs;
if (cs.isAutoCommitStatement()) {
try {
if (isReadOnly()) {
throw Error.error(ErrorCode.X_25006);
}
/** @todo - special autocommit for backward compatibility */
commit(false);
} catch (HsqlException e) {
}
}
if (!cs.isTransactionStatement()) {
r = cs.execute(this);
currentStatement = null;
return r;
}
while (true) {
beginAction(cs);
if (abortTransaction) {
rollback(false);
currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
try {
latch.await();
} catch (InterruptedException e) {
// System.out.println("interrupted");
}
if (abortTransaction) {
rollback(false);
currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
// tempActionHistory.add("sql execute " + cs.sql + " " + actionTimestamp + " " + rowActionList.size());
sessionContext.pushDynamicArguments(pvals);
r = cs.execute(this);
sessionContext.popDynamicArguments();
lockStatement = currentStatement;
// tempActionHistory.add("sql execute end " + actionTimestamp + " " + rowActionList.size());
endAction(r);
if (abortTransaction) {
rollback(false);
currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
if (redoAction) {
redoAction = false;
try {
latch.await();
} catch (InterruptedException e) {
//
System.out.println("interrupted");
}
} else {
break;
}
}
if (sessionContext.depth == 0 && (isAutoCommit || cs.isAutoCommitStatement())) {
try {
if (r.isError()) {
rollback(false);
} else {
commit(false);
}
} catch (Exception e) {
currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
}
currentStatement = null;
return r;
}
Aggregations