private void writeSelection(OutputStream out) throws IOException { ObjectOutputStream selectionOut = new ObjectOutputStream(out); //Do not save byte consuming selection LongUnion mergedSelection; Set<Long> selection = tableEditableElement.getSelection(); if(selection instanceof LongUnion) { mergedSelection = (LongUnion) selection; } else { mergedSelection = new LongUnion(selection); } if(mergedSelection.getValueRanges().size()>MAX_SELECTION_SERIALISATION_SIZE) { selectionOut.writeObject(new IntegerUnion()); } else { selectionOut.writeObject(mergedSelection); } selectionOut.flush(); selectionOut.close(); }
@Override protected Object doInBackground() throws SQLException { try(Connection connection = dataSource.getConnection()) { boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); int columnId = JDBCUtilities.getIntegerPrimaryKey(connection, tableName); if(columnId > 0) { String pkColumnName = JDBCUtilities.getFieldName(connection.getMetaData(), tableName, columnId); // A deletion batch is an ordered set of pk values to remove (a complete serial of integer without holes) List<Long> deletionBatch = rowPkToDelete.getValueRanges(); ProgressMonitor pmBatch = getProgressMonitor().startTask(deletionBatch.size() / 2); try(PreparedStatement st = connection.prepareStatement( String.format("DELETE FROM %s WHERE %s >= ? AND %s <= ?", TableLocation.parse(tableName).toString(isH2),pkColumnName, pkColumnName))) { for (int idDelBatch = 0; idDelBatch < deletionBatch.size() - 1; idDelBatch += 2) { long startBatch = deletionBatch.get(idDelBatch); long endBatch = deletionBatch.get(idDelBatch + 1); st.setLong(1, startBatch); st.setLong(2, endBatch); st.execute(); pmBatch.endTask(); } } } } return null; }