use of org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand in project ignite by apache.
the class QueryParser method parseNative.
/**
* Tries to parse sql query text using native parser. Only first (leading) sql command of the multi-statement is
* actually parsed.
*
* @param schemaName Schema name.
* @param qry which sql text to parse.
* @param remainingAllowed Whether multiple statements are allowed.
* @return Command or {@code null} if cannot parse this query.
*/
@SuppressWarnings("IfMayBeConditional")
@Nullable
private QueryParserResult parseNative(String schemaName, SqlFieldsQuery qry, boolean remainingAllowed) {
String sql = qry.getSql();
// Heuristic check for fast return.
if (!INTERNAL_CMD_RE.matcher(sql.trim()).find())
return null;
try {
SqlParser parser = new SqlParser(schemaName, sql);
SqlCommand nativeCmd = parser.nextCommand();
assert nativeCmd != null : "Empty query. Parser met end of data";
if (!(nativeCmd instanceof SqlCreateIndexCommand || nativeCmd instanceof SqlDropIndexCommand || nativeCmd instanceof SqlBeginTransactionCommand || nativeCmd instanceof SqlCommitTransactionCommand || nativeCmd instanceof SqlRollbackTransactionCommand || nativeCmd instanceof SqlBulkLoadCommand || nativeCmd instanceof SqlAlterTableCommand || nativeCmd instanceof SqlSetStreamingCommand || nativeCmd instanceof SqlCreateUserCommand || nativeCmd instanceof SqlAlterUserCommand || nativeCmd instanceof SqlDropUserCommand || nativeCmd instanceof SqlKillQueryCommand || nativeCmd instanceof SqlKillComputeTaskCommand || nativeCmd instanceof SqlKillServiceCommand || nativeCmd instanceof SqlKillTransactionCommand || nativeCmd instanceof SqlKillScanQueryCommand || nativeCmd instanceof SqlKillContinuousQueryCommand || nativeCmd instanceof SqlAnalyzeCommand || nativeCmd instanceof SqlRefreshStatitsicsCommand || nativeCmd instanceof SqlDropStatisticsCommand))
return null;
SqlFieldsQuery newQry = cloneFieldsQuery(qry).setSql(parser.lastCommandSql());
QueryDescriptor newPlanKey = queryDescriptor(schemaName, newQry);
SqlFieldsQuery remainingQry = null;
if (!F.isEmpty(parser.remainingSql())) {
checkRemainingAllowed(remainingAllowed);
remainingQry = cloneFieldsQuery(qry).setSql(parser.remainingSql()).setArgs(qry.getArgs());
}
QueryParserResultCommand cmd = new QueryParserResultCommand(nativeCmd, null, false);
return new QueryParserResult(newPlanKey, queryParameters(newQry), remainingQry, // Currently none of native statements supports parameters.
Collections.emptyList(), null, null, cmd);
} catch (SqlStrictParseException e) {
throw new IgniteSQLException(e.getMessage(), e.errorCode(), e);
} catch (Exception e) {
// Cannot parse, return.
if (log.isDebugEnabled())
log.debug("Failed to parse SQL with native parser [qry=" + sql + ", err=" + e + ']');
if (!IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_SQL_PARSER_DISABLE_H2_FALLBACK))
return null;
int code = IgniteQueryErrorCode.PARSING;
if (e instanceof SqlParseException)
code = ((SqlParseException) e).code();
throw new IgniteSQLException("Failed to parse DDL statement: " + sql + ": " + e.getMessage(), code, e);
}
}
use of org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand in project ignite by apache.
the class IgniteH2Indexing method checkClusterState.
/**
* Check whether command could be executed with the given cluster state.
*
* @param parseRes Parsing result.
*/
private void checkClusterState(QueryParserResult parseRes) {
if (!ctx.state().publicApiActiveState(true)) {
if (parseRes.isCommand()) {
QueryParserResultCommand cmd = parseRes.command();
assert cmd != null;
SqlCommand cmd0 = cmd.commandNative();
if (cmd0 instanceof SqlCommitTransactionCommand || cmd0 instanceof SqlRollbackTransactionCommand)
return;
}
throw new IgniteException("Can not perform the operation because the cluster is inactive. Note, " + "that the cluster is considered inactive by default if Ignite Persistent Store is used to " + "let all the nodes join the cluster. To activate the cluster call Ignite.active(true).");
}
}
use of org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand in project ignite by apache.
the class CommandProcessor method processTxCommand.
/**
* Process transactional command.
* @param cmd Command.
* @param params Parameters.
* @throws IgniteCheckedException if failed.
*/
private void processTxCommand(SqlCommand cmd, QueryParameters params) throws IgniteCheckedException {
NestedTxMode nestedTxMode = params.nestedTxMode();
GridNearTxLocal tx = tx(ctx);
if (cmd instanceof SqlBeginTransactionCommand) {
if (!mvccEnabled(ctx))
throw new IgniteSQLException("MVCC must be enabled in order to start transaction.", IgniteQueryErrorCode.MVCC_DISABLED);
if (tx != null) {
if (nestedTxMode == null)
nestedTxMode = NestedTxMode.DEFAULT;
switch(nestedTxMode) {
case COMMIT:
doCommit(tx);
txStart(ctx, params.timeout());
break;
case IGNORE:
log.warning("Transaction has already been started, ignoring BEGIN command.");
break;
case ERROR:
throw new IgniteSQLException("Transaction has already been started.", IgniteQueryErrorCode.TRANSACTION_EXISTS);
default:
throw new IgniteSQLException("Unexpected nested transaction handling mode: " + nestedTxMode.name());
}
} else
txStart(ctx, params.timeout());
} else if (cmd instanceof SqlCommitTransactionCommand) {
// Do nothing if there's no transaction.
if (tx != null)
doCommit(tx);
} else {
assert cmd instanceof SqlRollbackTransactionCommand;
// Do nothing if there's no transaction.
if (tx != null)
doRollback(tx);
}
}
Aggregations