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
|
@Override
|
||||||
public void put(final String key, final String value) throws SQLException {
|
public void put(final String key, final String value) throws SQLException {
|
||||||
|
|
||||||
|
//
|
||||||
Element element = getElement(key);
|
Element element = getElement(key);
|
||||||
|
|
||||||
|
//
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
//
|
//
|
||||||
element = new Element();
|
element = new Element();
|
||||||
|
@ -1699,12 +1702,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
element.update(value);
|
element.update(value);
|
||||||
element.setArchiveDate(null);
|
element.setArchiveDate(null);
|
||||||
|
|
||||||
//
|
|
||||||
put(element);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
element.update(value);
|
element.update(value);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
|
@ -1716,16 +1717,19 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
|
|
||||||
// Archive existing element.
|
// 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.setTimestamp(1, toTimestamp(element.getEditionDate()));
|
||||||
statement.setString(2, element.getKey());
|
statement.setString(2, element.getKey());
|
||||||
|
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.clearParameters();
|
statement.clearParameters();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
// Insert new version of the element.
|
// Insert new version of the element.
|
||||||
statement.clearParameters();
|
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
.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);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -1768,12 +1771,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
element.update(value);
|
element.update(value);
|
||||||
element.setArchiveDate(null);
|
element.setArchiveDate(null);
|
||||||
|
|
||||||
//
|
|
||||||
put(element);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
element.update(value);
|
element.update(value);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
|
@ -1785,6 +1786,7 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
|
|
||||||
// Archive existing element.
|
// 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 = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||||
|
|
||||||
statement.setTimestamp(1, toTimestamp(element.getEditionDate()));
|
statement.setTimestamp(1, toTimestamp(element.getEditionDate()));
|
||||||
|
@ -1793,9 +1795,10 @@ public class SQLSikevaDB implements SikevaDB {
|
||||||
|
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.clearParameters();
|
statement.clearParameters();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
// Insert new version of the element.
|
// Insert new version of the element.
|
||||||
statement.clearParameters();
|
|
||||||
statement = connection
|
statement = connection
|
||||||
.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
.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);
|
close(connection, statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
|
Loading…
Reference in a new issue