Fixed database export with unitary test. Added XML export in file.
This commit is contained in:
parent
240c9d28e9
commit
36a8350b53
3 changed files with 45 additions and 6 deletions
|
@ -297,11 +297,11 @@ public class XMLSikevaDB
|
||||||
|
|
||||||
if (out == null)
|
if (out == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("out is null.");
|
throw new IllegalArgumentException("Parameter out is null.");
|
||||||
}
|
}
|
||||||
else if (source == null)
|
else if (source == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("element is null.");
|
throw new IllegalArgumentException("Parameter element is null.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -371,12 +371,15 @@ public class XMLSikevaDB
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
Element topElement = source.getElement(topkey);
|
Element topElement = source.getElement(topkey);
|
||||||
|
if (topElement != null)
|
||||||
|
{
|
||||||
write(out, topElement);
|
write(out, topElement);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
for (String subkey : source.getSubkeys(topkey).sort())
|
for (String subkey : source.getSubkeys(topkey).sort())
|
||||||
{
|
{
|
||||||
Element subElement = source.getElement(subkey);
|
Element subElement = source.getElement(topkey, subkey);
|
||||||
write(out, subElement);
|
write(out, subElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,9 @@ public class FileTreeSikevaDB implements SikevaDB
|
||||||
CLOSED
|
CLOSED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FileTreeSikevaDB.class);
|
||||||
|
|
||||||
private static final DateTimeFormatter ISOFormatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
|
private static final DateTimeFormatter ISOFormatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
|
||||||
private final Logger logger = LoggerFactory.getLogger(FileTreeSikevaDB.class);
|
|
||||||
|
|
||||||
private Status status;
|
private Status status;
|
||||||
private String login;
|
private String login;
|
||||||
|
@ -787,9 +788,10 @@ public class FileTreeSikevaDB implements SikevaDB
|
||||||
result = new StringList();
|
result = new StringList();
|
||||||
|
|
||||||
File targetDirectory = new File(this.dataDirectory, key);
|
File targetDirectory = new File(this.dataDirectory, key);
|
||||||
if (targetDirectory.exists())
|
if ((targetDirectory.exists()) && (targetDirectory.isDirectory()))
|
||||||
{
|
{
|
||||||
File[] subfiles = targetDirectory.listFiles();
|
File[] subfiles = targetDirectory.listFiles();
|
||||||
|
|
||||||
for (File subfile : subfiles)
|
for (File subfile : subfiles)
|
||||||
{
|
{
|
||||||
result.add(subfile.getName());
|
result.add(subfile.getName());
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.junit.Test;
|
||||||
import fr.devinsy.sikevadb.core.Element;
|
import fr.devinsy.sikevadb.core.Element;
|
||||||
import fr.devinsy.sikevadb.core.Elements;
|
import fr.devinsy.sikevadb.core.Elements;
|
||||||
import fr.devinsy.sikevadb.core.SikevaDBException;
|
import fr.devinsy.sikevadb.core.SikevaDBException;
|
||||||
|
import fr.devinsy.sikevadb.core.XMLSikevaDB;
|
||||||
import fr.devinsy.util.strings.StringList;
|
import fr.devinsy.util.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +47,38 @@ public class TreeFileSikevaDBTest
|
||||||
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TreeFileSikevaDBTest.class);
|
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TreeFileSikevaDBTest.class);
|
||||||
private static FileTreeSikevaDB database;
|
private static FileTreeSikevaDB database;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExport01() throws Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
logger.debug("===== test starting...");
|
||||||
|
|
||||||
|
database.clear();
|
||||||
|
|
||||||
|
database.put("alpha01", "qlskjfmlqja");
|
||||||
|
database.put("alpha01", "qlskjfmlqjb");
|
||||||
|
database.put("alpha02", "qlskjfmlqj");
|
||||||
|
database.put("alpha03", "qlskjfmlqj");
|
||||||
|
database.put("alpha04", "qlskjfmlqj");
|
||||||
|
database.put("alpha05", "qlskjfmlqj");
|
||||||
|
database.delete("alpha03");
|
||||||
|
database.put("alpha01s", "bravo1", "qlskjfmlqja");
|
||||||
|
database.put("alpha01s", "bravo1", "qlskjfmlqjb");
|
||||||
|
database.put("alpha01s", "bravo2", "qlskjfmlqj");
|
||||||
|
database.put("alpha01s", "bravo3", "qlskjfmlqj");
|
||||||
|
database.put("alpha01s", "bravo4", "qlskjfmlqj");
|
||||||
|
database.put("alpha01s", "bravo5", "qlskjfmlqj");
|
||||||
|
database.delete("alpha01s", "bravo3");
|
||||||
|
|
||||||
|
File file = File.createTempFile("sikevadb-", ".tmp");
|
||||||
|
XMLSikevaDB.export(file, database);
|
||||||
|
Assert.assertTrue(file.exists());
|
||||||
|
file.delete();
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.debug("===== test done.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test get keyse 01.
|
* Test get keyse 01.
|
||||||
*
|
*
|
||||||
|
@ -671,6 +704,7 @@ public class TreeFileSikevaDBTest
|
||||||
if (database != null)
|
if (database != null)
|
||||||
{
|
{
|
||||||
database.close();
|
database.close();
|
||||||
|
database.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue