use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest in project ignite by apache.
the class JdbcThinConnection method executeNative.
/**
* @param sql Statement.
* @param cmd Parsed form of {@code sql}.
* @throws SQLException if failed.
*/
void executeNative(String sql, SqlCommand cmd) throws SQLException {
if (cmd instanceof SqlSetStreamingCommand) {
// If streaming is already on, we have to disable it first.
if (stream) {
// We have to send request regardless of actual batch size.
executeBatch(true);
stream = false;
}
boolean newVal = ((SqlSetStreamingCommand) cmd).isTurnOn();
// Actual ON, if needed.
if (newVal) {
sendRequest(new JdbcQueryExecuteRequest(JdbcStatementType.ANY_STATEMENT_TYPE, schema, 1, 1, sql, null));
streamBatchSize = ((SqlSetStreamingCommand) cmd).batchSize();
stream = true;
}
} else
throw IgniteQueryErrorCode.createJdbcSqlException("Unsupported native statement: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest in project ignite by apache.
the class JdbcThinStatement method execute0.
/**
* @param stmtType Expected statement type.
* @param sql Sql query.
* @param args Query parameters.
*
* @throws SQLException Onj error.
*/
protected void execute0(JdbcStatementType stmtType, String sql, List<Object> args) throws SQLException {
ensureNotClosed();
closeResults();
if (sql == null || sql.isEmpty())
throw new SQLException("SQL query is empty.");
checkStatementBatchEmpty();
SqlCommand nativeCmd = null;
if (stmtType != JdbcStatementType.SELECT_STATEMENT_TYPE && isEligibleForNativeParsing(sql))
nativeCmd = tryParseNative(sql);
if (nativeCmd != null) {
conn.executeNative(sql, nativeCmd);
resultSets = Collections.singletonList(resultSetForUpdate(0));
// as an ordinary batch citizen.
return;
}
if (conn.isStream()) {
if (stmtType == JdbcStatementType.SELECT_STATEMENT_TYPE)
throw new SQLException("executeQuery() method is not allowed in streaming mode.", SqlStateCode.INTERNAL_ERROR, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
conn.addBatch(sql, args);
resultSets = Collections.singletonList(resultSetForUpdate(0));
return;
}
JdbcResult res0 = conn.sendRequest(new JdbcQueryExecuteRequest(stmtType, schema, pageSize, maxRows, sql, args == null ? null : args.toArray(new Object[args.size()])));
assert res0 != null;
if (res0 instanceof JdbcBulkLoadAckResult)
res0 = sendFile((JdbcBulkLoadAckResult) res0);
if (res0 instanceof JdbcQueryExecuteResult) {
JdbcQueryExecuteResult res = (JdbcQueryExecuteResult) res0;
resultSets = Collections.singletonList(new JdbcThinResultSet(this, res.getQueryId(), pageSize, res.last(), res.items(), res.isQuery(), conn.autoCloseServerCursor(), res.updateCount(), closeOnCompletion));
} else if (res0 instanceof JdbcQueryExecuteMultipleStatementsResult) {
JdbcQueryExecuteMultipleStatementsResult res = (JdbcQueryExecuteMultipleStatementsResult) res0;
List<JdbcResultInfo> resInfos = res.results();
resultSets = new ArrayList<>(resInfos.size());
boolean firstRes = true;
for (JdbcResultInfo rsInfo : resInfos) {
if (!rsInfo.isQuery())
resultSets.add(resultSetForUpdate(rsInfo.updateCount()));
else {
if (firstRes) {
firstRes = false;
resultSets.add(new JdbcThinResultSet(this, rsInfo.queryId(), pageSize, res.isLast(), res.items(), true, conn.autoCloseServerCursor(), -1, closeOnCompletion));
} else {
resultSets.add(new JdbcThinResultSet(this, rsInfo.queryId(), pageSize, false, null, true, conn.autoCloseServerCursor(), -1, closeOnCompletion));
}
}
}
} else
throw new SQLException("Unexpected result [res=" + res0 + ']');
assert resultSets.size() > 0 : "At least one results set is expected";
}
Aggregations