diff --git a/src/fr/devinsy/sikevadb/core/SikevaDB.java b/src/fr/devinsy/sikevadb/core/SikevaDB.java index 61bb43a..fa0f4ba 100644 --- a/src/fr/devinsy/sikevadb/core/SikevaDB.java +++ b/src/fr/devinsy/sikevadb/core/SikevaDB.java @@ -224,7 +224,7 @@ public interface SikevaDB * @throws SikevaDBException * the SikevaDB exception */ - public StringList getKeys() throws SikevaDBException; + public StringList getTopKeys() throws SikevaDBException; /** * Gets all the sub keys of a key. diff --git a/src/fr/devinsy/sikevadb/core/XMLSikevaDB.java b/src/fr/devinsy/sikevadb/core/XMLSikevaDB.java index 212e06f..caa9813 100644 --- a/src/fr/devinsy/sikevadb/core/XMLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/core/XMLSikevaDB.java @@ -293,7 +293,8 @@ public class XMLSikevaDB } /** - * Write. + * Write in an XML writer the elements of a database, sorting by keys and + * sub keys. * * @param out * the out @@ -317,19 +318,16 @@ public class XMLSikevaDB { out.writeStartTag("elements"); - for (String key : source.getKeys()) + for (String topkey : source.getTopKeys().sort()) { // - Elements elements = source.getElements(key); - for (Element element : elements) - { - write(out, element); - } + Element topElement = source.getElement(topkey); + write(out, topElement); // - for (String subkey : source.getSubkeys(key)) + for (String subkey : source.getSubkeys(topkey).sort()) { - Element subElement = source.getElement(key, subkey); + Element subElement = source.getElement(subkey); write(out, subElement); } } diff --git a/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java b/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java index 39ef9fa..3cc0e6c 100644 --- a/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java +++ b/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java @@ -739,7 +739,7 @@ public class FileTreeSikevaDB implements SikevaDB * @see fr.devinsy.sikevadb.core.SikevaDB#getKeys() */ @Override - public StringList getKeys() throws SikevaDBException + public StringList getTopKeys() throws SikevaDBException { StringList result; @@ -760,15 +760,7 @@ public class FileTreeSikevaDB implements SikevaDB } else if (file.isDirectory()) { - File[] subFiles = file.listFiles(); - - for (File subFile : subFiles) - { - if (file.isFile()) - { - result.add(subFile.getName()); - } - } + result.add(file.getName()); } } } diff --git a/src/fr/devinsy/sikevadb/sql/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/sql/SQLSikevaDB.java index 435a63a..3a1ea48 100644 --- a/src/fr/devinsy/sikevadb/sql/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/sql/SQLSikevaDB.java @@ -1111,7 +1111,7 @@ public class SQLSikevaDB implements SikevaDB connection = getConnection(); connection.setAutoCommit(true); statement = connection - .prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL ORDER BY CREATION_DATE ASC"); + .prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL ORDER BY TOPKEY,SUBKEY ASC"); resultSet = statement.executeQuery(); while (resultSet.next()) @@ -1216,54 +1216,6 @@ public class SQLSikevaDB implements SikevaDB return result; } - /* (non-Javadoc) - * @see fr.devinsy.sikevadb.core.SikevaDB#getKeys() - */ - @Override - public StringList getKeys() throws SikevaDBException - { - StringList result; - - if (isClosed()) - { - throw new ClosedDatabaseException(); - } - else - { - // - 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 sikevadb_elements WHERE ARCHIVE_DATE IS NULL"); - resultSet = statement.executeQuery(); - - while (resultSet.next()) - { - result.add(resultSet.getString(1)); - } - } - catch (SQLException exception) - { - logger.error("Error getting keys.", exception); - throw new SikevaDBException("Error getting keys", exception); - } - finally - { - closeQuietly(connection, statement, resultSet); - } - } - - // - return result; - } - /** * Gets the login. * @@ -1348,6 +1300,54 @@ public class SQLSikevaDB implements SikevaDB return result; } + /* (non-Javadoc) + * @see fr.devinsy.sikevadb.core.SikevaDB#getKeys() + */ + @Override + public StringList getTopKeys() throws SikevaDBException + { + StringList result; + + if (isClosed()) + { + throw new ClosedDatabaseException(); + } + else + { + // + 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 sikevadb_elements WHERE ARCHIVE_DATE IS NULL"); + resultSet = statement.executeQuery(); + + while (resultSet.next()) + { + result.add(resultSet.getString(1)); + } + } + catch (SQLException exception) + { + logger.error("Error getting keys.", exception); + throw new SikevaDBException("Error getting keys", exception); + } + finally + { + closeQuietly(connection, statement, resultSet); + } + } + + // + return result; + } + /** * Gets the url. * diff --git a/test/fr/devinsy/sikevadb/filetree/TreeFileSikevaDBTest.java b/test/fr/devinsy/sikevadb/filetree/TreeFileSikevaDBTest.java index c3c6d71..ccef121 100644 --- a/test/fr/devinsy/sikevadb/filetree/TreeFileSikevaDBTest.java +++ b/test/fr/devinsy/sikevadb/filetree/TreeFileSikevaDBTest.java @@ -106,9 +106,9 @@ public class TreeFileSikevaDBTest database.put("alpha01s", "bravo4", "qlskjfmlqj"); database.put("alpha01s", "bravo5", "qlskjfmlqj"); - StringList keys = database.getKeys(); + StringList keys = database.getTopKeys(); - Assert.assertEquals(5, keys.size()); + Assert.assertEquals(6, keys.size()); Assert.assertTrue(keys.contains("alpha03")); Assert.assertEquals(0, database.getSubkeys("alpha03s").size()); Assert.assertEquals(5, database.getSubkeys("alpha01s").size()); diff --git a/test/fr/devinsy/sikevadb/sql/SQLSikevaDBTest.java b/test/fr/devinsy/sikevadb/sql/SQLSikevaDBTest.java index bb94a21..df6c3cf 100644 --- a/test/fr/devinsy/sikevadb/sql/SQLSikevaDBTest.java +++ b/test/fr/devinsy/sikevadb/sql/SQLSikevaDBTest.java @@ -170,7 +170,7 @@ public class SQLSikevaDBTest database.put("alpha01", "bravo4", "qlskjfmlqj"); database.put("alpha01", "bravo5", "qlskjfmlqj"); - StringList keys = database.getKeys(); + StringList keys = database.getTopKeys(); Assert.assertEquals(5, keys.size()); Assert.assertTrue(keys.contains("alpha03"));