diff --git a/bin/fr/devinsy/sikevadb/FileSikevaDB.class b/bin/fr/devinsy/sikevadb/FileSikevaDB.class index 1660bde..16c52f9 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 7b167eb..22db348 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 b83d6c4..613bc2e 100644 Binary files a/bin/fr/devinsy/sikevadb/SikevaDB.class and b/bin/fr/devinsy/sikevadb/SikevaDB.class differ diff --git a/src/fr/devinsy/sikevadb/FileSikevaDB.java b/src/fr/devinsy/sikevadb/FileSikevaDB.java index 7b9be1d..79e2701 100644 --- a/src/fr/devinsy/sikevadb/FileSikevaDB.java +++ b/src/fr/devinsy/sikevadb/FileSikevaDB.java @@ -255,6 +255,24 @@ public class FileSikevaDB implements SikevaDB { return 0; } + @Override + public long memorySizeOfArchive() throws Exception { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long memorySizeOfArchive(final String key) throws Exception { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long memorySizeOfArchive(final String key, final String subkey) throws Exception { + // TODO Auto-generated method stub + return 0; + } + @Override public void open() { // TODO Auto-generated method stub diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/SQLSikevaDB.java index bfe90c2..9e4fd35 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDB.java @@ -1391,7 +1391,7 @@ public class SQLSikevaDB implements SikevaDB { try { connection = getConnection(); connection.setAutoCommit(true); - statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE TOPKEY=?"); + statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NULL"); statement.setString(1, key); resultSet = statement.executeQuery(); @@ -1424,7 +1424,99 @@ public class SQLSikevaDB implements SikevaDB { try { 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 ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?"); + statement.setString(1, key); + statement.setString(2, subkey); + resultSet = statement.executeQuery(); + + resultSet.next(); + result = resultSet.getLong(1); + + } finally { + close(connection, statement, resultSet); + } + } + + // + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public long memorySizeOfArchive() throws SQLException { + long result; + + // + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + connection = getConnection(); + connection.setAutoCommit(true); + statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NOT NULL"); + resultSet = statement.executeQuery(); + + resultSet.next(); + result = resultSet.getLong(1); + + } finally { + close(connection, statement, resultSet); + } + + // + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public long memorySizeOfArchive(final String key) throws SQLException { + long result; + + // + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + connection = getConnection(); + connection.setAutoCommit(true); + statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY IS NULL"); + statement.setString(1, key); + resultSet = statement.executeQuery(); + + resultSet.next(); + result = resultSet.getLong(1); + + } finally { + close(connection, statement, resultSet); + } + + // + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public long memorySizeOfArchive(final String key, final String subkey) throws Exception { + long result; + + // + if (subkey == null) { + result = memorySize(key); + } else { + // + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + connection = getConnection(); + connection.setAutoCommit(true); + statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?"); statement.setString(1, key); statement.setString(2, subkey); resultSet = statement.executeQuery(); diff --git a/src/fr/devinsy/sikevadb/SikevaDB.java b/src/fr/devinsy/sikevadb/SikevaDB.java index ce74464..83a5dda 100644 --- a/src/fr/devinsy/sikevadb/SikevaDB.java +++ b/src/fr/devinsy/sikevadb/SikevaDB.java @@ -102,6 +102,12 @@ public interface SikevaDB { public long memorySize(String key, String subkey) throws Exception; + public long memorySizeOfArchive() throws Exception; + + long memorySizeOfArchive(String key) throws Exception; + + long memorySizeOfArchive(String key, String subkey) throws Exception; + public void open() throws Exception; public void put(Element element) throws Exception; diff --git a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java index cef357e..a36c481 100644 --- a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java +++ b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java @@ -16,7 +16,6 @@ import org.junit.Test; import fr.devinsy.util.StringList; /** - * ?profileSQL=true * * @author Christian P. Momon */ @@ -47,6 +46,7 @@ public class SQLSikevaDBTest { BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.ERROR); + // Add ?profileSQL=true to generate huge logs. this.database = new SQLSikevaDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/sikevadb-test", "sikevadb-test", "12345678"); this.database.open(); } @@ -123,6 +123,108 @@ public class SQLSikevaDBTest { logger.debug("===== test done."); } + /** + * @throws Exception + * + */ + @Test + public void testGeKeyse01() throws Exception { + // + logger.debug("===== test starting..."); + + database.clearDatabase(); + + database.put("alpha01", "1234567890"); + database.put("alpha01", "qlskjfmlqj"); + database.put("alpha02", "qlskjfmlqj"); + database.put("alpha03", "qlskjfmlqj"); + database.put("alpha04", "qlskjfmlqj"); + database.put("alpha05", "qlskjfmlqj"); + database.put("alpha01", "bravo1", "1234567890"); + database.put("alpha01", "bravo1", "qlskjfmlqj"); + database.put("alpha01", "bravo2", "qlskjfmlqj"); + database.put("alpha01", "bravo3", "qlskjfmlqj"); + database.put("alpha01", "bravo4", "qlskjfmlqj"); + database.put("alpha01", "bravo5", "qlskjfmlqj"); + + Assert.assertEquals(0, database.getSubkeys("none").size()); + + // + logger.debug("===== test done."); + } + + /** + * @throws Exception + * + */ + @Test + public void testGeKeyse02() throws Exception { + // + logger.debug("===== test starting..."); + + database.clearDatabase(); + + database.put("alpha01", "1234567890"); + database.put("alpha01", "qlskjfmlqj"); + database.put("alpha02", "qlskjfmlqj"); + database.put("alpha03", "qlskjfmlqj"); + database.put("alpha04", "qlskjfmlqj"); + database.put("alpha05", "qlskjfmlqj"); + database.put("alpha01", "bravo1", "1234567890"); + database.put("alpha01", "bravo1", "qlskjfmlqj"); + database.put("alpha01", "bravo2", "qlskjfmlqj"); + database.put("alpha01", "bravo3", "qlskjfmlqj"); + database.put("alpha01", "bravo4", "qlskjfmlqj"); + database.put("alpha01", "bravo5", "qlskjfmlqj"); + + StringList keys = database.getKeys(); + + Assert.assertEquals(5, keys.size()); + Assert.assertTrue(keys.contains("alpha03")); + Assert.assertEquals(1, database.getSubkeys("alpha03").size()); + + // + logger.debug("===== test done."); + } + + /** + * @throws Exception + * + */ + @Test + public void testMemorySize01() throws Exception { + // + logger.debug("===== test starting..."); + + database.clearDatabase(); + + Assert.assertEquals(0, database.memorySize()); + + database.put("alpha01", "1234567890"); + database.put("alpha01", "qlskjfmlqj"); + database.put("alpha02", "qlskjfmlqj"); + database.put("alpha03", "qlskjfmlqj"); + database.put("alpha04", "qlskjfmlqj"); + database.put("alpha05", "qlskjfmlqj"); + database.put("alpha01", "bravo1", "1234567890"); + database.put("alpha01", "bravo1", "qlskjfmlqj"); + database.put("alpha01", "bravo2", "qlskjfmlqj"); + database.put("alpha01", "bravo3", "qlskjfmlqj"); + database.put("alpha01", "bravo4", "qlskjfmlqj"); + database.put("alpha01", "bravo5", "qlskjfmlqj"); + + Assert.assertEquals(120, database.memorySize()); + Assert.assertEquals(10, database.memorySize("alpha01")); + Assert.assertEquals(10, database.memorySize("alpha01", "bravo1")); + + database.clearDatabase(); + + Assert.assertEquals(0, database.memorySize()); + + // + logger.debug("===== test done."); + } + /** * @throws Exception *