DeleteSelectedRows extends SwingWorkerPM { public static void deleteUsingRowSet(ReversibleRowSet reversibleRowSet, SortedSet<Long> rowPkToDelete) throws SQLException, InterruptedException { TreeSet<Integer> rowNumberToDelete = new TreeSet<>(reversibleRowSet.getRowNumberFromRowPk(rowPkToDelete)); Lock lock = reversibleRowSet.getReadLock(); if(lock.tryLock(TRY_LOCK_TIME, TimeUnit.SECONDS)) { try { for (int rowNumber : rowNumberToDelete.descendingSet()) { reversibleRowSet.absolute(rowNumber); reversibleRowSet.deleteRow(); } } finally { lock.unlock(); } } } DeleteSelectedRows(SortedSet<Long> rowPkToDelete, String tableName, DataSource dataSource); static void deleteUsingRowSet(ReversibleRowSet reversibleRowSet, SortedSet<Long> rowPkToDelete);  }
@Test public void testDeleteWithRowSet() throws SQLException, InterruptedException { try(Connection connection = dataSource.getConnection(); Statement st = connection.createStatement()) { st.execute("DROP TABLE IF EXISTS \"MY TABLE\""); st.execute("CREATE TABLE \"MY TABLE\"(PK INTEGER PRIMARY KEY) AS SELECT X FROM SYSTEM_RANGE(1,50);"); LongUnion pkToDelete = new LongUnion(1, 25); DataManager dataManager = new DataManagerImpl(dataSource); try(ReversibleRowSet reversibleRowSet = dataManager.createReversibleRowSet()) { reversibleRowSet.setCommand("SELECT * FROM \"MY TABLE\""); reversibleRowSet.execute(); DeleteSelectedRows.deleteUsingRowSet(reversibleRowSet, pkToDelete); } try(ResultSet rs = st.executeQuery("SELECT PK FROM \"MY TABLE\"")) { for(long expectedPk : new LongUnion(26,50)) { assertTrue(rs.next()); assertEquals(expectedPk, rs.getLong(1)); } assertFalse(rs.next()); } } }