LogStoreDataBaseDAO implements LogStore, Initialize { @Override public boolean updateBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getUpdateBranchTransactionStatusSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, branchTransactionDO.getStatus()); ps.setString(2, branchTransactionDO.getXid()); ps.setLong(3, branchTransactionDO.getBranchId()); return ps.executeUpdate() > 0; } 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 updateBranchTransactionDO() throws SQLException { BranchTransactionDO branchTransactionDO = new BranchTransactionDO(); branchTransactionDO.setResourceId("qqqq"); branchTransactionDO.setXid("abc-123:8888"); branchTransactionDO.setTransactionId(1285343); branchTransactionDO.setBranchId(343434318); 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.setStatus(3); Assertions.assertTrue(logStoreDataBaseDAO.updateBranchTransactionDO(branchTransactionDO)); String sql = "select * from branch_table where xid= 'abc-123:8888' and branch_id = 343434318"; String delSql = "delete from branch_table where xid= 'abc-123:8888' and branch_id = 343434318"; Connection conn = null; try{ conn = dataSource.getConnection(); ResultSet rs = conn.createStatement().executeQuery(sql); if(rs.next()){ Assertions.assertTrue(true); Assertions.assertEquals(3, rs.getInt("status")); }else { Assertions.assertTrue(false); } conn.createStatement().execute(delSql); }finally { if(conn != null){ conn.close(); } } }