Restrict targets in remove method. Add removeMany method and test.
Update devinsy-utils library.
This commit is contained in:
parent
ae511ea528
commit
9c0026da51
7 changed files with 111 additions and 41 deletions
|
@ -21,8 +21,8 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/mysql-jdbc-5.0.8.jar"/>
|
||||
<classpathentry kind="lib" path="lib/devinsy-utils-0.2.6.jar" sourcepath="lib/devinsy-utils-0.2.6-sources.zip"/>
|
||||
<classpathentry kind="lib" path="lib/joda-time-2.3.jar" sourcepath="lib/joda-time-2.3-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/hsqldb-2.3.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/devinsy-utils-0.2.12.jar" sourcepath="lib/devinsy-utils-0.2.12-sources.zip"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -1986,15 +1986,6 @@ 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 {
|
||||
//
|
||||
element.archive();
|
||||
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
@ -2003,32 +1994,26 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
//
|
||||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL");
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, element.getKey());
|
||||
statement.setString(1, key);
|
||||
|
||||
statement.executeUpdate();
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0) {
|
||||
logger.warn("Remove action without existing target [key=" + key + "]");
|
||||
}
|
||||
|
||||
} finally {
|
||||
close(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@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 {
|
||||
//
|
||||
element.archive();
|
||||
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
@ -2036,18 +2021,21 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
try {
|
||||
//
|
||||
connection = getConnection();
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=?");
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, element.getKey());
|
||||
statement.setString(2, element.getSubkey());
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
|
||||
statement.executeUpdate();
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0) {
|
||||
logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]");
|
||||
}
|
||||
|
||||
} finally {
|
||||
close(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -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}
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue