Fix auto commit issues. Fix null issues. Add test.
This commit is contained in:
parent
adf0f3a86c
commit
99377b9f8f
16 changed files with 1146 additions and 270 deletions
|
@ -4,7 +4,7 @@
|
||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar"/>
|
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
|
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
|
<classpathentry kind="lib" path="lib/junit-4.11.jar" sourcepath="lib/junit-4.11-sources.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
|
<classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
|
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
|
||||||
|
@ -21,5 +21,6 @@
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/devinsy-utils-0.2.4.jar"/>
|
<classpathentry kind="lib" path="lib/devinsy-utils-0.2.4.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/mysql-jdbc-5.0.8.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/mysql-jdbc-5.0.8.jar
Normal file
BIN
lib/mysql-jdbc-5.0.8.jar
Normal file
Binary file not shown.
|
@ -49,8 +49,7 @@ public class Element {
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public Element(final String key, final String subkey, final String value) {
|
public Element(final String key, final String subkey, final String value) {
|
||||||
updateValue(value);
|
update(value);
|
||||||
this.creationDate = this.editionDate;
|
|
||||||
this.archiveDate = null;
|
this.archiveDate = null;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.subkey = subkey;
|
this.subkey = subkey;
|
||||||
|
@ -127,9 +126,14 @@ public class Element {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateValue(final String value) {
|
public void update(final String value) {
|
||||||
|
//
|
||||||
setValue(value);
|
setValue(value);
|
||||||
|
|
||||||
|
//
|
||||||
this.editionDate = new Date();
|
this.editionDate = new Date();
|
||||||
|
|
||||||
|
//
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.digest = null;
|
this.digest = null;
|
||||||
|
@ -137,5 +141,10 @@ public class Element {
|
||||||
this.size = this.value.length();
|
this.size = this.value.length();
|
||||||
this.digest = DigestUtils.md5Hex(this.value);
|
this.digest = DigestUtils.md5Hex(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (this.creationDate == null) {
|
||||||
|
this.creationDate = this.editionDate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package fr.devinsy.sikevadb;
|
package fr.devinsy.sikevadb;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import fr.devinsy.util.StringList;
|
import fr.devinsy.util.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +45,30 @@ public class FileSikevaDB implements SikevaDB {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAllArchive() throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearArchive(final Date beforeDate) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearArchive(final int maxDays) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearDatabase() throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -115,6 +141,18 @@ public class FileSikevaDB implements SikevaDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringList getAllKeys() throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringList getAllSubkeys(final String key) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringList getAllValues(final String key) {
|
public StringList getAllValues(final String key) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -163,6 +201,18 @@ public class FileSikevaDB implements SikevaDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringList getKeys() throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringList getSubkeys(final String key) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(final String key) throws Exception {
|
public String getValue(final String key) throws Exception {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -240,4 +290,10 @@ public class FileSikevaDB implements SikevaDB {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAll(final String key) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,34 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void archive(final String key) throws SQLException {
|
public void archive(final String key) throws SQLException {
|
||||||
archive(key, null);
|
//
|
||||||
|
Element element = getElement(key);
|
||||||
|
|
||||||
|
if (element == null) {
|
||||||
|
throw new NullPointerException("Undefined element [key=" + key + "]");
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
element.archive();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL");
|
||||||
|
|
||||||
|
statement.setDate(1, dateToDate(element.getArchiveDate()));
|
||||||
|
statement.setString(2, element.getKey());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,9 +121,12 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void archive(final String key, final String subkey) throws SQLException {
|
public void archive(final String key, final String subkey) throws SQLException {
|
||||||
|
|
||||||
//
|
//
|
||||||
Element element = getElement(key, null);
|
if (subkey == null) {
|
||||||
|
archive(key);
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
Element element = getElement(key, subkey);
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]");
|
throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]");
|
||||||
|
@ -111,19 +141,106 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?");
|
||||||
|
|
||||||
statement.setDate(1, dateToDate(element.getArchiveDate()));
|
statement.setDate(1, dateToDate(element.getArchiveDate()));
|
||||||
statement.setString(2, element.getKey());
|
statement.setString(2, element.getKey());
|
||||||
statement.setString(3, element.getSubkey());
|
statement.setString(3, element.getSubkey());
|
||||||
|
|
||||||
statement.executeQuery();
|
statement.executeUpdate();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearAllArchive() throws SQLException {
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("DELETE FROM elements WHERE ARCHIVE_DATE IS NOT NULL");
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearArchive(final Date beforeDate) throws SQLException {
|
||||||
|
if (beforeDate == null) {
|
||||||
|
throw new NullPointerException("beforeDate is null.");
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("DELETE FROM elements WHERE ARCHIVE_DATE<?");
|
||||||
|
|
||||||
|
statement.setDate(1, dateToDate(beforeDate));
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearArchive(final int maxDays) throws SQLException {
|
||||||
|
if (maxDays < 0) {
|
||||||
|
throw new IndexOutOfBoundsException("maxDays is negative.");
|
||||||
|
} else {
|
||||||
|
Date beforeDate = new Date(new Date().getTime() + maxDays * 24 * 60 * 60 * 1000);
|
||||||
|
clearArchive(beforeDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearDatabase() throws Exception {
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("DELETE FROM elements");
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -217,6 +334,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE AND TOPKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE AND TOPKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -239,11 +357,16 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public long countOfAllElements(final String key, final String subkey) throws SQLException {
|
public long countOfAllElements(final String key, final String subkey) throws SQLException {
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = countOfAllElements(key);
|
||||||
|
} else {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -255,6 +378,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -272,6 +396,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
resultSet = statement.executeQuery("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL");
|
resultSet = statement.executeQuery("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL");
|
||||||
|
|
||||||
|
@ -298,6 +423,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -320,11 +446,16 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public long countOfArchivedElements(final String key, final String subkey) throws SQLException {
|
public long countOfArchivedElements(final String key, final String subkey) throws SQLException {
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = countOfArchivedElements(key);
|
||||||
|
} else {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -336,6 +467,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -355,6 +487,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
resultSet = statement.executeQuery("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL");
|
resultSet = statement.executeQuery("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL");
|
||||||
|
|
||||||
|
@ -383,6 +516,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -405,11 +539,16 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public long countOfElements(final String key, final String subkey) throws SQLException {
|
public long countOfElements(final String key, final String subkey) throws SQLException {
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = countOfElements(key);
|
||||||
|
} else {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -421,6 +560,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -442,6 +582,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -478,6 +619,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public Elements getAllElements(final String key, final String subkey) throws SQLException {
|
public Elements getAllElements(final String key, final String subkey) throws SQLException {
|
||||||
Elements result;
|
Elements result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getAllElements(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
result = new Elements((int) countOfAllElements(key, subkey));
|
result = new Elements((int) countOfAllElements(key, subkey));
|
||||||
|
|
||||||
|
@ -487,6 +632,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -512,6 +658,74 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public StringList getAllKeys() throws SQLException {
|
||||||
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = new StringList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("SELECT DISTINCT TOPKEY FROM elements ORDER BY CREATION_DATE ASC");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
//
|
||||||
|
result.add(resultSet.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public StringList getAllSubkeys(final String key) throws SQLException {
|
||||||
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = new StringList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("SELECT DISTINCT SUBKEY FROM elements WHERE KEY=? ORDER BY CREATION_DATE ASC");
|
||||||
|
statement.setString(1, key);
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
//
|
||||||
|
result.add(resultSet.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -533,6 +747,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -557,6 +772,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public StringList getAllValues(final String key, final String subkey) throws SQLException {
|
public StringList getAllValues(final String key, final String subkey) throws SQLException {
|
||||||
StringList result;
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getAllValues(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
result = new StringList((int) countOfAllElements(key, subkey));
|
result = new StringList((int) countOfAllElements(key, subkey));
|
||||||
|
|
||||||
|
@ -566,6 +785,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -579,6 +799,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -600,6 +821,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -624,6 +846,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public StringList getArchivedValues(final String key, final String subkey) throws SQLException {
|
public StringList getArchivedValues(final String key, final String subkey) throws SQLException {
|
||||||
StringList result;
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getArchivedValues(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
result = new StringList((int) countOfArchivedElements(key, subkey));
|
result = new StringList((int) countOfArchivedElements(key, subkey));
|
||||||
|
|
||||||
|
@ -633,6 +859,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -647,6 +874,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -694,8 +922,9 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NULL");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
@ -717,7 +946,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
|
|
||||||
//
|
//
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
throw new SQLException("More than only once result.");
|
throw new SQLException("More than only once result [key=" + key + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -735,6 +964,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public Element getElement(final String key, final String subkey) throws SQLException {
|
public Element getElement(final String key, final String subkey) throws SQLException {
|
||||||
Element result;
|
Element result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getElement(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
@ -742,8 +975,9 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -772,6 +1006,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -793,6 +1028,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE ASC");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -829,6 +1065,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public Elements getElements(final String key, final String subkey) throws SQLException {
|
public Elements getElements(final String key, final String subkey) throws SQLException {
|
||||||
Elements result;
|
Elements result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getElements(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
result = new Elements((int) countOfElements(key, subkey));
|
result = new Elements((int) countOfElements(key, subkey));
|
||||||
|
|
||||||
|
@ -838,6 +1078,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY CREATION_DATE ASC");
|
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY CREATION_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -863,6 +1104,40 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public StringList getKeys() throws SQLException {
|
||||||
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = new StringList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("SELECT DISTINCT TOPKEY FROM elements WHERE ARCHIVE_DATE IS NULL ORDER BY CREATION_DATE ASC");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
//
|
||||||
|
result.add(resultSet.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -876,6 +1151,40 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public StringList getSubkeys(final String key) throws SQLException {
|
||||||
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = new StringList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("SELECT DISTINCT SUBKEY FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? ORDER BY CREATION_DATE ASC");
|
||||||
|
statement.setString(1, key);
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
//
|
||||||
|
result.add(resultSet.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -894,6 +1203,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -926,6 +1236,9 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public String getValue(final String key, final String subkey) throws SQLException {
|
public String getValue(final String key, final String subkey) throws SQLException {
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getValue(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
@ -933,6 +1246,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -954,6 +1268,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -975,6 +1290,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
statement = connection.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -999,6 +1315,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public StringList getValues(final String key, final String subkey) throws SQLException {
|
public StringList getValues(final String key, final String subkey) throws SQLException {
|
||||||
StringList result;
|
StringList result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = getValues(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
result = new StringList((int) countOfElements(key, subkey));
|
result = new StringList((int) countOfElements(key, subkey));
|
||||||
|
|
||||||
|
@ -1008,6 +1328,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
.prepareStatement("SELECT VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
|
@ -1022,6 +1343,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -1040,6 +1362,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements");
|
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
@ -1067,6 +1390,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE TOPKEY=?");
|
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE TOPKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
@ -1089,12 +1413,17 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
public long memorySize(final String key, final String subkey) throws SQLException {
|
public long memorySize(final String key, final String subkey) throws SQLException {
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (subkey == null) {
|
||||||
|
result = memorySize(key);
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE TOPKEY=? AND SUBKEY=?");
|
||||||
statement.setString(1, key);
|
statement.setString(1, key);
|
||||||
statement.setString(2, subkey);
|
statement.setString(2, subkey);
|
||||||
|
@ -1106,6 +1435,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -1143,8 +1473,9 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(1, 2, 3, 4, 5,6,7,8)");
|
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
statement.setString(1, element.getKey());
|
statement.setString(1, element.getKey());
|
||||||
statement.setString(2, element.getSubkey());
|
statement.setString(2, element.getSubkey());
|
||||||
|
@ -1155,7 +1486,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||||
statement.setString(8, element.getValue());
|
statement.setString(8, element.getValue());
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
statement.executeUpdate();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
|
@ -1167,7 +1498,64 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void put(final String key, final String value) throws SQLException {
|
public void put(final String key, final String value) throws SQLException {
|
||||||
put(key, null, value);
|
Element element = getElement(key);
|
||||||
|
|
||||||
|
if (element == null) {
|
||||||
|
//
|
||||||
|
element = new Element();
|
||||||
|
element.setKey(key);
|
||||||
|
element.update(value);
|
||||||
|
element.setArchiveDate(null);
|
||||||
|
|
||||||
|
//
|
||||||
|
put(element);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
element.update(value);
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
|
||||||
|
// Archive existing element.
|
||||||
|
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL");
|
||||||
|
|
||||||
|
statement.setDate(1, dateToDate(element.getEditionDate()));
|
||||||
|
statement.setString(2, element.getKey());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.clearParameters();
|
||||||
|
|
||||||
|
// Insert new version of the element.
|
||||||
|
statement.clearParameters();
|
||||||
|
statement = connection
|
||||||
|
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
|
statement.setString(1, element.getKey());
|
||||||
|
statement.setString(2, element.getSubkey());
|
||||||
|
statement.setLong(3, element.getSize());
|
||||||
|
statement.setString(4, element.getDigest());
|
||||||
|
statement.setDate(5, dateToDate(element.getCreationDate()));
|
||||||
|
statement.setDate(6, dateToDate(element.getEditionDate()));
|
||||||
|
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||||
|
statement.setString(8, element.getValue());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
connection.commit();
|
||||||
|
|
||||||
|
} catch (Exception exception) {
|
||||||
|
connection.rollback();
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1175,13 +1563,25 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void put(final String key, final String subkey, final String value) throws SQLException {
|
public void put(final String key, final String subkey, final String value) throws SQLException {
|
||||||
Element element = getElement(key, null);
|
|
||||||
|
|
||||||
|
//
|
||||||
|
Element element = getElement(key, subkey);
|
||||||
|
|
||||||
|
//
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
|
//
|
||||||
|
element = new Element();
|
||||||
|
element.setKey(key);
|
||||||
|
element.setSubkey(subkey);
|
||||||
|
element.update(value);
|
||||||
|
element.setArchiveDate(null);
|
||||||
|
|
||||||
|
//
|
||||||
|
put(element);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
element.updateValue(value);
|
element.update(value);
|
||||||
|
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
|
@ -1199,13 +1599,13 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
statement.setString(2, element.getKey());
|
statement.setString(2, element.getKey());
|
||||||
statement.setString(3, element.getSubkey());
|
statement.setString(3, element.getSubkey());
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
statement.executeUpdate();
|
||||||
statement.clearParameters();
|
statement.clearParameters();
|
||||||
|
|
||||||
// Insert new version of the element.
|
// Insert new version of the element.
|
||||||
statement.clearParameters();
|
statement.clearParameters();
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(1, 2, 3, 4, 5,6,7,8)");
|
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
statement.setString(1, element.getKey());
|
statement.setString(1, element.getKey());
|
||||||
statement.setString(2, element.getSubkey());
|
statement.setString(2, element.getSubkey());
|
||||||
|
@ -1216,12 +1616,13 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||||
statement.setString(8, element.getValue());
|
statement.setString(8, element.getValue());
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
statement.executeUpdate();
|
||||||
|
|
||||||
connection.commit();
|
connection.commit();
|
||||||
|
|
||||||
} finally {
|
} catch (Exception exception) {
|
||||||
connection.rollback();
|
connection.rollback();
|
||||||
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1231,8 +1632,34 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void remove(final String key) throws Exception {
|
public void remove(final String key) throws SQLException {
|
||||||
remove(key, null);
|
//
|
||||||
|
Element element = getElement(key);
|
||||||
|
|
||||||
|
if (element == null) {
|
||||||
|
throw new NullPointerException("Undefined element [key=" + key + "]");
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
element.archive();
|
||||||
|
|
||||||
|
//
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("DELETE FROM elements WHERE TOPKEY=? AND SUBKEY IS NULL");
|
||||||
|
|
||||||
|
statement.setString(1, element.getKey());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1240,9 +1667,8 @@ 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, null);
|
Element element = getElement(key, subkey);
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]");
|
throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]");
|
||||||
|
@ -1257,12 +1683,46 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
statement = connection.prepareStatement("DELETE FROM elements WHERE WHERE TOPKEY=? AND SUBKEY=?");
|
statement = connection.prepareStatement("DELETE FROM elements WHERE TOPKEY=? AND SUBKEY=?");
|
||||||
|
|
||||||
statement.setString(1, element.getKey());
|
statement.setString(1, element.getKey());
|
||||||
statement.setString(2, element.getSubkey());
|
statement.setString(2, element.getSubkey());
|
||||||
|
|
||||||
statement.executeQuery();
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
close(connection, statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void removeAll(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;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
connection = getConnection();
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
statement = connection.prepareStatement("DELETE FROM elements WHERE TOPKEY=? AND SUBKEY IS NOT NULL");
|
||||||
|
|
||||||
|
statement.setString(1, element.getKey());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
close(connection, statement, resultSet);
|
close(connection, statement, resultSet);
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package fr.devinsy.sikevadb;
|
package fr.devinsy.sikevadb;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import fr.devinsy.util.StringList;
|
import fr.devinsy.util.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +32,14 @@ public interface SikevaDB {
|
||||||
|
|
||||||
public void archive(final String key, final String subkey) throws Exception;
|
public void archive(final String key, final String subkey) throws Exception;
|
||||||
|
|
||||||
|
public void clearAllArchive() throws Exception;
|
||||||
|
|
||||||
|
public void clearArchive(final Date beforeDate) throws Exception;
|
||||||
|
|
||||||
|
public void clearArchive(final int maxDays) throws Exception;
|
||||||
|
|
||||||
|
public void clearDatabase() throws Exception;
|
||||||
|
|
||||||
public void close() throws Exception;
|
public void close() throws Exception;
|
||||||
|
|
||||||
public long countOfAllElements() throws Exception;
|
public long countOfAllElements() throws Exception;
|
||||||
|
@ -54,6 +64,10 @@ public interface SikevaDB {
|
||||||
|
|
||||||
public Elements getAllElements(String key, String subkey) throws Exception;
|
public Elements getAllElements(String key, String subkey) throws Exception;
|
||||||
|
|
||||||
|
public StringList getAllKeys() throws Exception;
|
||||||
|
|
||||||
|
public StringList getAllSubkeys(String key) throws Exception;
|
||||||
|
|
||||||
public StringList getAllValues(String key) throws Exception;
|
public StringList getAllValues(String key) throws Exception;
|
||||||
|
|
||||||
public StringList getAllValues(String key, String subkey) throws Exception;
|
public StringList getAllValues(String key, String subkey) throws Exception;
|
||||||
|
@ -70,6 +84,10 @@ public interface SikevaDB {
|
||||||
|
|
||||||
public Elements getElements(String key, String subkey) throws Exception;
|
public Elements getElements(String key, String subkey) throws Exception;
|
||||||
|
|
||||||
|
public StringList getKeys() throws Exception;
|
||||||
|
|
||||||
|
public StringList getSubkeys(String key) throws Exception;
|
||||||
|
|
||||||
public String getValue(String key) throws Exception;
|
public String getValue(String key) throws Exception;
|
||||||
|
|
||||||
public String getValue(String key, String subkey) throws Exception;
|
public String getValue(String key, String subkey) throws Exception;
|
||||||
|
@ -95,4 +113,6 @@ public interface SikevaDB {
|
||||||
public void remove(final String key) throws Exception;
|
public void remove(final String key) throws Exception;
|
||||||
|
|
||||||
public void remove(final String key, final String subkey) throws Exception;
|
public void remove(final String key, final String subkey) throws Exception;
|
||||||
|
|
||||||
|
public void removeAll(final String key) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,16 +37,16 @@ public class SikevaDBFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param host
|
* @param driverClassName
|
||||||
* @param port
|
* @param url
|
||||||
* @param login
|
* @param login
|
||||||
* @param password
|
* @param password
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static SikevaDB get(final String host, final String port, final String login, final String password) {
|
public static SikevaDB get(final String driverClassName, final String url, final String login, final String password) {
|
||||||
SikevaDB result;
|
SikevaDB result;
|
||||||
|
|
||||||
result = new SQLSikevaDB(host, port, login, password);
|
result = new SQLSikevaDB(driverClassName, url, login, password);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package fr.devinsy.sikevadb;
|
|
||||||
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Christian P. Momon
|
|
||||||
*/
|
|
||||||
public class AlphaTest {
|
|
||||||
static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AlphaTest.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
Logger.getRootLogger().setLevel(Level.ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testFoo01() {
|
|
||||||
//
|
|
||||||
logger.debug("===== test starting...");
|
|
||||||
|
|
||||||
//
|
|
||||||
Assert.assertEquals('a', 'a');
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.debug("===== test done.");
|
|
||||||
}
|
|
||||||
}
|
|
358
test/fr/devinsy/sikevadb/SQLSikevaDBTest.java
Normal file
358
test/fr/devinsy/sikevadb/SQLSikevaDBTest.java
Normal file
|
@ -0,0 +1,358 @@
|
||||||
|
package fr.devinsy.sikevadb;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Level;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import fr.devinsy.util.StringList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?profileSQL=true
|
||||||
|
*
|
||||||
|
* @author Christian P. Momon
|
||||||
|
*/
|
||||||
|
public class SQLSikevaDBTest {
|
||||||
|
static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SQLSikevaDBTest.class);
|
||||||
|
private SQLSikevaDB database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@After
|
||||||
|
public void after() {
|
||||||
|
if (this.database != null) {
|
||||||
|
this.database.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws NamingException
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
* @throws InstantiationException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void before() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
Logger.getRootLogger().setLevel(Level.ERROR);
|
||||||
|
|
||||||
|
this.database = new SQLSikevaDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/sikevadb-test", "sikevadb-test", "12345678");
|
||||||
|
this.database.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testClearArchive01() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
Element element = new Element();
|
||||||
|
|
||||||
|
element.setKey("alpha");
|
||||||
|
element.setSubkey(null);
|
||||||
|
element.setSize(10);
|
||||||
|
element.setDigest("qsdkfqskjf");
|
||||||
|
element.setCreationDate(new Date());
|
||||||
|
element.setEditionDate(new Date());
|
||||||
|
element.setArchiveDate(new Date(new Date().getTime() - 10 * 24 * 60 * 60 * 1000));
|
||||||
|
element.setValue("bonjour");
|
||||||
|
|
||||||
|
database.put(element);
|
||||||
|
|
||||||
|
database.put("alpha", "bravo", "toto");
|
||||||
|
|
||||||
|
database.clearArchive(5);
|
||||||
|
|
||||||
|
Assert.assertEquals(1, database.countOfElements());
|
||||||
|
Assert.assertEquals(0, database.countOfArchivedElements());
|
||||||
|
Assert.assertEquals(1, database.countOfAllElements());
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testClearArchive02() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
Element element = new Element();
|
||||||
|
|
||||||
|
element.setKey("alpha");
|
||||||
|
element.setSubkey(null);
|
||||||
|
element.setSize(10);
|
||||||
|
element.setDigest("qsdkfqskjf");
|
||||||
|
element.setCreationDate(new Date());
|
||||||
|
element.setEditionDate(new Date());
|
||||||
|
element.setArchiveDate(new Date(new Date().getTime() - 10 * 24 * 60 * 60 * 1000));
|
||||||
|
element.setValue("bonjour");
|
||||||
|
|
||||||
|
database.put(element);
|
||||||
|
|
||||||
|
database.put("alpha", "bravo", "toto");
|
||||||
|
|
||||||
|
database.clearArchive(new Date(new Date().getTime() - 5 * 24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
|
Assert.assertEquals(1, database.countOfElements());
|
||||||
|
Assert.assertEquals(0, database.countOfArchivedElements());
|
||||||
|
Assert.assertEquals(1, database.countOfAllElements());
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut01() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", source);
|
||||||
|
String target = database.getValue("alpha01");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut02() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha01");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
target = database.getValue("alpha01", null);
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut03() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", null, source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha01");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
target = database.getValue("alpha01", null);
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut04() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha02", "bravo", source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha02", "bravo");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut05() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha01");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
String source2 = "au revoir";
|
||||||
|
database.put("alpha01", source2);
|
||||||
|
|
||||||
|
target = database.getValue("alpha01");
|
||||||
|
Assert.assertEquals(source2, target);
|
||||||
|
|
||||||
|
StringList targets = database.getArchivedValues("alpha01");
|
||||||
|
Assert.assertEquals(1, targets.size());
|
||||||
|
Assert.assertEquals(source, targets.get(0));
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPut06() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", "bravo", source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
String source2 = "au revoir";
|
||||||
|
database.put("alpha01", "bravo", source2);
|
||||||
|
|
||||||
|
target = database.getValue("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(source2, target);
|
||||||
|
|
||||||
|
StringList targets = database.getArchivedValues("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(1, targets.size());
|
||||||
|
Assert.assertEquals(source, targets.get(0));
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testRemove01() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
String source = "bonjour";
|
||||||
|
database.put("alpha01", "bravo", source);
|
||||||
|
|
||||||
|
String target = database.getValue("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(source, target);
|
||||||
|
|
||||||
|
String source2 = "au revoir";
|
||||||
|
database.put("alpha01", "bravo", source2);
|
||||||
|
|
||||||
|
target = database.getValue("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(source2, target);
|
||||||
|
|
||||||
|
StringList targets = database.getArchivedValues("alpha01", "bravo");
|
||||||
|
Assert.assertEquals(1, targets.size());
|
||||||
|
Assert.assertEquals(source, targets.get(0));
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSize01() throws Exception {
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
Assert.assertEquals(0, database.countOfElements());
|
||||||
|
Assert.assertEquals(0, database.countOfArchivedElements());
|
||||||
|
Assert.assertEquals(0, database.countOfAllElements());
|
||||||
|
|
||||||
|
database.put("alpha01", "qlskjfmlqja");
|
||||||
|
database.put("alpha01", "qlskjfmlqjb");
|
||||||
|
database.put("alpha02", "qlskjfmlqj");
|
||||||
|
database.put("alpha03", "qlskjfmlqj");
|
||||||
|
database.put("alpha04", "qlskjfmlqj");
|
||||||
|
database.put("alpha05", "qlskjfmlqj");
|
||||||
|
database.archive("alpha02");
|
||||||
|
database.remove("alpha03");
|
||||||
|
database.put("alpha01", "bravo1", "qlskjfmlqja");
|
||||||
|
database.put("alpha01", "bravo1", "qlskjfmlqjb");
|
||||||
|
database.put("alpha01", "bravo2", "qlskjfmlqj");
|
||||||
|
database.put("alpha01", "bravo3", "qlskjfmlqj");
|
||||||
|
database.put("alpha01", "bravo4", "qlskjfmlqj");
|
||||||
|
database.put("alpha01", "bravo5", "qlskjfmlqj");
|
||||||
|
database.archive("alpha01", "bravo2");
|
||||||
|
database.remove("alpha01", "bravo3");
|
||||||
|
|
||||||
|
// System.out.println(database.countOfElements() + " " +
|
||||||
|
// database.countOfArchivedElements() + " " +
|
||||||
|
// database.countOfAllElements());
|
||||||
|
|
||||||
|
Assert.assertEquals(6, database.countOfElements());
|
||||||
|
Assert.assertEquals(4, database.countOfArchivedElements());
|
||||||
|
Assert.assertEquals(10, database.countOfAllElements());
|
||||||
|
|
||||||
|
database.clearDatabase();
|
||||||
|
|
||||||
|
Assert.assertEquals(0, database.countOfElements());
|
||||||
|
Assert.assertEquals(0, database.countOfArchivedElements());
|
||||||
|
Assert.assertEquals(0, database.countOfAllElements());
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
test/fr/devinsy/sikevadb/data.xml
Normal file
12
test/fr/devinsy/sikevadb/data.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<dataset>
|
||||||
|
<ELEMENTS
|
||||||
|
TOPKEY="alpha"
|
||||||
|
SUBKEY=NULL
|
||||||
|
SIZE="10"
|
||||||
|
DIGEST="7c12772809c1c0c3deda6103b10fdfa0"
|
||||||
|
CREATION_DATE="2013-01-01 18:00:00.000"
|
||||||
|
EDITION_DATE="2013-01-01 18:00:00.000"
|
||||||
|
ARCHIVE_DATE="2013-01-01 18:00:00.000"
|
||||||
|
VALUE="1234567890"
|
||||||
|
/>
|
||||||
|
</dataset>
|
Loading…
Reference in a new issue