Search in sources :

Example 1 with LocalXaSqlConnection

use of cn.mycat.vertx.xa.impl.LocalXaSqlConnection in project Mycat2 by MyCATApache.

the class MycatDataContextImpl method switchTransaction.

@Override
public void switchTransaction(TransactionType transactionSessionType) {
    int transcationIsolationLevel = Optional.ofNullable(user).map(i -> i.getUserConfig()).map(i -> i.getIsolation()).orElse(3);
    MySQLIsolation mySQLIsolation = MySQLIsolation.values()[transcationIsolationLevel - 1];
    Objects.requireNonNull(transactionSessionType);
    TransactionSession transactionSession = null;
    XaSqlConnection connection;
    switch(transactionSessionType) {
        case PROXY_TRANSACTION_TYPE:
            connection = new LocalSqlConnection(mySQLIsolation, () -> MetaClusterCurrent.wrapper(MySQLManager.class), MetaClusterCurrent.wrapper(XaLog.class));
            break;
        case JDBC_TRANSACTION_TYPE:
            connection = new LocalXaSqlConnection(mySQLIsolation, () -> MetaClusterCurrent.wrapper(MySQLManager.class), MetaClusterCurrent.wrapper(XaLog.class));
            break;
        default:
            throw new IllegalStateException("Unexpected transaction type: " + transactionSessionType);
    }
    connection = new SavepointSqlConnection(connection);
    transactionSession = new MycatXaTranscation(connection, transactionSessionType);
    if (this.transactionSession != null) {
        this.transactionSession.deliverTo(transactionSession);
    }
    this.transactionSession = transactionSession;
}
Also used : TransactionType(io.mycat.beans.mycat.TransactionType) Setter(lombok.Setter) java.util(java.util) io.mycat(io.mycat) Getter(lombok.Getter) LocalXaSqlConnection(cn.mycat.vertx.xa.impl.LocalXaSqlConnection) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XaLog(cn.mycat.vertx.xa.XaLog) CompletableFuture(java.util.concurrent.CompletableFuture) Charset(java.nio.charset.Charset) okhttp3(okhttp3) Observable(io.reactivex.rxjava3.core.Observable) MySQLIsolation(io.mycat.beans.mysql.MySQLIsolation) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) LocalSqlConnection(cn.mycat.vertx.xa.impl.LocalSqlConnection) AbstractWritePacket(io.mycat.util.packet.AbstractWritePacket) SQLUtils(com.alibaba.druid.sql.SQLUtils) Logger(org.slf4j.Logger) MycatServerConfig(io.mycat.config.MycatServerConfig) ObservableEmitter(io.reactivex.rxjava3.core.ObservableEmitter) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) AtomicLong(java.util.concurrent.atomic.AtomicLong) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) MySQLIsolation(io.mycat.beans.mysql.MySQLIsolation) LocalXaSqlConnection(cn.mycat.vertx.xa.impl.LocalXaSqlConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) LocalSqlConnection(cn.mycat.vertx.xa.impl.LocalSqlConnection) LocalXaSqlConnection(cn.mycat.vertx.xa.impl.LocalXaSqlConnection) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection)

Aggregations

MySQLManager (cn.mycat.vertx.xa.MySQLManager)1 SavepointSqlConnection (cn.mycat.vertx.xa.SavepointSqlConnection)1 XaLog (cn.mycat.vertx.xa.XaLog)1 XaSqlConnection (cn.mycat.vertx.xa.XaSqlConnection)1 LocalSqlConnection (cn.mycat.vertx.xa.impl.LocalSqlConnection)1 LocalXaSqlConnection (cn.mycat.vertx.xa.impl.LocalXaSqlConnection)1 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 io.mycat (io.mycat)1 TransactionType (io.mycat.beans.mycat.TransactionType)1 MySQLIsolation (io.mycat.beans.mysql.MySQLIsolation)1 MycatServerConfig (io.mycat.config.MycatServerConfig)1 AbstractWritePacket (io.mycat.util.packet.AbstractWritePacket)1 Observable (io.reactivex.rxjava3.core.Observable)1 ObservableEmitter (io.reactivex.rxjava3.core.ObservableEmitter)1 Charset (java.nio.charset.Charset)1 java.util (java.util)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1