diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2012-08-26 19:45:17 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2012-08-26 19:45:17 +0000 |
commit | 3e547e1d59bd61e8d1ad9bab945af5d0eafba061 (patch) | |
tree | b2e062d7c1e87129fcfd901fbe33e64f460b7524 /src | |
parent | 64f98b1d1067fbaa4d7cf2a825e682f845c600a7 (diff) | |
download | jackcess-3e547e1d59bd61e8d1ad9bab945af5d0eafba061.tar.gz jackcess-3e547e1d59bd61e8d1ad9bab945af5d0eafba061.zip |
Add some more functionality to Joiner to facilitate integrity enforcement (hasRows and deleteRows)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@640 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r-- | src/changes/changes.xml | 6 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Joiner.java | 34 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1572375..b27fa1e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,12 @@ <author email="javajedi@users.sf.net">Tim McCune</author> </properties> <body> + <release version="1.2.9" date="TBD"> + <action dev="jahlborn" type="update"> + Add some more functionality to Joiner to facilitate integrity + enforcement (hasRows and deleteRows). + </action> + </release> <release version="1.2.8" date="2012-07-10"> <action dev="jahlborn" type="update" issue="3523179"> Add osgi header information to the manifest. diff --git a/src/java/com/healthmarketscience/jackcess/Joiner.java b/src/java/com/healthmarketscience/jackcess/Joiner.java index 3b51854..8e5bf7c 100644 --- a/src/java/com/healthmarketscience/jackcess/Joiner.java +++ b/src/java/com/healthmarketscience/jackcess/Joiner.java @@ -21,6 +21,7 @@ package com.healthmarketscience.jackcess; import java.io.IOException; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -115,6 +116,15 @@ public class Joiner } /** + * Returns {@code true} if the "to" table has any rows based on the given + * columns in the "from" table, {@code false} otherwise. + */ + public boolean hasRows(Map<String,?> fromRow) throws IOException { + toEntryValues(fromRow); + return _toCursor.findFirstRowByEntry(_entryValues); + } + + /** * Returns the first row in the "to" table based on the given columns in the * "from" table if any, {@code null} if there is no matching row. * @@ -140,9 +150,7 @@ public class Joiner Collection<String> columnNames) throws IOException { - toEntryValues(fromRow); - return ((_toCursor.findFirstRowByEntry(_entryValues) ? - _toCursor.getCurrentRow(columnNames) : null)); + return (hasRows(fromRow) ? _toCursor.getCurrentRow(columnNames) : null); } /** @@ -207,6 +215,26 @@ public class Joiner } /** + * Deletes any rows in the "to" table based on the given columns in the + * "from" table. + * + * @param fromRow row from the "from" table (which must include the relevant + * columns for this join relationship) + * @return {@code true} if any "to" rows were deleted, {@code false} + * otherwise + */ + public boolean deleteRows(Map<String,?> fromRow) throws IOException { + boolean removed = false; + for(Iterator<Map<String,Object>> iter = findRows( + fromRow, Collections.<String>emptySet()); iter.hasNext(); ) { + iter.next(); + iter.remove(); + removed = true; + } + return removed; + } + + /** * Fills in the _entryValues with the relevant info from the given "from" * table row. */ |