use of org.h2.value.Transfer in project h2database by h2database.
the class CommandRemote method executeUpdate.
@Override
public ResultWithGeneratedKeys executeUpdate(Object generatedKeysRequest) {
checkParameters();
boolean supportsGeneratedKeys = session.isSupportsGeneratedKeys();
boolean readGeneratedKeys = supportsGeneratedKeys && !Boolean.FALSE.equals(generatedKeysRequest);
int objectId = readGeneratedKeys ? session.getNextId() : 0;
synchronized (session) {
int updateCount = 0;
ResultRemote generatedKeys = null;
boolean autoCommit = false;
for (int i = 0, count = 0; i < transferList.size(); i++) {
prepareIfRequired();
Transfer transfer = transferList.get(i);
try {
session.traceOperation("COMMAND_EXECUTE_UPDATE", id);
transfer.writeInt(SessionRemote.COMMAND_EXECUTE_UPDATE).writeInt(id);
sendParameters(transfer);
if (supportsGeneratedKeys) {
int mode = GeneratedKeysMode.valueOf(generatedKeysRequest);
transfer.writeInt(mode);
switch(mode) {
case GeneratedKeysMode.COLUMN_NUMBERS:
{
int[] keys = (int[]) generatedKeysRequest;
transfer.writeInt(keys.length);
for (int key : keys) {
transfer.writeInt(key);
}
break;
}
case GeneratedKeysMode.COLUMN_NAMES:
{
String[] keys = (String[]) generatedKeysRequest;
transfer.writeInt(keys.length);
for (String key : keys) {
transfer.writeString(key);
}
break;
}
}
}
session.done(transfer);
updateCount = transfer.readInt();
autoCommit = transfer.readBoolean();
if (readGeneratedKeys) {
int columnCount = transfer.readInt();
if (generatedKeys != null) {
generatedKeys.close();
generatedKeys = null;
}
generatedKeys = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
}
} catch (IOException e) {
session.removeServer(e, i--, ++count);
}
}
session.setAutoCommitFromServer(autoCommit);
session.autoCommitIfCluster();
session.readSessionState();
if (generatedKeys != null) {
return new ResultWithGeneratedKeys.WithKeys(updateCount, generatedKeys);
}
return ResultWithGeneratedKeys.of(updateCount);
}
}
use of org.h2.value.Transfer 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.value.Transfer in project h2database by h2database.
the class CommandRemote method sendParameters.
private void sendParameters(Transfer transfer) throws IOException {
int len = parameters.size();
transfer.writeInt(len);
for (ParameterInterface p : parameters) {
Value pVal = p.getParamValue();
if (pVal == null && cmdType == EXPLAIN) {
pVal = ValueNull.INSTANCE;
}
transfer.writeValue(pVal);
}
}
use of org.h2.value.Transfer 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.value.Transfer in project h2database by h2database.
the class ResultRemote method fetchRows.
private void fetchRows(boolean sendFetch) {
synchronized (session) {
session.checkClosed();
try {
rowOffset += result.size();
result.clear();
int fetch = Math.min(fetchSize, rowCount - rowOffset);
if (sendFetch) {
session.traceOperation("RESULT_FETCH_ROWS", id);
transfer.writeInt(SessionRemote.RESULT_FETCH_ROWS).writeInt(id).writeInt(fetch);
session.done(transfer);
}
for (int r = 0; r < fetch; r++) {
boolean row = transfer.readBoolean();
if (!row) {
break;
}
int len = columns.length;
Value[] values = new Value[len];
for (int i = 0; i < len; i++) {
Value v = transfer.readValue();
values[i] = v;
}
result.add(values);
}
if (rowOffset + result.size() >= rowCount) {
sendClose();
}
} catch (IOException e) {
throw DbException.convertIOException(e, null);
}
}
}
Aggregations