use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class DmlStatementsProcessor method updateSqlFieldsBatched.
/**
* Execute DML statement, possibly with few re-attempts in case of concurrent data modifications.
*
* @param schemaName Schema.
* @param conn Connection.
* @param prepared Prepared statement.
* @param fieldsQry Original query.
* @param loc Query locality flag.
* @param filters Cache name and key filter.
* @param cancel Cancel.
* @return Update result (modified items count and failed keys).
* @throws IgniteCheckedException if failed.
*/
private Collection<UpdateResult> updateSqlFieldsBatched(String schemaName, Connection conn, Prepared prepared, SqlFieldsQueryEx fieldsQry, boolean loc, IndexingQueryFilter filters, GridQueryCancel cancel) throws IgniteCheckedException {
List<Object[]> argss = fieldsQry.batchedArguments();
UpdatePlan plan = getPlanForStatement(schemaName, conn, prepared, fieldsQry, loc, null);
if (plan.hasRows() && plan.mode() == UpdateMode.INSERT) {
GridCacheContext<?, ?> cctx = plan.cacheContext();
CacheOperationContext opCtx = setKeepBinaryContext(cctx);
try {
List<List<List<?>>> cur = plan.createRows(argss);
List<UpdateResult> res = processDmlSelectResultBatched(plan, cur, fieldsQry.getPageSize());
return res;
} finally {
cctx.operationContextPerCall(opCtx);
}
} else {
// Fallback to previous mode.
Collection<UpdateResult> ress = new ArrayList<>(argss.size());
SQLException batchException = null;
int[] cntPerRow = new int[argss.size()];
int cntr = 0;
for (Object[] args : argss) {
SqlFieldsQueryEx qry0 = (SqlFieldsQueryEx) fieldsQry.copy();
qry0.clearBatchedArgs();
qry0.setArgs(args);
UpdateResult res;
try {
res = updateSqlFields(schemaName, conn, prepared, qry0, loc, filters, cancel);
cntPerRow[cntr++] = (int) res.counter();
ress.add(res);
} catch (Exception e) {
String sqlState;
int code;
if (e instanceof IgniteSQLException) {
sqlState = ((IgniteSQLException) e).sqlState();
code = ((IgniteSQLException) e).statusCode();
} else {
sqlState = SqlStateCode.INTERNAL_ERROR;
code = IgniteQueryErrorCode.UNKNOWN;
}
batchException = chainException(batchException, new SQLException(e.getMessage(), sqlState, code, e));
cntPerRow[cntr++] = Statement.EXECUTE_FAILED;
}
}
if (batchException != null) {
BatchUpdateException e = new BatchUpdateException(batchException.getMessage(), batchException.getSQLState(), batchException.getErrorCode(), cntPerRow, batchException);
throw new IgniteCheckedException(e);
}
return ress;
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class JdbcRequestHandler method getParametersMeta.
/**
* @param req Request.
* @return Response.
*/
private JdbcResponse getParametersMeta(JdbcMetaParamsRequest req) {
String schemaName = prepareSchemaName(req.schemaName());
SqlFieldsQueryEx qry = new SqlFieldsQueryEx(req.sql(), null);
setupQuery(qry, schemaName);
try {
List<JdbcParameterMeta> meta = connCtx.kernalContext().query().getIndexing().parameterMetaData(schemaName, qry);
JdbcMetaParamsResult res = new JdbcMetaParamsResult(meta);
return resultToResonse(res);
} catch (Exception e) {
U.error(log, "Failed to get parameters metadata [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToResult(e);
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method getParamsMeta.
/**
* {@link OdbcQueryGetQueryMetaRequest} command handler.
* Returns metadata for the parameters to be set.
*
* @param req Get params metadata request.
* @return Response.
*/
private ClientListenerResponse getParamsMeta(OdbcQueryGetParamsMetaRequest req) {
try {
String sql = OdbcEscapeUtils.parse(req.query());
String schema = OdbcUtils.prepareSchema(req.schema());
SqlFieldsQueryEx qry = makeQuery(schema, sql);
List<JdbcParameterMeta> params = ctx.query().getIndexing().parameterMetaData(schema, qry);
byte[] typeIds = new byte[params.size()];
for (int i = 0; i < params.size(); ++i) {
int sqlType = params.get(i).type();
typeIds[i] = sqlTypeToBinary(sqlType);
}
OdbcQueryGetParamsMetaResult res = new OdbcQueryGetParamsMetaResult(typeIds);
return new OdbcResponse(res);
} catch (Exception e) {
U.error(log, "Failed to get params metadata [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToResult(e);
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method makeQuery.
/**
* Make query considering handler configuration.
* @param schema Schema.
* @param sql SQL request.
* @return Query instance.
*/
private SqlFieldsQueryEx makeQuery(String schema, String sql) {
SqlFieldsQueryEx qry = new SqlFieldsQueryEx(sql, null);
qry.setDistributedJoins(cliCtx.isDistributedJoins());
qry.setEnforceJoinOrder(cliCtx.isEnforceJoinOrder());
qry.setReplicatedOnly(cliCtx.isReplicatedOnly());
qry.setCollocated(cliCtx.isCollocated());
qry.setLazy(cliCtx.isLazy());
qry.setSchema(OdbcUtils.prepareSchema(schema));
qry.setSkipReducerOnUpdate(cliCtx.isSkipReducerOnUpdate());
qry.setNestedTxMode(nestedTxMode);
qry.setQueryInitiatorId(connCtx.clientDescriptor());
return qry;
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method makeQuery.
/**
* Make query considering handler configuration.
* @param schema Schema.
* @param sql SQL request.
* @param args Arguments.
* @param autoCommit Autocommit transaction.
* @param timeout Query timeout.
* @return Query instance.
*/
private SqlFieldsQueryEx makeQuery(String schema, String sql, Object[] args, int timeout, boolean autoCommit) {
SqlFieldsQueryEx qry = makeQuery(schema, sql);
qry.setArgs(args);
qry.setAutoCommit(autoCommit);
QueryUtils.withQueryTimeout(qry, timeout, TimeUnit.SECONDS);
return qry;
}
Aggregations