Fixed XML export and getKeys methods (thanks Didier). Renamed getKeys

with getTopKeys.
This commit is contained in:
Christian P. MOMON 2018-02-28 16:20:16 +01:00
parent 280e8c7a57
commit 70bb0c74dd
6 changed files with 62 additions and 72 deletions

View file

@ -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.

View file

@ -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);
}
}

View file

@ -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());
}
}
}

View file

@ -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.
*

View file

@ -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());

View file

@ -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"));