@Test public void insertBranchTransactionDO() throws SQLException { BranchTransactionDO branchTransactionDO = new BranchTransactionDO(); branchTransactionDO.setResourceId("qqqq"); branchTransactionDO.setXid("abc-123:7777"); branchTransactionDO.setTransactionId(1285343); branchTransactionDO.setBranchId(1234508); 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); String sql = "select * from branch_table where xid= 'abc-123:7777' and branch_id = 1234508"; String delSql = "delete from branch_table where xid= 'abc-123:7777' and branch_id = 1234508"; Connection conn = null; try{ conn = dataSource.getConnection(); ResultSet rs = conn.createStatement().executeQuery(sql); if(rs.next()){ Assertions.assertTrue(true); }else { Assertions.assertTrue(false); } conn.createStatement().execute(delSql); }finally { if(conn != null){ conn.close(); } } }
@Override public boolean insertBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getInsertBranchTransactionSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, branchTransactionDO.getXid()); ps.setLong(2, branchTransactionDO.getTransactionId()); ps.setLong(3, branchTransactionDO.getBranchId()); ps.setString(4, branchTransactionDO.getResourceGroupId()); ps.setString(5, branchTransactionDO.getResourceId()); ps.setString(6, branchTransactionDO.getLockKey()); ps.setString(7, branchTransactionDO.getBranchType()); ps.setInt(8, branchTransactionDO.getStatus()); ps.setString(9, branchTransactionDO.getClientId()); ps.setString(10, branchTransactionDO.getApplicationData()); 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 insertBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getInsertBranchTransactionSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, branchTransactionDO.getXid()); ps.setLong(2, branchTransactionDO.getTransactionId()); ps.setLong(3, branchTransactionDO.getBranchId()); ps.setString(4, branchTransactionDO.getResourceGroupId()); ps.setString(5, branchTransactionDO.getResourceId()); ps.setString(6, branchTransactionDO.getLockKey()); ps.setString(7, branchTransactionDO.getBranchType()); ps.setInt(8, branchTransactionDO.getStatus()); ps.setString(9, branchTransactionDO.getClientId()); ps.setString(10, branchTransactionDO.getApplicationData()); 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 insertBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getInsertBranchTransactionSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, branchTransactionDO.getXid()); ps.setLong(2, branchTransactionDO.getTransactionId()); ps.setLong(3, branchTransactionDO.getBranchId()); ps.setString(4, branchTransactionDO.getResourceGroupId()); ps.setString(5, branchTransactionDO.getResourceId()); ps.setString(6, branchTransactionDO.getLockKey()); ps.setString(7, branchTransactionDO.getBranchType()); ps.setInt(8, branchTransactionDO.getStatus()); ps.setString(9, branchTransactionDO.getClientId()); ps.setString(10, branchTransactionDO.getApplicationData()); 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 insertBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getInsertBranchTransactionSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, branchTransactionDO.getXid()); ps.setLong(2, branchTransactionDO.getTransactionId()); ps.setLong(3, branchTransactionDO.getBranchId()); ps.setString(4, branchTransactionDO.getResourceGroupId()); ps.setString(5, branchTransactionDO.getResourceId()); ps.setString(6, branchTransactionDO.getLockKey()); ps.setString(7, branchTransactionDO.getBranchType()); ps.setInt(8, branchTransactionDO.getStatus()); ps.setString(9, branchTransactionDO.getClientId()); ps.setString(10, branchTransactionDO.getApplicationData()); 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 insertBranchTransactionDO(BranchTransactionDO branchTransactionDO) { String sql = LogStoreSqls.getInsertBranchTransactionSQL(brachTable, dbType); Connection conn = null; PreparedStatement ps = null; try { conn = logStoreDataSource.getConnection(); conn.setAutoCommit(true); ps = conn.prepareStatement(sql); ps.setString(1, branchTransactionDO.getXid()); ps.setLong(2, branchTransactionDO.getTransactionId()); ps.setLong(3, branchTransactionDO.getBranchId()); ps.setString(4, branchTransactionDO.getResourceGroupId()); ps.setString(5, branchTransactionDO.getResourceId()); ps.setString(6, branchTransactionDO.getLockKey()); ps.setString(7, branchTransactionDO.getBranchType()); ps.setInt(8, branchTransactionDO.getStatus()); ps.setString(9, branchTransactionDO.getClientId()); ps.setString(10, branchTransactionDO.getApplicationData()); 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();  }