use of org.h2.result.ResultInterface in project h2database by h2database.
the class CommandRemote method executeQuery.
@Override
public ResultInterface executeQuery(int maxRows, boolean scrollable) {
checkParameters();
synchronized (session) {
int objectId = session.getNextId();
ResultRemote result = null;
for (int i = 0, count = 0; i < transferList.size(); i++) {
prepareIfRequired();
Transfer transfer = transferList.get(i);
try {
session.traceOperation("COMMAND_EXECUTE_QUERY", id);
transfer.writeInt(SessionRemote.COMMAND_EXECUTE_QUERY).writeInt(id).writeInt(objectId).writeInt(maxRows);
int fetch;
if (session.isClustered() || scrollable) {
fetch = Integer.MAX_VALUE;
} else {
fetch = fetchSize;
}
transfer.writeInt(fetch);
sendParameters(transfer);
session.done(transfer);
int columnCount = transfer.readInt();
if (result != null) {
result.close();
result = null;
}
result = new ResultRemote(session, transfer, objectId, columnCount, fetch);
if (readonly) {
break;
}
} catch (IOException e) {
session.removeServer(e, i--, ++count);
}
}
session.autoCommitIfCluster();
session.readSessionState();
return result;
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class CommandRemote method getMetaData.
@Override
public ResultInterface getMetaData() {
synchronized (session) {
if (!isQuery) {
return null;
}
int objectId = session.getNextId();
ResultRemote result = null;
for (int i = 0, count = 0; i < transferList.size(); i++) {
prepareIfRequired();
Transfer transfer = transferList.get(i);
try {
session.traceOperation("COMMAND_GET_META_DATA", id);
transfer.writeInt(SessionRemote.COMMAND_GET_META_DATA).writeInt(id).writeInt(objectId);
session.done(transfer);
int columnCount = transfer.readInt();
result = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
break;
} catch (IOException e) {
session.removeServer(e, i--, ++count);
}
}
session.autoCommitIfCluster();
return result;
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class Command method executeQuery.
/**
* Execute a query and return the result.
* This method prepares everything and calls {@link #query(int)} finally.
*
* @param maxrows the maximum number of rows to return
* @param scrollable if the result set must be scrollable (ignored)
* @return the result set
*/
@Override
public ResultInterface executeQuery(int maxrows, boolean scrollable) {
startTimeNanos = 0;
long start = 0;
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
session.waitIfExclusiveModeEnabled();
boolean callStop = true;
boolean writing = !isReadOnly();
if (writing) {
while (!database.beforeWriting()) {
// wait
}
}
synchronized (sync) {
session.setCurrentCommand(this, false);
try {
while (true) {
database.checkPowerOff();
try {
ResultInterface result = query(maxrows);
callStop = !result.isLazy();
return result;
} catch (DbException e) {
start = filterConcurrentUpdate(e, start);
} catch (OutOfMemoryError e) {
callStop = false;
// there is a serious problem:
// the transaction may be applied partially
// in this case we need to panic:
// close the database
database.shutdownImmediately();
throw DbException.convert(e);
} catch (Throwable e) {
throw DbException.convert(e);
}
}
} catch (DbException e) {
e = e.addSQL(sql);
SQLException s = e.getSQLException();
database.exceptionThrown(s, sql);
if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
callStop = false;
database.shutdownImmediately();
throw e;
}
database.checkPowerOff();
throw e;
} finally {
if (callStop) {
stop();
}
if (writing) {
database.afterWriting();
}
}
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcConnection method getTransactionIsolation.
/**
* Returns the current transaction isolation level.
*
* @return the isolation level.
* @throws SQLException if the connection is closed
*/
@Override
public int getTransactionIsolation() throws SQLException {
try {
debugCodeCall("getTransactionIsolation");
checkClosed();
getLockMode = prepareCommand("CALL LOCK_MODE()", getLockMode);
ResultInterface result = getLockMode.executeQuery(0, false);
result.next();
int lockMode = result.currentRow()[0].getInt();
result.close();
int transactionIsolationLevel;
switch(lockMode) {
case Constants.LOCK_MODE_OFF:
transactionIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
break;
case Constants.LOCK_MODE_READ_COMMITTED:
transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
break;
case Constants.LOCK_MODE_TABLE:
case Constants.LOCK_MODE_TABLE_GC:
transactionIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
break;
default:
throw DbException.throwInternalError("lockMode:" + lockMode);
}
return transactionIsolationLevel;
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcPreparedStatement method getMetaData.
/**
* Gets the result set metadata of the query returned when the statement is
* executed. If this is not a query, this method returns null.
*
* @return the meta data or null if this is not a query
* @throws SQLException if this object is closed
*/
@Override
public ResultSetMetaData getMetaData() throws SQLException {
try {
debugCodeCall("getMetaData");
checkClosed();
ResultInterface result = command.getMetaData();
if (result == null) {
return null;
}
int id = getNextId(TraceObject.RESULT_SET_META_DATA);
if (isDebugEnabled()) {
debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
}
String catalog = conn.getCatalog();
return new JdbcResultSetMetaData(null, this, result, catalog, session.getTrace(), id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
Aggregations