From: James Ahlborn Date: Fri, 25 Nov 2011 00:30:53 +0000 (+0000) Subject: Allow ImportFilter and ExportFilter to return null from filterRow() to indicate that... X-Git-Tag: jackcess-1.2.6~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2661755b796d99fb8331393c075c9f9309a687cd;p=jackcess.git Allow ImportFilter and ExportFilter to return null from filterRow() to indicate that a row should be skipped. git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@597 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 17dacb2..2fa0e8d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -20,6 +20,10 @@ Reuse previously written memo/ole values when updating other values in a row in order to reduce unnecessary data duplication. + + Allow ImportFilter and ExportFilter to return null from filterRow() to + indicate that a row should be skipped. + diff --git a/src/java/com/healthmarketscience/jackcess/ExportFilter.java b/src/java/com/healthmarketscience/jackcess/ExportFilter.java index b9c6124..f145fd5 100644 --- a/src/java/com/healthmarketscience/jackcess/ExportFilter.java +++ b/src/java/com/healthmarketscience/jackcess/ExportFilter.java @@ -54,7 +54,8 @@ public interface ExportFilter { * @param row * the row data as determined by the import code, may be directly * modified - * @return the row data as it should be written to the import table + * @return the row data as it should be written to the import table. if + * {@code null}, the row will be skipped */ public Object[] filterRow(Object[] row) throws IOException; diff --git a/src/java/com/healthmarketscience/jackcess/ExportUtil.java b/src/java/com/healthmarketscience/jackcess/ExportUtil.java index 7876fb0..472d328 100644 --- a/src/java/com/healthmarketscience/jackcess/ExportUtil.java +++ b/src/java/com/healthmarketscience/jackcess/ExportUtil.java @@ -332,6 +332,9 @@ public class ExportUtil { // apply filter Object[] rowData = filter.filterRow(unfilteredRowData); + if(rowData == null) { + continue; + } // print row for (int i = 0; i < columns.size(); i++) { diff --git a/src/java/com/healthmarketscience/jackcess/ImportFilter.java b/src/java/com/healthmarketscience/jackcess/ImportFilter.java index 6bcc620..144b481 100644 --- a/src/java/com/healthmarketscience/jackcess/ImportFilter.java +++ b/src/java/com/healthmarketscience/jackcess/ImportFilter.java @@ -56,7 +56,8 @@ public interface ImportFilter { * The desired values for the row. * @param row the row data as determined by the import code, may be directly * modified - * @return the row data as it should be written to the import table + * @return the row data as it should be written to the import table. if + * {@code null}, the row will be skipped */ public Object[] filterRow(Object[] row) throws SQLException, IOException; diff --git a/src/java/com/healthmarketscience/jackcess/ImportUtil.java b/src/java/com/healthmarketscience/jackcess/ImportUtil.java index 0cd418e..b647570 100644 --- a/src/java/com/healthmarketscience/jackcess/ImportUtil.java +++ b/src/java/com/healthmarketscience/jackcess/ImportUtil.java @@ -164,7 +164,11 @@ public class ImportUtil for (int i = 0; i < row.length; i++) { row[i] = source.getObject(i + 1); } - rows.add(filter.filterRow(row)); + row = filter.filterRow(row); + if(row == null) { + continue; + } + rows.add(row); if (rows.size() == COPY_TABLE_BATCH_SIZE) { table.addRows(rows); rows.clear(); @@ -385,7 +389,11 @@ public class ImportUtil while ((line = in.readLine()) != null) { Object[] data = splitLine(line, delimPat, quote, in, numColumns); - rows.add(filter.filterRow(data)); + data = filter.filterRow(data); + if(data == null) { + continue; + } + rows.add(data); if (rows.size() == COPY_TABLE_BATCH_SIZE) { table.addRows(rows); rows.clear();