Throwable t = Throwables.getRootCause(e);
if (t instanceof HandleNotFoundException) {
LOG.error("Error executing query", e);
throw new SQLException("Unknown state");
} else if (t instanceof UnexpectedQueryStatusException) {
UnexpectedQueryStatusException sE = (UnexpectedQueryStatusException) t;
if (QueryStatus.OpStatus.CANCELED.equals(sE.getStatus())) {
// The query execution may have been canceled without calling futureResults.cancel(), using the right
// REST endpoint with the handle for eg.
return false;
}
throw new SQLException(String.format("Statement '%s' execution did not finish successfully. " +
"Got final state - %s", sql, sE.getStatus().toString()));
}
LOG.error("Caught exception", e);
throw new SQLException(Throwables.getRootCause(e));
} catch (CancellationException e) {
// If futureResults has been cancelled