use of herddb.network.Channel in project herddb by diennea.
the class RoutedClientSideConnection method executeGet.
GetResult executeGet(String tableSpace, String query, long tx, List<Object> params) throws HDBException, ClientSideMetadataProviderException {
Channel _channel = ensureOpen();
try {
Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, query, tx, false, params);
Message reply = _channel.sendMessageWithReply(message, timeout);
if (reply.type == Message.TYPE_ERROR) {
boolean notLeader = reply.parameters.get("notLeader") != null;
if (notLeader) {
this.connection.requestMetadataRefresh();
throw new RetryRequestException(reply + "");
}
throw new HDBException(reply);
}
long found = (Long) reply.parameters.get("updateCount");
long transactionId = (Long) reply.parameters.get("tx");
if (found <= 0) {
return new GetResult(null, transactionId);
} else {
return new GetResult((Map<String, Object>) reply.parameters.get("data"), transactionId);
}
} catch (InterruptedException | TimeoutException err) {
throw new HDBException(err);
}
}
use of herddb.network.Channel in project herddb by diennea.
the class RoutedClientSideConnection method executeScan.
ScanResultSet executeScan(String tableSpace, String query, List<Object> params, long tx, int maxRows, int fetchSize) throws HDBException, ClientSideMetadataProviderException {
Channel _channel = ensureOpen();
try {
String scannerId = this.clientId + ":" + SCANNERID_GENERATOR.incrementAndGet();
Message message = Message.OPEN_SCANNER(clientId, tableSpace, query, scannerId, tx, params, fetchSize, maxRows);
LOGGER.log(Level.FINEST, "open scanner {0} for query {1}, params {2}", new Object[] { scannerId, query, params });
Message reply = _channel.sendMessageWithReply(message, timeout);
if (reply.type == Message.TYPE_ERROR) {
boolean notLeader = reply.parameters.get("notLeader") != null;
if (notLeader) {
this.connection.requestMetadataRefresh();
throw new RetryRequestException(reply + "");
}
throw new HDBException(reply);
}
TuplesList data = (TuplesList) reply.parameters.get("data");
List<DataAccessor> initialFetchBuffer = data.tuples;
String[] columnNames = data.columnNames;
boolean last = (Boolean) reply.parameters.get("last");
long transactionId = (Long) reply.parameters.get("tx");
// LOGGER.log(Level.SEVERE, "received first " + initialFetchBuffer.size() + " records for query " + query);
ScanResultSetImpl impl = new ScanResultSetImpl(scannerId, columnNames, initialFetchBuffer, fetchSize, last, transactionId);
return impl;
} catch (InterruptedException | TimeoutException err) {
throw new HDBException(err);
}
}
use of herddb.network.Channel in project herddb by diennea.
the class RoutedClientSideConnection method commitTransaction.
void commitTransaction(String tableSpace, long tx) throws HDBException, ClientSideMetadataProviderException {
Channel _channel = ensureOpen();
try {
Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, "COMMIT TRANSACTION '" + tableSpace + "'," + tx, 0, false, null);
Message reply = _channel.sendMessageWithReply(message, timeout);
if (reply.type == Message.TYPE_ERROR) {
boolean notLeader = reply.parameters.get("notLeader") != null;
if (notLeader) {
this.connection.requestMetadataRefresh();
throw new RetryRequestException(reply + "");
}
throw new HDBException(reply);
}
} catch (InterruptedException | TimeoutException err) {
throw new HDBException(err);
}
}
use of herddb.network.Channel in project herddb by diennea.
the class RoutedClientSideConnection method executeUpdates.
List<DMLResult> executeUpdates(String tableSpace, String query, long tx, boolean returnValues, List<List<Object>> batch) throws HDBException, ClientSideMetadataProviderException {
Channel _channel = ensureOpen();
try {
Message message = Message.EXECUTE_STATEMENTS(clientId, tableSpace, query, tx, returnValues, batch);
Message reply = _channel.sendMessageWithReply(message, timeout);
if (reply.type == Message.TYPE_ERROR) {
boolean notLeader = reply.parameters.get("notLeader") != null;
if (notLeader) {
this.connection.requestMetadataRefresh();
throw new RetryRequestException(reply + "");
}
throw new HDBException(reply);
}
long transactionId = (Long) reply.parameters.get("tx");
List<Map<String, Object>> data = (List<Map<String, Object>>) reply.parameters.get("data");
List<Long> updateCounts = (List<Long>) reply.parameters.get("updateCount");
List<DMLResult> results = new ArrayList<>();
for (int i = 0; i < updateCounts.size(); i++) {
Object key = data.get(0).get("key");
Map<String, Object> newvalue = (Map<String, Object>) data.get(i).get("newvalue");
DMLResult res = new DMLResult(updateCounts.get(i), key, newvalue, transactionId);
results.add(res);
}
return results;
} catch (InterruptedException | TimeoutException err) {
throw new HDBException(err);
}
}
use of herddb.network.Channel in project herddb by diennea.
the class RoutedClientSideConnection method beginTransaction.
long beginTransaction(String tableSpace) throws HDBException, ClientSideMetadataProviderException {
Channel _channel = ensureOpen();
try {
Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, "BEGIN TRANSACTION '" + tableSpace + "'", 0, false, null);
Message reply = _channel.sendMessageWithReply(message, timeout);
if (reply.type == Message.TYPE_ERROR) {
boolean notLeader = reply.parameters.get("notLeader") != null;
if (notLeader) {
this.connection.requestMetadataRefresh();
throw new RetryRequestException(reply + "");
}
throw new HDBException(reply);
}
Map<String, Object> data = (Map<String, Object>) reply.parameters.get("data");
return (Long) data.get("tx");
} catch (InterruptedException | TimeoutException err) {
throw new HDBException(err);
}
}
Aggregations