Improve code design.
This commit is contained in:
parent
4b211d8190
commit
bdc7359b79
1 changed files with 71 additions and 69 deletions
|
@ -1690,8 +1690,11 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
*/
|
||||
@Override
|
||||
public void put(final String key, final String value) throws SQLException {
|
||||
|
||||
//
|
||||
Element element = getElement(key);
|
||||
|
||||
//
|
||||
if (element == null) {
|
||||
//
|
||||
element = new Element();
|
||||
|
@ -1699,12 +1702,10 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
element.update(value);
|
||||
element.setArchiveDate(null);
|
||||
|
||||
//
|
||||
put(element);
|
||||
|
||||
} else {
|
||||
//
|
||||
element.update(value);
|
||||
}
|
||||
|
||||
//
|
||||
Connection connection = null;
|
||||
|
@ -1716,16 +1717,19 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection.setAutoCommit(false);
|
||||
|
||||
// Archive existing element.
|
||||
statement = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL");
|
||||
if (element.getCreationDate() != null) {
|
||||
statement = connection
|
||||
.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setTimestamp(1, toTimestamp(element.getEditionDate()));
|
||||
statement.setString(2, element.getKey());
|
||||
|
||||
statement.executeUpdate();
|
||||
statement.clearParameters();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
// Insert new version of the element.
|
||||
statement.clearParameters();
|
||||
statement = connection
|
||||
.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
|
@ -1748,7 +1752,6 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
close(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -1768,12 +1771,10 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
element.update(value);
|
||||
element.setArchiveDate(null);
|
||||
|
||||
//
|
||||
put(element);
|
||||
|
||||
} else {
|
||||
//
|
||||
element.update(value);
|
||||
}
|
||||
|
||||
//
|
||||
Connection connection = null;
|
||||
|
@ -1785,6 +1786,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection.setAutoCommit(false);
|
||||
|
||||
// Archive existing element.
|
||||
if (element.getCreationDate() != null) {
|
||||
statement = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setTimestamp(1, toTimestamp(element.getEditionDate()));
|
||||
|
@ -1793,9 +1795,10 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
|
||||
statement.executeUpdate();
|
||||
statement.clearParameters();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
// Insert new version of the element.
|
||||
statement.clearParameters();
|
||||
statement = connection
|
||||
.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
|
@ -1818,7 +1821,6 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
close(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
|
Loading…
Reference in a new issue