use of io.seata.common.exception.StoreException in project seata by seata.
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;
}
use of io.seata.common.exception.StoreException in project seata by seata.
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);
}
}
use of io.seata.common.exception.StoreException in project seata by seata.
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);
}
}
use of io.seata.common.exception.StoreException in project seata by seata.
the class LogStoreDataBaseDAO method deleteBranchTransactionDO.
@Override
public boolean deleteBranchTransactionDO(BranchTransactionDO branchTransactionDO) {
String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getDeleteBranchTransactionByBranchIdSQL(branchTable);
Connection conn = null;
PreparedStatement ps = null;
try {
conn = logStoreDataSource.getConnection();
conn.setAutoCommit(true);
ps = conn.prepareStatement(sql);
ps.setString(1, branchTransactionDO.getXid());
ps.setLong(2, branchTransactionDO.getBranchId());
ps.executeUpdate();
} catch (SQLException e) {
throw new StoreException(e);
} finally {
IOUtil.close(ps, conn);
}
return true;
}
use of io.seata.common.exception.StoreException in project seata by seata.
the class LogStoreDataBaseDAO method updateGlobalTransactionDO.
@Override
public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) {
String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getUpdateGlobalTransactionStatusSQL(globalTable);
Connection conn = null;
PreparedStatement ps = null;
try {
conn = logStoreDataSource.getConnection();
conn.setAutoCommit(true);
ps = conn.prepareStatement(sql);
ps.setInt(1, globalTransactionDO.getStatus());
ps.setString(2, globalTransactionDO.getXid());
return ps.executeUpdate() > 0;
} catch (SQLException e) {
throw new StoreException(e);
} finally {
IOUtil.close(ps, conn);
}
}
Aggregations