Search in sources :

Example 36 with StoreException

use of io.seata.common.exception.StoreException in project XHuiCloud by sindaZeng.

the class RedisTransactionStoreManager method updateBranchTransactionDO.

/**
 * Update the branch transaction
 * @param branchTransactionDO
 * @return
 */
private boolean updateBranchTransactionDO(BranchTransactionDO branchTransactionDO) {
    String branchKey = buildBranchKey(branchTransactionDO.getBranchId());
    try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
        String previousBranchStatus = jedis.hget(branchKey, REDIS_KEY_BRANCH_STATUS);
        if (StringUtils.isEmpty(previousBranchStatus)) {
            throw new StoreException("Branch transaction is not exist, update branch transaction failed.");
        }
        Map<String, String> map = new HashMap<>(2, 1);
        map.put(REDIS_KEY_BRANCH_STATUS, String.valueOf(branchTransactionDO.getStatus()));
        map.put(REDIS_KEY_BRANCH_GMT_MODIFIED, String.valueOf((new Date()).getTime()));
        jedis.hmset(branchKey, map);
        return true;
    } catch (Exception ex) {
        throw new RedisException(ex);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) RedisException(io.seata.common.exception.RedisException) StoreException(io.seata.common.exception.StoreException) RedisException(io.seata.common.exception.RedisException) StoreException(io.seata.common.exception.StoreException)

Example 37 with StoreException

use of io.seata.common.exception.StoreException in project XHuiCloud by sindaZeng.

the class LockStoreDataBaseDAO method unLock.

@Override
public boolean unLock(List<LockDO> lockDOs) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = lockStoreDataSource.getConnection();
        conn.setAutoCommit(true);
        StringJoiner sj = new StringJoiner(",");
        for (int i = 0; i < lockDOs.size(); i++) {
            sj.add("?");
        }
        // batch release lock
        String batchDeleteSQL = LockStoreSqlFactory.getLogStoreSql(dbType).getBatchDeleteLockSql(lockTable, sj.toString());
        ps = conn.prepareStatement(batchDeleteSQL);
        ps.setString(1, lockDOs.get(0).getXid());
        for (int i = 0; i < lockDOs.size(); i++) {
            ps.setString(i + 2, lockDOs.get(i).getRowKey());
        }
        ps.executeUpdate();
    } catch (SQLException e) {
        throw new StoreException(e);
    } finally {
        IOUtil.close(ps, conn);
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StoreException(io.seata.common.exception.StoreException)

Example 38 with StoreException

use of io.seata.common.exception.StoreException in project XHuiCloud by sindaZeng.

the class LockStoreDataBaseDAO method doAcquireLock.

/**
 * Do acquire lock boolean.
 *
 * @param conn   the conn
 * @param lockDO the lock do
 * @return the boolean
 */
protected boolean doAcquireLock(Connection conn, LockDO lockDO) {
    PreparedStatement ps = null;
    try {
        // insert
        String insertLockSQL = LockStoreSqlFactory.getLogStoreSql(dbType).getInsertLockSQL(lockTable);
        ps = conn.prepareStatement(insertLockSQL);
        ps.setString(1, lockDO.getXid());
        ps.setLong(2, lockDO.getTransactionId());
        ps.setLong(3, lockDO.getBranchId());
        ps.setString(4, lockDO.getResourceId());
        ps.setString(5, lockDO.getTableName());
        ps.setString(6, lockDO.getPk());
        ps.setString(7, lockDO.getRowKey());
        return ps.executeUpdate() > 0;
    } catch (SQLException e) {
        throw new StoreException(e);
    } finally {
        IOUtil.close(ps);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) StoreException(io.seata.common.exception.StoreException)

Example 39 with StoreException

use of io.seata.common.exception.StoreException in project XHuiCloud by sindaZeng.

the class LogStoreDataBaseDAO method insertGlobalTransactionDO.

@Override
public boolean insertGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) {
    String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getInsertGlobalTransactionSQL(globalTable);
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = logStoreDataSource.getConnection();
        conn.setAutoCommit(true);
        ps = conn.prepareStatement(sql);
        ps.setString(1, globalTransactionDO.getXid());
        ps.setLong(2, globalTransactionDO.getTransactionId());
        ps.setInt(3, globalTransactionDO.getStatus());
        ps.setString(4, globalTransactionDO.getApplicationId());
        ps.setString(5, globalTransactionDO.getTransactionServiceGroup());
        String transactionName = globalTransactionDO.getTransactionName();
        transactionName = transactionName.length() > transactionNameColumnSize ? transactionName.substring(0, transactionNameColumnSize) : transactionName;
        ps.setString(6, transactionName);
        ps.setInt(7, globalTransactionDO.getTimeout());
        ps.setLong(8, globalTransactionDO.getBeginTime());
        ps.setString(9, globalTransactionDO.getApplicationData());
        return ps.executeUpdate() > 0;
    } catch (SQLException e) {
        throw new StoreException(e);
    } finally {
        IOUtil.close(ps, conn);
    }
}
Also used : StoreException(io.seata.common.exception.StoreException)

Aggregations

StoreException (io.seata.common.exception.StoreException)39 PreparedStatement (java.sql.PreparedStatement)20 SQLException (java.sql.SQLException)20 Connection (java.sql.Connection)18 TransactionException (io.seata.core.exception.TransactionException)7 RedisException (io.seata.common.exception.RedisException)4 ResultSet (java.sql.ResultSet)4 Jedis (redis.clients.jedis.Jedis)4 StringJoiner (java.util.StringJoiner)3 LockDO (io.seata.core.store.LockDO)2 StoreMode (io.seata.core.store.StoreMode)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Transaction (redis.clients.jedis.Transaction)2 BranchRegisterRequest (io.seata.core.protocol.transaction.BranchRegisterRequest)1 BranchRegisterResponse (io.seata.core.protocol.transaction.BranchRegisterResponse)1 BranchReportRequest (io.seata.core.protocol.transaction.BranchReportRequest)1 BranchReportResponse (io.seata.core.protocol.transaction.BranchReportResponse)1 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)1 GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)1