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>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/mysql-jdbc-5.0.8.jar"/>
|
<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/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/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"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</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
|
@Override
|
||||||
public void renameKey(final String oldKey, final String newKey) throws Exception {
|
public void renameKey(final String oldKey, final String newKey) throws Exception {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
|
@ -1987,31 +1987,25 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
@Override
|
@Override
|
||||||
public void remove(final String key) throws SQLException {
|
public void remove(final String key) throws SQLException {
|
||||||
//
|
//
|
||||||
Element element = getElement(key);
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
if (element == null) {
|
ResultSet resultSet = null;
|
||||||
throw new NullPointerException("Undefined element [key=" + key + "]");
|
try {
|
||||||
} else {
|
|
||||||
//
|
//
|
||||||
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");
|
||||||
|
|
||||||
//
|
statement.setString(1, key);
|
||||||
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, element.getKey());
|
int rowCount = statement.executeUpdate();
|
||||||
|
|
||||||
statement.executeUpdate();
|
if (rowCount == 0) {
|
||||||
|
logger.warn("Remove action without existing target [key=" + key + "]");
|
||||||
} finally {
|
|
||||||
close(connection, statement, resultSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2021,31 +2015,25 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
@Override
|
@Override
|
||||||
public void remove(final String key, final String subkey) throws SQLException {
|
public void remove(final String key, final String subkey) throws SQLException {
|
||||||
//
|
//
|
||||||
Element element = getElement(key, subkey);
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
if (element == null) {
|
ResultSet resultSet = null;
|
||||||
throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]");
|
try {
|
||||||
} else {
|
|
||||||
//
|
//
|
||||||
element.archive();
|
connection = getConnection();
|
||||||
|
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||||
|
|
||||||
//
|
statement.setString(1, key);
|
||||||
Connection connection = null;
|
statement.setString(2, subkey);
|
||||||
PreparedStatement statement = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
connection = getConnection();
|
|
||||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=?");
|
|
||||||
|
|
||||||
statement.setString(1, element.getKey());
|
int rowCount = statement.executeUpdate();
|
||||||
statement.setString(2, element.getSubkey());
|
|
||||||
|
|
||||||
statement.executeUpdate();
|
if (rowCount == 0) {
|
||||||
|
logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]");
|
||||||
} finally {
|
|
||||||
close(connection, statement, resultSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} 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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -126,6 +126,8 @@ public interface SikevaDB {
|
||||||
|
|
||||||
public void removeAll(final String key) throws Exception;
|
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 renameKey(final String oldKey, final String newKey) throws Exception;
|
||||||
|
|
||||||
public void replaceInValue(final String key, final String... tokens) throws Exception;
|
public void replaceInValue(final String key, final String... tokens) throws Exception;
|
||||||
|
|
|
@ -529,6 +529,41 @@ public class SQLSikevaDBTest {
|
||||||
logger.debug("===== test done.");
|
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
|
* @throws Exception
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue