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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations