diff --git a/.classpath b/.classpath index c5c9f50..3400f50 100644 --- a/.classpath +++ b/.classpath @@ -21,8 +21,8 @@ - + diff --git a/lib/devinsy-utils-0.2.6-sources.zip b/lib/devinsy-utils-0.2.12-sources.zip similarity index 69% rename from lib/devinsy-utils-0.2.6-sources.zip rename to lib/devinsy-utils-0.2.12-sources.zip index 639aa1b..3cbd960 100644 Binary files a/lib/devinsy-utils-0.2.6-sources.zip and b/lib/devinsy-utils-0.2.12-sources.zip differ diff --git a/lib/devinsy-utils-0.2.6.jar b/lib/devinsy-utils-0.2.12.jar similarity index 65% rename from lib/devinsy-utils-0.2.6.jar rename to lib/devinsy-utils-0.2.12.jar index 18a4d59..7b46e1e 100644 Binary files a/lib/devinsy-utils-0.2.6.jar and b/lib/devinsy-utils-0.2.12.jar differ diff --git a/src/fr/devinsy/sikevadb/FileSikevaDB.java b/src/fr/devinsy/sikevadb/FileSikevaDB.java index 6da6ff1..d8ae90f 100644 --- a/src/fr/devinsy/sikevadb/FileSikevaDB.java +++ b/src/fr/devinsy/sikevadb/FileSikevaDB.java @@ -337,6 +337,12 @@ public class FileSikevaDB implements SikevaDB { } + @Override + public void removeMany(final String key, final String... subkeys) throws Exception { + // TODO Auto-generated method stub + + } + @Override public void renameKey(final String oldKey, final String newKey) throws Exception { // TODO Auto-generated method stub diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/SQLSikevaDB.java index af84cae..97d3933 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDB.java @@ -1987,31 +1987,25 @@ public class SQLSikevaDB implements SikevaDB { @Override public void remove(final String key) throws SQLException { // - Element element = getElement(key); - - if (element == null) { - throw new NullPointerException("Undefined element [key=" + key + "]"); - } else { + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { // - element.archive(); + connection = getConnection(); + connection.setAutoCommit(true); + statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL"); - // - Connection connection = null; - PreparedStatement statement = null; - ResultSet resultSet = null; - try { - // - connection = getConnection(); - connection.setAutoCommit(true); - statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL"); + statement.setString(1, key); - statement.setString(1, element.getKey()); + int rowCount = statement.executeUpdate(); - statement.executeUpdate(); - - } finally { - close(connection, statement, resultSet); + if (rowCount == 0) { + logger.warn("Remove action without existing target [key=" + key + "]"); } + + } finally { + close(connection, statement, resultSet); } } @@ -2021,31 +2015,25 @@ public class SQLSikevaDB implements SikevaDB { @Override public void remove(final String key, final String subkey) throws SQLException { // - Element element = getElement(key, subkey); - - if (element == null) { - throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]"); - } else { + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { // - element.archive(); + connection = getConnection(); + statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL"); - // - Connection connection = null; - PreparedStatement statement = null; - ResultSet resultSet = null; - try { - // - connection = getConnection(); - statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=?"); + statement.setString(1, key); + statement.setString(2, subkey); - statement.setString(1, element.getKey()); - statement.setString(2, element.getSubkey()); + int rowCount = statement.executeUpdate(); - statement.executeUpdate(); - - } finally { - close(connection, statement, resultSet); + if (rowCount == 0) { + logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]"); } + + } finally { + close(connection, statement, resultSet); } } @@ -2083,6 +2071,45 @@ public class SQLSikevaDB implements SikevaDB { } } + /** + * {@inheritDoc} + */ + @Override + public void removeMany(final String key, final String... subkeys) throws SQLException { + // + if ((subkeys != null) && (subkeys.length > 0)) { + // + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + // + connection = getConnection(); + + // + String questionMarks = new StringList(subkeys.length).append('?').repeatLast(subkeys.length - 1).toStringWithCommas(); + statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IN (" + questionMarks + + ") AND ARCHIVE_DATE IS NULL"); + // + statement.setString(1, key); + + // + for (int index = 0; index < subkeys.length; index++) { + statement.setString(2 + index, subkeys[index]); + } + + // + int rowCount = statement.executeUpdate(); + if (rowCount == 0) { + logger.warn("Remove action without existing target [key=" + key + "][subkeys=" + new StringList(subkeys).toStringWithCommas() + "]"); + } + + } finally { + close(connection, statement, resultSet); + } + } + } + /** * {@inheritDoc} */ diff --git a/src/fr/devinsy/sikevadb/SikevaDB.java b/src/fr/devinsy/sikevadb/SikevaDB.java index c99a971..4a8ccf8 100644 --- a/src/fr/devinsy/sikevadb/SikevaDB.java +++ b/src/fr/devinsy/sikevadb/SikevaDB.java @@ -126,6 +126,8 @@ public interface SikevaDB { public void removeAll(final String key) throws Exception; + public void removeMany(final String key, final String... subkeys) throws Exception; + public void renameKey(final String oldKey, final String newKey) throws Exception; public void replaceInValue(final String key, final String... tokens) throws Exception; diff --git a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java index 3e89ada..ff2922d 100644 --- a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java +++ b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java @@ -529,6 +529,41 @@ public class SQLSikevaDBTest { logger.debug("===== test done."); } + /** + * @throws Exception + * + */ + @Test + public void testRemoveMany01() throws Exception { + // + logger.debug("===== test starting..."); + + database.clearDatabase(); + + database.put("alpha01", "alpha", "Allo"); + database.put("alpha01", "bravo", "Bonjour"); + database.put("alpha01", "charlie", "Courage"); + database.put("alpha01", "delta", "Droiture"); + database.put("alpha01", "echo", "Europe"); + database.put("alpha01", "fox", "Force"); + + database.put("alpha02", "alpha", "Allo"); + database.put("alpha02", "bravo", "Bonjour"); + database.put("alpha02", "charlie", "Courage"); + database.put("alpha02", "delta", "Droiture"); + database.put("alpha02", "echo", "Europe"); + database.put("alpha02", "fox", "Force"); + + Assert.assertEquals(12, database.countOfElements()); + + database.removeMany("alpha01", "bravo", "delta", "fox"); + + Assert.assertEquals(9, database.countOfElements()); + + // + logger.debug("===== test done."); + } + /** * @throws Exception *