Search in sources :

Example 1 with NestedTxMode

use of org.apache.ignite.internal.processors.query.NestedTxMode in project ignite by apache.

the class JdbcConnectionContext method initializeFromHandshake.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFromHandshake(GridNioSession ses, ClientListenerProtocolVersion ver, BinaryReaderExImpl reader) throws IgniteCheckedException {
    assert SUPPORTED_VERS.contains(ver) : "Unsupported JDBC protocol version.";
    boolean distributedJoins = reader.readBoolean();
    boolean enforceJoinOrder = reader.readBoolean();
    boolean collocated = reader.readBoolean();
    boolean replicatedOnly = reader.readBoolean();
    boolean autoCloseCursors = reader.readBoolean();
    boolean lazyExec = false;
    boolean skipReducerOnUpdate = false;
    NestedTxMode nestedTxMode = NestedTxMode.DEFAULT;
    if (ver.compareTo(VER_2_1_5) >= 0)
        lazyExec = reader.readBoolean();
    if (ver.compareTo(VER_2_3_0) >= 0)
        skipReducerOnUpdate = reader.readBoolean();
    if (ver.compareTo(VER_2_7_0) >= 0) {
        String nestedTxModeName = reader.readString();
        if (!F.isEmpty(nestedTxModeName)) {
            try {
                nestedTxMode = NestedTxMode.valueOf(nestedTxModeName);
            } catch (IllegalArgumentException e) {
                throw new IgniteCheckedException("Invalid nested transactions handling mode: " + nestedTxModeName);
            }
        }
    }
    Boolean dataPageScanEnabled = null;
    Integer updateBatchSize = null;
    EnumSet<JdbcThinFeature> features = EnumSet.noneOf(JdbcThinFeature.class);
    if (ver.compareTo(VER_2_8_0) >= 0) {
        dataPageScanEnabled = nullableBooleanFromByte(reader.readByte());
        updateBatchSize = JdbcUtils.readNullableInteger(reader);
    }
    if (ver.compareTo(VER_2_9_0) >= 0) {
        userAttrs = reader.readMap();
        byte[] cliFeatures = reader.readByteArray();
        features = JdbcThinFeature.enumSet(cliFeatures);
    }
    if (ver.compareTo(VER_2_5_0) >= 0) {
        String user = null;
        String passwd = null;
        try {
            if (reader.available() > 0) {
                user = reader.readString();
                passwd = reader.readString();
            }
        } catch (Exception e) {
            throw new IgniteCheckedException("Handshake error: " + e.getMessage(), e);
        }
        authenticate(ses, user, passwd);
    }
    protoCtx = new JdbcProtocolContext(ver, features, true);
    initClientDescriptor("jdbc-thin");
    parser = new JdbcMessageParser(ctx, protoCtx);
    ClientListenerResponseSender sender = new ClientListenerResponseSender() {

        @Override
        public void send(ClientListenerResponse resp) {
            if (resp != null) {
                if (log.isDebugEnabled())
                    log.debug("Async response: [resp=" + resp.status() + ']');
                ses.send(parser.encode(resp));
            }
        }
    };
    handler = new JdbcRequestHandler(busyLock, sender, maxCursors, distributedJoins, enforceJoinOrder, collocated, replicatedOnly, autoCloseCursors, lazyExec, skipReducerOnUpdate, nestedTxMode, dataPageScanEnabled, updateBatchSize, ver, this);
    handler.start();
}
Also used : NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) ClientListenerResponseSender(org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClientListenerResponse(org.apache.ignite.internal.processors.odbc.ClientListenerResponse)

Example 2 with NestedTxMode

use of org.apache.ignite.internal.processors.query.NestedTxMode 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)

Example 3 with NestedTxMode

use of org.apache.ignite.internal.processors.query.NestedTxMode in project ignite by apache.

the class OdbcConnectionContext method initializeFromHandshake.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFromHandshake(GridNioSession ses, ClientListenerProtocolVersion ver, BinaryReaderExImpl reader) throws IgniteCheckedException {
    assert SUPPORTED_VERS.contains(ver) : "Unsupported ODBC protocol version.";
    boolean distributedJoins = reader.readBoolean();
    boolean enforceJoinOrder = reader.readBoolean();
    boolean replicatedOnly = reader.readBoolean();
    boolean collocated = reader.readBoolean();
    boolean lazy = false;
    if (ver.compareTo(VER_2_1_5) >= 0)
        lazy = reader.readBoolean();
    boolean skipReducerOnUpdate = false;
    if (ver.compareTo(VER_2_3_0) >= 0)
        skipReducerOnUpdate = reader.readBoolean();
    String user = null;
    String passwd = null;
    NestedTxMode nestedTxMode = NestedTxMode.DEFAULT;
    if (ver.compareTo(VER_2_5_0) >= 0) {
        user = reader.readString();
        passwd = reader.readString();
    }
    if (ver.compareTo(VER_2_7_0) >= 0) {
        byte nestedTxModeVal = reader.readByte();
        nestedTxMode = NestedTxMode.fromByte(nestedTxModeVal);
    }
    authenticate(ses, user, passwd);
    ClientListenerResponseSender sender = new ClientListenerResponseSender() {

        @Override
        public void send(ClientListenerResponse resp) {
            if (resp != null) {
                if (log.isDebugEnabled())
                    log.debug("Async response: [resp=" + resp.status() + ']');
                ses.send(parser.encode(resp));
            }
        }
    };
    initClientDescriptor("odbc");
    handler = new OdbcRequestHandler(ctx, busyLock, sender, maxCursors, distributedJoins, enforceJoinOrder, replicatedOnly, collocated, lazy, skipReducerOnUpdate, nestedTxMode, ver, this);
    parser = new OdbcMessageParser(ctx, ver);
    handler.start();
}
Also used : ClientListenerResponse(org.apache.ignite.internal.processors.odbc.ClientListenerResponse) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) ClientListenerResponseSender(org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender)

Example 4 with NestedTxMode

use of org.apache.ignite.internal.processors.query.NestedTxMode in project ignite by apache.

the class QueryParser method queryParameters.

/**
 * Create parameters from query.
 *
 * @param qry Query.
 * @return Parameters.
 */
public QueryParameters queryParameters(SqlFieldsQuery qry) {
    NestedTxMode nestedTxMode = NestedTxMode.DEFAULT;
    boolean autoCommit = true;
    List<Object[]> batchedArgs = null;
    if (qry instanceof SqlFieldsQueryEx) {
        SqlFieldsQueryEx qry0 = (SqlFieldsQueryEx) qry;
        if (qry0.getNestedTxMode() != null)
            nestedTxMode = qry0.getNestedTxMode();
        autoCommit = qry0.isAutoCommit();
        batchedArgs = qry0.batchedArguments();
    }
    int timeout = qry.getTimeout();
    if (timeout < 0)
        timeout = (int) idx.distributedConfiguration().defaultQueryTimeout();
    return new QueryParameters(qry.getArgs(), qry.getPartitions(), timeout, qry.isLazy(), qry.getPageSize(), null, nestedTxMode, autoCommit, batchedArgs, qry.getUpdateBatchSize());
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode)

Aggregations

NestedTxMode (org.apache.ignite.internal.processors.query.NestedTxMode)4 ClientListenerResponse (org.apache.ignite.internal.processors.odbc.ClientListenerResponse)2 ClientListenerResponseSender (org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 SqlFieldsQueryEx (org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 SqlBeginTransactionCommand (org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand)1 SqlCommitTransactionCommand (org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand)1 SqlRollbackTransactionCommand (org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand)1