LogStoreDataBaseDAO implements LogStore, Initialize { @Override public List<BranchTransactionDO> queryBranchTransactionDO(String xid) { List<BranchTransactionDO> rets = new ArrayList<>(); String sql = LogStoreSqls.getQureyBranchTransaction(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, xid); ResultSet rs = ps.executeQuery(); while (rs.next()) { rets.add(convertBranchTransactionDO(rs)); } return rets; } catch (SQLException e) { throw new StoreException(e); } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } } LogStoreDataBaseDAO();  LogStoreDataBaseDAO(DataSource logStoreDataSource); @Override void init(); @Override GlobalTransactionDO queryGlobalTransactionDO(String xid); @Override GlobalTransactionDO queryGlobalTransactionDO(long transactionId); @Override List<GlobalTransactionDO> queryGlobalTransactionDO(int[] statuses, int limit); @Override boolean insertGlobalTransactionDO(GlobalTransactionDO globalTransactionDO); @Override boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO); @Override boolean deleteGlobalTransactionDO(GlobalTransactionDO globalTransactionDO); @Override List<BranchTransactionDO> queryBranchTransactionDO(String xid); @Override boolean insertBranchTransactionDO(BranchTransactionDO branchTransactionDO); @Override boolean updateBranchTransactionDO(BranchTransactionDO branchTransactionDO); @Override boolean deleteBranchTransactionDO(BranchTransactionDO branchTransactionDO); void initTransactionNameSize(); void setLogStoreDataSource(DataSource logStoreDataSource); void setGlobalTable(String globalTable); void setBrachTable(String brachTable); void setDbType(String dbType); int getTransactionNameColumnSize();  }
@Test public void queryBranchTransactionDO() throws SQLException { { BranchTransactionDO branchTransactionDO = new BranchTransactionDO(); branchTransactionDO.setResourceId("qqqq"); branchTransactionDO.setXid("abc-123:6789"); branchTransactionDO.setTransactionId(24234235); branchTransactionDO.setBranchId(345465676); branchTransactionDO.setBranchType("TCC"); branchTransactionDO.setResourceGroupId("abc"); branchTransactionDO.setLockKey("t:1,2,3;t2,4,5,6"); branchTransactionDO.setResourceGroupId("a"); branchTransactionDO.setClientId("1.1.1.1"); branchTransactionDO.setStatus(1); branchTransactionDO.setApplicationData("abc=123"); branchTransactionDO.setResourceGroupId("test"); boolean ret = logStoreDataBaseDAO.insertBranchTransactionDO(branchTransactionDO); Assertions.assertTrue(ret); } { BranchTransactionDO branchTransactionDO = new BranchTransactionDO(); branchTransactionDO.setResourceId("qqqq"); branchTransactionDO.setXid("abc-123:6789"); branchTransactionDO.setTransactionId(24234235); branchTransactionDO.setBranchId(78563453); branchTransactionDO.setBranchType("TCC"); branchTransactionDO.setResourceGroupId("abc"); branchTransactionDO.setLockKey("t:6;t2:7"); branchTransactionDO.setResourceGroupId("a"); branchTransactionDO.setClientId("1.1.1.1"); branchTransactionDO.setStatus(1); branchTransactionDO.setApplicationData("abc=123"); branchTransactionDO.setResourceGroupId("test"); boolean ret = logStoreDataBaseDAO.insertBranchTransactionDO(branchTransactionDO); Assertions.assertTrue(ret); } List<BranchTransactionDO> rets = logStoreDataBaseDAO.queryBranchTransactionDO("abc-123:6789"); Assertions.assertTrue(CollectionUtils.isNotEmpty(rets)); Assertions.assertEquals(2, rets.size()); if(78563453 == rets.get(0).getBranchId() && 345465676 == rets.get(1).getBranchId()){ Assertions.assertTrue(true); }else if(78563453 == rets.get(1).getBranchId() && 345465676 == rets.get(0).getBranchId()){ Assertions.assertTrue(true); }else { Assertions.assertTrue(false); } String delSql = "delete from branch_table where xid= 'abc-123:6789' "; Connection conn = null; try{ conn = dataSource.getConnection(); conn.createStatement().execute(delSql); }finally { if(conn != null){ conn.close(); } } }