Search in sources :

Example 1 with SqlRollbackTransactionCommand

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);
    }
}
Also used : SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) SqlStrictParseException(org.apache.ignite.internal.sql.SqlStrictParseException) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) SqlKillContinuousQueryCommand(org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) SqlKillScanQueryCommand(org.apache.ignite.internal.sql.command.SqlKillScanQueryCommand) SqlAnalyzeCommand(org.apache.ignite.internal.sql.command.SqlAnalyzeCommand) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) SqlDropStatisticsCommand(org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand) SqlParser(org.apache.ignite.internal.sql.SqlParser) SqlKillComputeTaskCommand(org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand) SqlRefreshStatitsicsCommand(org.apache.ignite.internal.sql.command.SqlRefreshStatitsicsCommand) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlStrictParseException(org.apache.ignite.internal.sql.SqlStrictParseException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) SqlKillTransactionCommand(org.apache.ignite.internal.sql.command.SqlKillTransactionCommand) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) SqlKillServiceCommand(org.apache.ignite.internal.sql.command.SqlKillServiceCommand) SqlKillQueryCommand(org.apache.ignite.internal.sql.command.SqlKillQueryCommand) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SqlRollbackTransactionCommand

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).");
    }
}
Also used : SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) IgniteException(org.apache.ignite.IgniteException) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand)

Example 3 with SqlRollbackTransactionCommand

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);
    }
}
Also used : SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand)

Aggregations

SqlCommitTransactionCommand (org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand)3 SqlRollbackTransactionCommand (org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand)3 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 SqlBeginTransactionCommand (org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand)2 SqlCommand (org.apache.ignite.internal.sql.command.SqlCommand)2 SQLException (java.sql.SQLException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 NestedTxMode (org.apache.ignite.internal.processors.query.NestedTxMode)1 SqlParseException (org.apache.ignite.internal.sql.SqlParseException)1 SqlParser (org.apache.ignite.internal.sql.SqlParser)1 SqlStrictParseException (org.apache.ignite.internal.sql.SqlStrictParseException)1 SqlAlterTableCommand (org.apache.ignite.internal.sql.command.SqlAlterTableCommand)1 SqlAlterUserCommand (org.apache.ignite.internal.sql.command.SqlAlterUserCommand)1 SqlAnalyzeCommand (org.apache.ignite.internal.sql.command.SqlAnalyzeCommand)1 SqlBulkLoadCommand (org.apache.ignite.internal.sql.command.SqlBulkLoadCommand)1 SqlCreateIndexCommand (org.apache.ignite.internal.sql.command.SqlCreateIndexCommand)1 SqlCreateUserCommand (org.apache.ignite.internal.sql.command.SqlCreateUserCommand)1