diff --git a/.classpath b/.classpath index 4cc5a1c..aef547d 100644 --- a/.classpath +++ b/.classpath @@ -4,7 +4,7 @@ - + @@ -21,5 +21,6 @@ + diff --git a/bin/fr/devinsy/sikevadb/AlphaTest.class b/bin/fr/devinsy/sikevadb/AlphaTest.class deleted file mode 100644 index acba22f..0000000 Binary files a/bin/fr/devinsy/sikevadb/AlphaTest.class and /dev/null differ diff --git a/bin/fr/devinsy/sikevadb/Element.class b/bin/fr/devinsy/sikevadb/Element.class index eee2b6c..d1c81db 100644 Binary files a/bin/fr/devinsy/sikevadb/Element.class and b/bin/fr/devinsy/sikevadb/Element.class differ diff --git a/bin/fr/devinsy/sikevadb/FileSikevaDB.class b/bin/fr/devinsy/sikevadb/FileSikevaDB.class index a303586..1660bde 100644 Binary files a/bin/fr/devinsy/sikevadb/FileSikevaDB.class and b/bin/fr/devinsy/sikevadb/FileSikevaDB.class differ diff --git a/bin/fr/devinsy/sikevadb/SQLSikevaDB.class b/bin/fr/devinsy/sikevadb/SQLSikevaDB.class index 4fc777c..7b167eb 100644 Binary files a/bin/fr/devinsy/sikevadb/SQLSikevaDB.class and b/bin/fr/devinsy/sikevadb/SQLSikevaDB.class differ diff --git a/bin/fr/devinsy/sikevadb/SikevaDB.class b/bin/fr/devinsy/sikevadb/SikevaDB.class index 928f713..b83d6c4 100644 Binary files a/bin/fr/devinsy/sikevadb/SikevaDB.class and b/bin/fr/devinsy/sikevadb/SikevaDB.class differ diff --git a/bin/fr/devinsy/sikevadb/SikevaDBFactory.class b/bin/fr/devinsy/sikevadb/SikevaDBFactory.class index 8194aef..e59274a 100644 Binary files a/bin/fr/devinsy/sikevadb/SikevaDBFactory.class and b/bin/fr/devinsy/sikevadb/SikevaDBFactory.class differ diff --git a/lib/mysql-jdbc-5.0.8.jar b/lib/mysql-jdbc-5.0.8.jar new file mode 100644 index 0000000..0170c3e Binary files /dev/null and b/lib/mysql-jdbc-5.0.8.jar differ diff --git a/src/fr/devinsy/sikevadb/Element.java b/src/fr/devinsy/sikevadb/Element.java index d750e00..9180f0e 100644 --- a/src/fr/devinsy/sikevadb/Element.java +++ b/src/fr/devinsy/sikevadb/Element.java @@ -49,8 +49,7 @@ public class Element { * @param value */ public Element(final String key, final String subkey, final String value) { - updateValue(value); - this.creationDate = this.editionDate; + update(value); this.archiveDate = null; this.key = key; this.subkey = subkey; @@ -127,9 +126,14 @@ public class Element { this.value = value; } - public void updateValue(final String value) { + public void update(final String value) { + // setValue(value); + + // this.editionDate = new Date(); + + // if (value == null) { this.size = 0; this.digest = null; @@ -137,5 +141,10 @@ public class Element { this.size = this.value.length(); this.digest = DigestUtils.md5Hex(this.value); } + + // + if (this.creationDate == null) { + this.creationDate = this.editionDate; + } } } diff --git a/src/fr/devinsy/sikevadb/FileSikevaDB.java b/src/fr/devinsy/sikevadb/FileSikevaDB.java index 401a3a2..7b9be1d 100644 --- a/src/fr/devinsy/sikevadb/FileSikevaDB.java +++ b/src/fr/devinsy/sikevadb/FileSikevaDB.java @@ -15,6 +15,8 @@ */ package fr.devinsy.sikevadb; +import java.util.Date; + 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 public void close() { // TODO Auto-generated method stub @@ -115,6 +141,18 @@ public class FileSikevaDB implements SikevaDB { 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 public StringList getAllValues(final String key) { // TODO Auto-generated method stub @@ -163,6 +201,18 @@ public class FileSikevaDB implements SikevaDB { 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 public String getValue(final String key) throws Exception { // TODO Auto-generated method stub @@ -240,4 +290,10 @@ public class FileSikevaDB implements SikevaDB { // TODO Auto-generated method stub } + + @Override + public void removeAll(final String key) throws Exception { + // TODO Auto-generated method stub + + } } diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/SQLSikevaDB.java index b9a34f1..bfe90c2 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDB.java @@ -86,20 +86,11 @@ public class SQLSikevaDB implements SikevaDB { */ @Override public void archive(final String key) throws SQLException { - archive(key, null); - } - - /** - * {@inheritDoc} - */ - @Override - public void archive(final String key, final String subkey) throws SQLException { - // - Element element = getElement(key, null); + Element element = getElement(key); if (element == null) { - throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]"); + throw new NullPointerException("Undefined element [key=" + key + "]"); } else { // element.archive(); @@ -111,13 +102,13 @@ public class SQLSikevaDB implements SikevaDB { try { // connection = getConnection(); - statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?"); + 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.setString(3, element.getSubkey()); - statement.executeQuery(); + statement.executeUpdate(); } finally { close(connection, statement, resultSet); @@ -125,6 +116,132 @@ public class SQLSikevaDB implements SikevaDB { } } + /** + * {@inheritDoc} + */ + @Override + public void archive(final String key, final String subkey) throws SQLException { + // + if (subkey == null) { + archive(key); + } else { + // + 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; + ResultSet resultSet = null; + try { + // + connection = getConnection(); + connection.setAutoCommit(true); + statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?"); + + statement.setDate(1, dateToDate(element.getArchiveDate())); + statement.setString(2, element.getKey()); + statement.setString(3, element.getSubkey()); + + statement.executeUpdate(); + + } finally { + 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 + + \ No newline at end of file