use of org.adbcj.support.DefaultResult in project adbcj by mheath.
the class ProtocolHandler method doCommandComplete.
private void doCommandComplete(AbstractConnection connection, CommandCompleteMessage commandCompleteMessage) {
AbstractDbSession.Request<Object> request = connection.getActiveRequest();
if (request == null) {
throw new IllegalStateException("Received a data row without an active request");
}
Object accumulator = request.getAccumulator();
switch(commandCompleteMessage.getCommand()) {
case SELECT:
request.getEventHandler().endResults(accumulator);
request.complete(accumulator);
case BEGIN:
case COMMIT:
case ROLLBACK:
request.complete(null);
break;
case DELETE:
case INSERT:
case UPDATE:
DefaultResult result = new DefaultResult(commandCompleteMessage.getRowCount(), Collections.<String>emptyList());
request.complete(result);
break;
// TODO Implement MOVE command completion
default:
throw new IllegalStateException(String.format("Command completions of type %s are not implemented", commandCompleteMessage.getCommand()));
}
}
use of org.adbcj.support.DefaultResult in project adbcj by mheath.
the class ProtocolHandler method handleOkResponse.
private void handleOkResponse(AbstractMySqlConnection connection, OkResponse response) {
logger.trace("Response '{}' on connection {}", response, connection);
List<String> warnings = null;
if (response.getWarningCount() > 0) {
warnings = new LinkedList<String>();
for (int i = 0; i < response.getWarningCount(); i++) {
warnings.add(response.getMessage());
}
}
logger.warn("Warnings: {}", warnings);
Request<Result> activeRequest = connection.getActiveRequest();
if (activeRequest == null) {
// TODO Do we need to pass the warnings on to the connection?
DefaultDbFuture<Connection> connectFuture = connection.getConnectFuture();
if (!connectFuture.isDone()) {
connectFuture.setResult(connection);
return;
} else {
throw new IllegalStateException("Received an OkResponse with no activeRequest " + response);
}
}
Result result = new DefaultResult(response.getAffectedRows(), warnings);
activeRequest.complete(result);
}
Aggregations