use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class SessionConverterTest method testConvertGlobalSessionNull.
@Test
public void testConvertGlobalSessionNull() {
GlobalTransactionDO globalTransactionDO = null;
GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
Assertions.assertNull(globalSession);
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class SessionConverterTest method testConvertGlobalSessionNotNull.
@Test
public void testConvertGlobalSessionNotNull() {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
Date date = new Date();
long now = date.getTime();
globalTransactionDO.setXid("192.168.158.80:8091:39372760251957248");
globalTransactionDO.setTransactionId(39372760251957248L);
globalTransactionDO.setStatus(1);
globalTransactionDO.setApplicationId("credit");
globalTransactionDO.setTransactionServiceGroup("fsp_tx");
globalTransactionDO.setTransactionName("createOrder");
globalTransactionDO.setTimeout(60);
globalTransactionDO.setBeginTime(now);
globalTransactionDO.setApplicationData("id=1,product=2");
globalTransactionDO.setGmtCreate(date);
globalTransactionDO.setGmtModified(date);
GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
Assertions.assertEquals(globalTransactionDO.getXid(), globalSession.getXid());
Assertions.assertEquals(globalTransactionDO.getTransactionId(), globalSession.getTransactionId());
Assertions.assertEquals(globalTransactionDO.getStatus(), globalSession.getStatus().getCode());
Assertions.assertEquals(globalTransactionDO.getApplicationId(), globalSession.getApplicationId());
Assertions.assertEquals(globalTransactionDO.getTransactionServiceGroup(), globalSession.getTransactionServiceGroup());
Assertions.assertEquals(globalTransactionDO.getTransactionName(), globalSession.getTransactionName());
Assertions.assertEquals(globalTransactionDO.getTimeout(), globalSession.getTimeout());
Assertions.assertEquals(globalTransactionDO.getBeginTime(), globalSession.getBeginTime());
Assertions.assertEquals(globalTransactionDO.getApplicationData(), globalSession.getApplicationData());
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAO method convertGlobalTransactionDO.
private GlobalTransactionDO convertGlobalTransactionDO(ResultSet rs) throws SQLException {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_XID));
globalTransactionDO.setStatus(rs.getInt(ServerTableColumnsName.GLOBAL_TABLE_STATUS));
globalTransactionDO.setApplicationId(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_ID));
globalTransactionDO.setBeginTime(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_BEGIN_TIME));
globalTransactionDO.setTimeout(rs.getInt(ServerTableColumnsName.GLOBAL_TABLE_TIMEOUT));
globalTransactionDO.setTransactionId(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_ID));
globalTransactionDO.setTransactionName(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_NAME));
globalTransactionDO.setTransactionServiceGroup(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_SERVICE_GROUP));
globalTransactionDO.setApplicationData(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_DATA));
globalTransactionDO.setGmtCreate(rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_CREATE));
globalTransactionDO.setGmtModified(rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_MODIFIED));
return globalTransactionDO;
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAO method queryGlobalTransactionDO.
@Override
public List<GlobalTransactionDO> queryGlobalTransactionDO(int[] statuses, int limit) {
List<GlobalTransactionDO> ret = new ArrayList<>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = logStoreDataSource.getConnection();
conn.setAutoCommit(true);
String paramsPlaceHolder = org.apache.commons.lang.StringUtils.repeat("?", ",", statuses.length);
String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getQueryGlobalTransactionSQLByStatus(globalTable, paramsPlaceHolder);
ps = conn.prepareStatement(sql);
for (int i = 0; i < statuses.length; i++) {
int status = statuses[i];
ps.setInt(i + 1, status);
}
ps.setInt(statuses.length + 1, limit);
rs = ps.executeQuery();
while (rs.next()) {
ret.add(convertGlobalTransactionDO(rs));
}
return ret;
} catch (SQLException e) {
throw new DataAccessException(e);
} finally {
IOUtil.close(rs, ps, conn);
}
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class SessionConverter method convertGlobalTransactionDO.
public static GlobalTransactionDO convertGlobalTransactionDO(SessionStorable session) {
if (session == null || !(session instanceof GlobalSession)) {
throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
}
GlobalSession globalSession = (GlobalSession) session;
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid(globalSession.getXid());
globalTransactionDO.setStatus(globalSession.getStatus().getCode());
globalTransactionDO.setApplicationId(globalSession.getApplicationId());
globalTransactionDO.setBeginTime(globalSession.getBeginTime());
globalTransactionDO.setTimeout(globalSession.getTimeout());
globalTransactionDO.setTransactionId(globalSession.getTransactionId());
globalTransactionDO.setTransactionName(globalSession.getTransactionName());
globalTransactionDO.setTransactionServiceGroup(globalSession.getTransactionServiceGroup());
globalTransactionDO.setApplicationData(globalSession.getApplicationData());
return globalTransactionDO;
}
Aggregations