use of org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter in project ignite by apache.
the class IgniteH2Indexing method queryLocalSqlFields.
/**
* Queries individual fields (generally used by JDBC drivers).
*
* @param schemaName Schema name.
* @param qry Query.
* @param params Query parameters.
* @param filter Cache name and key filter.
* @param enforceJoinOrder Enforce join order of tables in the query.
* @param timeout Query timeout in milliseconds.
* @param cancel Query cancel.
* @return Query result.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
public GridQueryFieldsResult queryLocalSqlFields(final String schemaName, final String qry, @Nullable final Collection<Object> params, final IndexingQueryFilter filter, boolean enforceJoinOrder, final int timeout, final GridQueryCancel cancel) throws IgniteCheckedException {
final Connection conn = connectionForSchema(schemaName);
H2Utils.setupConnection(conn, false, enforceJoinOrder);
final PreparedStatement stmt = preparedStatementWithParams(conn, qry, params, true);
Prepared p = GridSqlQueryParser.prepared(stmt);
if (DmlStatementsProcessor.isDmlStatement(p)) {
SqlFieldsQuery fldsQry = new SqlFieldsQuery(qry);
if (params != null)
fldsQry.setArgs(params.toArray());
fldsQry.setEnforceJoinOrder(enforceJoinOrder);
fldsQry.setTimeout(timeout, TimeUnit.MILLISECONDS);
return dmlProc.updateSqlFieldsLocal(schemaName, stmt, fldsQry, filter, cancel);
} else if (DdlStatementsProcessor.isDdlStatement(p))
throw new IgniteSQLException("DDL statements are supported for the whole cluster only", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
List<GridQueryFieldMetadata> meta;
try {
meta = H2Utils.meta(stmt.getMetaData());
} catch (SQLException e) {
throw new IgniteCheckedException("Cannot prepare query metadata", e);
}
final GridH2QueryContext ctx = new GridH2QueryContext(nodeId, nodeId, 0, LOCAL).filter(filter).distributedJoinMode(OFF);
return new GridQueryFieldsResultAdapter(meta, null) {
@Override
public GridCloseableIterator<List<?>> iterator() throws IgniteCheckedException {
assert GridH2QueryContext.get() == null;
GridH2QueryContext.set(ctx);
GridRunningQueryInfo run = new GridRunningQueryInfo(qryIdGen.incrementAndGet(), qry, SQL_FIELDS, schemaName, U.currentTimeMillis(), cancel, true);
runs.putIfAbsent(run.id(), run);
try {
ResultSet rs = executeSqlQueryWithTimer(stmt, conn, qry, params, timeout, cancel);
return new H2FieldsIterator(rs);
} finally {
GridH2QueryContext.clearThreadLocal();
runs.remove(run.id());
}
}
};
}
Aggregations