Search in sources :

Example 1 with StoreException

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

the class AbstractStore method selectList.

protected <T> List<T> selectList(String sql, ResultSetToObject<T> resultSetToObject, Object... args) {
    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet resultSet = null;
    try {
        connection = dataSource.getConnection();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Preparing SQL: {}", sql);
        }
        stmt = connection.prepareStatement(sql);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("setting params to PreparedStatement: {}", Arrays.toString(args));
        }
        for (int i = 0; i < args.length; i++) {
            stmt.setObject(i + 1, args[i]);
        }
        resultSet = stmt.executeQuery();
        List<T> list = new ArrayList<>();
        while (resultSet.next()) {
            list.add(resultSetToObject.toObject(resultSet));
        }
        return list;
    } catch (SQLException e) {
        throw new StoreException(e);
    } finally {
        closeSilent(resultSet);
        closeSilent(stmt);
        closeSilent(connection);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) StoreException(io.seata.common.exception.StoreException)

Example 2 with StoreException

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

the class AbstractStore method selectOne.

protected <T> T selectOne(String sql, ResultSetToObject<T> resultSetToObject, Object... args) {
    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet resultSet = null;
    try {
        connection = dataSource.getConnection();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Preparing SQL statement: {}", sql);
        }
        stmt = connection.prepareStatement(sql);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("setting params to PreparedStatement: {}", Arrays.toString(args));
        }
        for (int i = 0; i < args.length; i++) {
            stmt.setObject(i + 1, args[i]);
        }
        resultSet = stmt.executeQuery();
        if (resultSet.next()) {
            return resultSetToObject.toObject(resultSet);
        }
    } catch (SQLException e) {
        throw new StoreException(e);
    } finally {
        closeSilent(resultSet);
        closeSilent(stmt);
        closeSilent(connection);
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) StoreException(io.seata.common.exception.StoreException)

Example 3 with StoreException

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

the class AbstractTCInboundHandler method handle.

@Override
public BranchReportResponse handle(BranchReportRequest request, final RpcContext rpcContext) {
    BranchReportResponse response = new BranchReportResponse();
    exceptionHandleTemplate(new AbstractCallback<BranchReportRequest, BranchReportResponse>() {

        @Override
        public void execute(BranchReportRequest request, BranchReportResponse response) throws TransactionException {
            try {
                doBranchReport(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("branch report request failed. xid=%s, branchId=%s, msg=%s", request.getXid(), request.getBranchId(), e.getMessage()), e);
            }
        }
    }, request, response);
    return response;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) BranchReportRequest(io.seata.core.protocol.transaction.BranchReportRequest) StoreException(io.seata.common.exception.StoreException)

Example 4 with StoreException

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

the class AbstractTCInboundHandler method handle.

@Override
public GlobalLockQueryResponse handle(GlobalLockQueryRequest request, final RpcContext rpcContext) {
    GlobalLockQueryResponse response = new GlobalLockQueryResponse();
    exceptionHandleTemplate(new AbstractCallback<GlobalLockQueryRequest, GlobalLockQueryResponse>() {

        @Override
        public void execute(GlobalLockQueryRequest request, GlobalLockQueryResponse response) throws TransactionException {
            try {
                doLockCheck(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("global lock query request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
            }
        }
    }, request, response);
    return response;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) GlobalLockQueryResponse(io.seata.core.protocol.transaction.GlobalLockQueryResponse) StoreException(io.seata.common.exception.StoreException)

Example 5 with StoreException

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

the class AbstractTCInboundHandler method handle.

@Override
public GlobalRollbackResponse handle(GlobalRollbackRequest request, final RpcContext rpcContext) {
    GlobalRollbackResponse response = new GlobalRollbackResponse();
    response.setGlobalStatus(GlobalStatus.Rollbacking);
    exceptionHandleTemplate(new AbstractCallback<GlobalRollbackRequest, GlobalRollbackResponse>() {

        @Override
        public void execute(GlobalRollbackRequest request, GlobalRollbackResponse response) throws TransactionException {
            try {
                doGlobalRollback(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("global rollback request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
            }
        }

        @Override
        public void onTransactionException(GlobalRollbackRequest request, GlobalRollbackResponse response, TransactionException tex) {
            super.onTransactionException(request, response, tex);
            // may be appears StoreException outer layer method catch
            checkTransactionStatus(request, response);
        }

        @Override
        public void onException(GlobalRollbackRequest request, GlobalRollbackResponse response, Exception rex) {
            super.onException(request, response, rex);
            // may be appears StoreException outer layer method catch
            checkTransactionStatus(request, response);
        }
    }, request, response);
    return response;
}
Also used : GlobalRollbackRequest(io.seata.core.protocol.transaction.GlobalRollbackRequest) TransactionException(io.seata.core.exception.TransactionException) GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) TransactionException(io.seata.core.exception.TransactionException) StoreException(io.seata.common.exception.StoreException) 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