@Test public void updateGlobalTransactionDO() throws SQLException { GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO(); globalTransactionDO.setXid("abc-123:222"); globalTransactionDO.setApplicationData("abc=5454"); globalTransactionDO.setTransactionServiceGroup("abc"); globalTransactionDO.setTransactionName("test"); globalTransactionDO.setTransactionId(12345); globalTransactionDO.setTimeout(20); globalTransactionDO.setBeginTime(System.currentTimeMillis()); globalTransactionDO.setApplicationId("test"); globalTransactionDO.setStatus(1); boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO); Assertions.assertTrue(ret); String sql = "select * from global_table where xid= 'abc-123:222'"; String delSql = "delete from global_table where xid= 'abc-123:222'"; Connection conn = null; try{ conn = dataSource.getConnection(); ResultSet rs = conn.createStatement().executeQuery(sql); if(rs.next()){ Assertions.assertTrue(true); Assertions.assertEquals(1, rs.getInt("status")); }else{ Assertions.assertTrue(false); } rs.close(); globalTransactionDO.setStatus(2); Assertions.assertTrue(logStoreDataBaseDAO.updateGlobalTransactionDO(globalTransactionDO)); rs = conn.createStatement().executeQuery(sql); if(rs.next()){ Assertions.assertTrue(true); Assertions.assertEquals(2, rs.getInt("status")); }else{ Assertions.assertTrue(false); } rs.close(); conn.createStatement().execute(delSql); }finally { if(conn != null){ conn.close(); } } }
@Override public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) { String sql = LogStoreSqls.getUpdateGlobalTransactionStatusSQL(globalTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, globalTransactionDO.getStatus()); ps.setString(2, globalTransactionDO.getXid()); 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 implements LogStore, Initialize { @Override public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) { String sql = LogStoreSqls.getUpdateGlobalTransactionStatusSQL(globalTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, globalTransactionDO.getStatus()); ps.setString(2, globalTransactionDO.getXid()); 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 implements LogStore, Initialize { @Override public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) { String sql = LogStoreSqls.getUpdateGlobalTransactionStatusSQL(globalTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, globalTransactionDO.getStatus()); ps.setString(2, globalTransactionDO.getXid()); 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); }
LogStoreDataBaseDAO implements LogStore, Initialize { @Override public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) { String sql = LogStoreSqls.getUpdateGlobalTransactionStatusSQL(globalTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, globalTransactionDO.getStatus()); ps.setString(2, globalTransactionDO.getXid()); 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(); }
LogStoreDataBaseDAO implements LogStore, Initialize { @Override public boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactionDO) { String sql = LogStoreSqls.getUpdateGlobalTransactionStatusSQL(globalTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setInt(1, globalTransactionDO.getStatus()); ps.setString(2, globalTransactionDO.getXid()); 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();  }