in core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java [521:583]
protected ResultSet executeQueryInternal(AvaticaStatement statement,
Meta.Signature signature, Meta.Frame firstFrame, QueryState state, boolean isUpdate)
throws SQLException {
// Close the previous open result set, if there is one.
Meta.Frame frame = firstFrame;
Meta.Signature signature2 = signature;
synchronized (statement) {
if (statement.openResultSet != null) {
final AvaticaResultSet rs = statement.openResultSet;
statement.openResultSet = null;
try {
rs.close();
} catch (Exception e) {
throw HELPER.createException(
"Error while closing previous result set", e);
}
}
try {
if (statement.isWrapperFor(AvaticaPreparedStatement.class)) {
final AvaticaPreparedStatement pstmt = (AvaticaPreparedStatement) statement;
Meta.StatementHandle handle = pstmt.handle;
if (isUpdate) {
// Make a copy of the StatementHandle, nulling out the Signature.
// CALCITE-1086 we don't need to send the Signature to the server
// when we're only performing an update. Saves on serialization.
handle = new Meta.StatementHandle(handle.connectionId, handle.id, null);
}
final Meta.ExecuteResult executeResult =
meta.execute(handle, pstmt.getParameterValues(),
statement.getFetchSize());
final MetaResultSet metaResultSet = executeResult.resultSets.get(0);
frame = metaResultSet.firstFrame;
statement.updateCount = metaResultSet.updateCount;
signature2 = executeResult.resultSets.get(0).signature;
}
} catch (Exception e) {
throw HELPER.createException(e.getMessage(), e);
}
final TimeZone timeZone = getTimeZone();
if (frame == null && signature2 == null && statement.updateCount != -1) {
statement.openResultSet = null;
} else {
// Duplicative SQL, for support non-prepared statements
statement.openResultSet =
factory.newResultSet(statement, state, signature2, timeZone, frame);
}
}
// Release the monitor before executing, to give another thread the
// opportunity to call cancel.
try {
if (statement.openResultSet != null) {
statement.openResultSet.execute();
isUpdateCapable(statement);
}
} catch (Exception e) {
throw HELPER.createException(
"exception while executing query: " + e.getMessage(), e);
}
return statement.openResultSet;
}