Refactored hugely to branch 1.0

This commit is contained in:
Christian P. MOMON 2017-04-21 19:25:39 +02:00
parent ffdba7956c
commit b04d79fd08
30 changed files with 3837 additions and 2162 deletions

View file

@ -23,6 +23,8 @@
<classpathentry kind="lib" path="lib/mysql-jdbc-5.0.8.jar"/> <classpathentry kind="lib" path="lib/mysql-jdbc-5.0.8.jar"/>
<classpathentry kind="lib" path="lib/joda-time-2.3.jar" sourcepath="lib/joda-time-2.3-sources.jar"/> <classpathentry kind="lib" path="lib/joda-time-2.3.jar" sourcepath="lib/joda-time-2.3-sources.jar"/>
<classpathentry kind="lib" path="lib/hsqldb-2.3.0.jar"/> <classpathentry kind="lib" path="lib/hsqldb-2.3.0.jar"/>
<classpathentry kind="lib" path="lib/devinsy-utils-0.2.12.jar" sourcepath="lib/devinsy-utils-0.2.12-sources.zip"/> <classpathentry kind="lib" path="lib/commons-io-2.4-sources.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.4.jar" sourcepath="lib/commons-io-2.4-sources.jar"/>
<classpathentry kind="lib" path="lib/devinsy-utils-0.3.3.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Feb 08 16:31:19 CET 2014 #Sat Feb 08 16:31:19 CET 2014
build.number=11 build.number=0

View file

@ -1,3 +1,3 @@
product.name=sikevadb product.name=sikevadb
product.revision.major=0 product.revision.major=0
product.revision.minor=1 product.revision.minor=2

Binary file not shown.

BIN
lib/commons-io-2.4.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/devinsy-utils-0.3.3.jar Normal file

Binary file not shown.

View file

@ -1,422 +0,0 @@
/**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb;
import java.io.File;
import org.joda.time.DateTime;
import fr.devinsy.util.StringList;
/**
*
*
* @author Christian Pierre MOMON
*/
public class FileSikevaDB implements SikevaDB
{
/**
*
* @param path
*/
public FileSikevaDB(final File path)
{
}
/**
*
* @param path
*/
public FileSikevaDB(final String path)
{
}
@Override
public void archive(final String key) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void archive(final String key, final String subkey) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void clearAllArchive() throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void clearArchive(final DateTime 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
}
@Override
public long countOfAllElements()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfAllElements(final String key)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfAllElements(final String key, final String subkey)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfArchivedElements()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfArchivedElements(final String key)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfArchivedElements(final String key, final String subkey)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfElements()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfElements(final String key)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long countOfElements(final String key, final String subkey)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public Elements getAllElements() throws Exception
{
// TODO Auto-generated method stub
return null;
}
@Override
public Elements getAllElements(final String key) throws Exception
{
// TODO Auto-generated method stub
return null;
}
@Override
public Elements getAllElements(final String key, final String subkey) throws Exception
{
// TODO Auto-generated method stub
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
return null;
}
@Override
public StringList getAllValues(final String key, final String subkey)
{
// TODO Auto-generated method stub
return null;
}
@Override
public StringList getArchivedValues(final String key)
{
// TODO Auto-generated method stub
return null;
}
@Override
public StringList getArchivedValues(final String key, final String subkey)
{
// TODO Auto-generated method stub
return null;
}
@Override
public Element getElement(final String key) throws Exception
{
// TODO Auto-generated method stub
return null;
}
@Override
public Element getElement(final String key, final String subkey) throws Exception
{
// TODO Auto-generated method stub
return null;
}
@Override
public Elements getElements(final String key) throws Exception
{
// TODO Auto-generated method stub
return null;
}
@Override
public Elements getElements(final String key, final String subkey) throws Exception
{
// TODO Auto-generated method stub
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
return null;
}
@Override
public String getValue(final String key, final String subkey)
{
// TODO Auto-generated method stub
return null;
}
@Override
public StringList getValues(final String key)
{
// TODO Auto-generated method stub
return null;
}
@Override
public long memorySize()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long memorySize(final String key)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long memorySize(final String key, final String subkey)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long memorySizeOfAll() throws Exception
{
// TODO Auto-generated method stub
return 0;
}
@Override
public long memorySizeOfAll(final String key) throws Exception
{
// TODO Auto-generated method stub
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
}
@Override
public void put(final Element element) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void put(final String key, final String value)
{
// TODO Auto-generated method stub
}
@Override
public void put(final String key, final String subkey, final String value)
{
// TODO Auto-generated method stub
}
@Override
public void remove(final String key) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void remove(final String key, final String subkey) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void removeAll(final String key) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void removeMany(final String key, final String... subkeys) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void renameKey(final String oldKey, final String newKey) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void replaceInValue(final String key, final String... tokens) throws Exception
{
// TODO Auto-generated method stub
}
@Override
public void replaceInValues(final String key, final String... tokens) throws Exception
{
// TODO Auto-generated method stub
}
}

View file

@ -1,139 +0,0 @@
/**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb;
import org.joda.time.DateTime;
import fr.devinsy.util.StringList;
/**
* All elements = archived elements + elements.
*
*
*
* @author Christian Pierre MOMON
*/
public interface SikevaDB
{
public void archive(final String key) throws Exception;
public void archive(final String key, final String subkey) throws Exception;
public void clearAllArchive() throws Exception;
public void clearArchive(final DateTime beforeDate) throws Exception;
public void clearArchive(final int maxDays) throws Exception;
public void clearDatabase() throws Exception;
public void close() throws Exception;
public long countOfAllElements() throws Exception;
public long countOfAllElements(String key) throws Exception;
public long countOfAllElements(String key, String subkey) throws Exception;
public long countOfArchivedElements() throws Exception;
public long countOfArchivedElements(String key) throws Exception;
public long countOfArchivedElements(String key, String subkey) throws Exception;
public long countOfElements() throws Exception;
public long countOfElements(String key) throws Exception;
public long countOfElements(String key, String subkey) throws Exception;
public Elements getAllElements() throws Exception;
public Elements getAllElements(String key) throws Exception;
public Elements getAllElements(String key, String subkey) throws Exception;
public StringList getAllKeys() throws Exception;
public StringList getAllSubkeys(String key) throws Exception;
public StringList getAllValues(String key) throws Exception;
public StringList getAllValues(String key, String subkey) throws Exception;
public StringList getArchivedValues(String key) throws Exception;
public StringList getArchivedValues(String key, String subkey) throws Exception;
public Element getElement(String key) throws Exception;
public Element getElement(String key, String subkey) throws Exception;
public Elements getElements(String key) throws Exception;
public Elements getElements(String key, String subkey) throws Exception;
public StringList getKeys() throws Exception;
public StringList getSubkeys(String key) throws Exception;
public String getValue(String key) throws Exception;
public String getValue(String key, String subkey) throws Exception;
public StringList getValues(String key) throws Exception;
public long memorySize() throws Exception;
public long memorySize(String key) throws Exception;
public long memorySize(String key, String subkey) throws Exception;
public long memorySizeOfAll() throws Exception;
long memorySizeOfAll(String key) 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;
public void put(String key, String value) throws Exception;
public void put(String key, String subkey, String value) throws Exception;
public void remove(final String key) throws Exception;
public void remove(final String key, final String subkey) throws Exception;
public void removeAll(final String key) throws Exception;
public void removeMany(final String key, final String... subkeys) throws Exception;
public void renameKey(final String oldKey, final String newKey) throws Exception;
public void replaceInValue(final String key, final String... tokens) throws Exception;
public void replaceInValues(final String key, final String... tokens) throws Exception;
}

View file

@ -0,0 +1,78 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb;
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.sikevadb.cli.SikevaCLI;
/**
* This class Siba stands for Simple Backup. This is the main class.
*
*
*/
public final class SikevaDBLauncher
{
private static Logger logger = LoggerFactory.getLogger(SikevaDBLauncher.class);
/**
*
*/
private SikevaDBLauncher()
{
}
/**
*
* @param args
*/
public static void main(final String[] args)
{
// Configure log.
File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists())
{
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
}
else
{
BasicConfigurator.configure();
logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
}
// Run.
if (args.length == 0)
{
// TODO
// SikevaGUI.run();
}
else
{
SikevaCLI.run(args);
}
}
}

View file

@ -0,0 +1,166 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.cli;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import utils.BuildInformation;
import fr.devinsy.sikevadb.core.SikevaDBException;
import fr.devinsy.util.strings.StringList;
/**
* This class manage a Command Line Interface for SikevaDB.
*
*
*/
public final class SikevaCLI
{
private static Logger logger = LoggerFactory.getLogger(SikevaCLI.class);
/**
*
*/
private SikevaCLI()
{
}
/**
* This method displays the CLI help.
*
*/
public static void help()
{
StringList message = new StringList();
message.append("SikevaDB CLI version ").appendln(BuildInformation.instance().version());
message.appendln("Usage:");
message.appendln(" sikevadbcli [ -h | -help | --help ]");
message.appendln(" sikevadbcli get key");
message.appendln(" sikevadbcli get key subkey");
System.out.println(message.toString());
}
/**
*
* @param args
*/
public static void main(final String[] args)
{
// Configure log.
File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists())
{
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
}
else
{
BasicConfigurator.configure();
logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
}
// Run.
SikevaCLI.run(args);
}
/**
*
* This method launch CLI.
*
* @param args
* necessary arguments
*/
public static void run(final String[] args)
{
try
{
// Set default catch.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException(final Thread thread, final Throwable exception)
{
String message;
if (exception instanceof OutOfMemoryError)
{
message = "Java ran out of memory!\n\n";
}
else
{
message = String.format("An error occured: %1s(%2s)", exception.getClass(), exception.getMessage());
}
logger.error("uncaughtException ", exception);
logger.error(message);
logger.info("Oups, an unexpected error occured. Please try again.");
}
});
// This part implements an automate.
int parameterCount = args.length;
if (parameterCount == 0)
{
help();
}
else if (StringUtils.equals(args[0], "-h") || StringUtils.equals(args[0], "-help") || StringUtils.equals(args[0], "--help"))
{
help();
}
else if (StringUtils.equals(args[0], "get"))
{
switch (parameterCount)
{
case 2:
{
}
break;
case 3:
{
}
break;
default:
throw new SikevaDBException("Bad parameter count.");
}
}
else
{
System.out.println("Bad usage detected.");
help();
}
}
catch (SikevaDBException exception)
{
System.err.println("SibaException = " + exception.getMessage());
logger.error(exception.getMessage(), exception);
help();
}
}
}

View file

@ -0,0 +1,63 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.cli;
/**
*
*/
public class SikevaCLIException extends Exception
{
private static final long serialVersionUID = 2986878456227891377L;
/**
*
*/
public SikevaCLIException()
{
super();
}
/**
*
* @param message
*/
public SikevaCLIException(final String message)
{
super(message);
}
/**
*
* @param message
* @param cause
*/
public SikevaCLIException(final String message, final Throwable cause)
{
super(message, cause);
}
/**
*
* @param cause
*/
public SikevaCLIException(final Throwable cause)
{
super(cause);
}
}

View file

@ -0,0 +1,89 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.core;
import fr.devinsy.util.strings.StringList;
/**
*
*
* @author Christian Pierre MOMON
*/
public interface Archiver
{
public void clear() throws SikevaDBException;
public void close() throws SikevaDBException;
public long countOfElements() throws SikevaDBException;
public long countOfElements(String key) throws SikevaDBException;
public long countOfElements(String key, String subkey) throws SikevaDBException;
public Element getElement(String key) throws SikevaDBException;
public Element getElement(String key, String subkey) throws SikevaDBException;
public Elements getElements() throws SikevaDBException;
public Elements getElements(String key) throws SikevaDBException;
public StringList getKeys() throws SikevaDBException;
public StringList getSubkeys(String key) throws SikevaDBException;
public String getValue(String key) throws SikevaDBException;
public String getValue(String key, String subkey) throws SikevaDBException;
public StringList getValues(String key) throws SikevaDBException;
public boolean isClosed();
public boolean isOpened();
public long memorySize() throws SikevaDBException;
public long memorySize(String key) throws SikevaDBException;
public long memorySize(String key, String subkey) throws SikevaDBException;
void open() throws SikevaDBException;
void put(Element element) throws SikevaDBException;
void put(String key, String value) throws SikevaDBException;
void put(String key, String subkey, String value) throws SikevaDBException;
void remove(final String key) throws SikevaDBException;
void remove(final String key, final String subkey) throws SikevaDBException;
void removeMany(final String key, final String... subkeys) throws SikevaDBException;
void renameKey(final String oldKey, final String newKey) throws SikevaDBException;
void renameSubKey(final String key, final String oldSubKey, final String newSubKey) throws SikevaDBException;
void replaceInValue(final String key, final String... tokens) throws SikevaDBException;
void replaceInValues(final String key, final String... tokens) throws SikevaDBException;
}

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>. * along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.sikevadb; package fr.devinsy.sikevadb.core;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -33,6 +33,7 @@ public class Element
private long id; private long id;
private DateTime creationDate; private DateTime creationDate;
private DateTime editionDate; private DateTime editionDate;
/* archiveDate field is reserved for journalizer. */
private DateTime archiveDate; private DateTime archiveDate;
private String key; private String key;
private String subkey; private String subkey;
@ -161,6 +162,10 @@ public class Element
this.value = value; this.value = value;
} }
/**
*
* @param value
*/
public void update(final String value) public void update(final String value)
{ {
// //
@ -173,7 +178,7 @@ public class Element
if (value == null) if (value == null)
{ {
this.size = 0; this.size = 0;
this.digest = null; this.digest = DigestUtils.md5Hex("");
} }
else else
{ {

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>. * along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.sikevadb; package fr.devinsy.sikevadb.core;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -0,0 +1,93 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.core;
import fr.devinsy.util.strings.StringList;
/**
*
*
* @author Christian Pierre MOMON
*/
public interface SikevaDB
{
public void clear() throws SikevaDBException;
public void close() throws SikevaDBException;
public long countOfElements() throws SikevaDBException;
public long countOfElements(String key) throws SikevaDBException;
public long countOfElements(String key, String subkey) throws SikevaDBException;
public void create() throws SikevaDBException;
public Element getElement(String key) throws SikevaDBException;
public Element getElement(String key, String subkey) throws SikevaDBException;
public Elements getElements() throws SikevaDBException;
public Elements getElements(String key) throws SikevaDBException;
public fr.devinsy.util.strings.StringList getKeys() throws SikevaDBException;
public StringList getSubkeys(String key) throws SikevaDBException;
public String getValue(String key) throws SikevaDBException;
public String getValue(String key, String subkey) throws SikevaDBException;
public StringList getValues(String key) throws SikevaDBException;
public boolean isClosed();
public boolean isCreated() throws SikevaDBException;
public boolean isOpened();
public long memorySize() throws SikevaDBException;
public long memorySize(String key) throws SikevaDBException;
public long memorySize(String key, String subkey) throws SikevaDBException;
void open() throws SikevaDBException;
void put(Element element) throws SikevaDBException;
void put(String key, String value) throws SikevaDBException;
void put(String key, String subkey, String value) throws SikevaDBException;
void remove(final String key) throws SikevaDBException;
void remove(final String key, final String subkey) throws SikevaDBException;
void removeMany(final String key, final String... subkeys) throws SikevaDBException;
void renameKey(final String oldKey, final String newKey) throws SikevaDBException;
void renameSubKey(final String key, final String oldSubKey, final String newSubKey) throws SikevaDBException;
void replaceInValue(final String key, final String... tokens) throws SikevaDBException;
void replaceInValues(final String key, final String... tokens) throws SikevaDBException;
}

View file

@ -0,0 +1,64 @@
/**
* Copyright (C) 2013-2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.core;
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
public class SikevaDBException extends Exception
{
private static final long serialVersionUID = 8323299610751708972L;
/**
*
*/
public SikevaDBException()
{
super();
}
/**
*
* @param message
*/
public SikevaDBException(final String message)
{
super(message);
}
/**
*
* @param message
* @param cause
*/
public SikevaDBException(final String message, final Throwable cause)
{
super(message, cause);
}
/**
*
* @param cause
*/
public SikevaDBException(final Throwable cause)
{
super(cause);
}
}

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -16,10 +16,11 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>. * along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.sikevadb; package fr.devinsy.sikevadb.core;
import java.io.File; import java.io.File;
import fr.devinsy.sikevadb.filetree.FileTreeSikevaDB;
import fr.devinsy.sikevadb.sql.SQLSikevaDB; import fr.devinsy.sikevadb.sql.SQLSikevaDB;
/** /**
@ -38,7 +39,7 @@ public class SikevaDBFactory
{ {
SikevaDB result; SikevaDB result;
result = new FileSikevaDB(path); result = new FileTreeSikevaDB(path, null, null);
// //
return result; return result;
@ -46,7 +47,7 @@ public class SikevaDBFactory
/** /**
* *
* @param path * @param contextName
* @return * @return
*/ */
public static SikevaDB get(final String contextName) public static SikevaDB get(final String contextName)

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>. * along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.sikevadb; package fr.devinsy.sikevadb.core;
import java.util.Date; import java.util.Date;

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>. * along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.sikevadb; package fr.devinsy.sikevadb.core;
import java.io.File; import java.io.File;
import java.io.OutputStream; import java.io.OutputStream;
@ -87,7 +87,6 @@ public class XMLSikevaDB
} }
else else
{ {
//
XMLZipWriter target = null; XMLZipWriter target = null;
try try
{ {
@ -117,7 +116,6 @@ public class XMLSikevaDB
*/ */
public static void importData(final SikevaDB database, final File file) throws Exception public static void importData(final SikevaDB database, final File file) throws Exception
{ {
// XMLReader in = null; // XMLReader in = null;
// try { // try {
// in = new XMLZipReader(file); // in = new XMLZipReader(file);
@ -196,7 +194,6 @@ public class XMLSikevaDB
*/ */
public static void readElements(final SikevaDB target, final XMLReader in) throws Exception public static void readElements(final SikevaDB target, final XMLReader in) throws Exception
{ {
// //
XMLTag list = in.readListTag("elements"); XMLTag list = in.readListTag("elements");
@ -279,7 +276,6 @@ public class XMLSikevaDB
*/ */
public static void write(final XMLWriter out, final SikevaDB source) throws Exception public static void write(final XMLWriter out, final SikevaDB source) throws Exception
{ {
if (out == null) if (out == null)
{ {
throw new NullPointerException("out is null."); throw new NullPointerException("out is null.");
@ -292,10 +288,10 @@ public class XMLSikevaDB
{ {
out.writeStartTag("elements"); out.writeStartTag("elements");
for (String key : source.getAllKeys()) for (String key : source.getKeys())
{ {
// //
Elements elements = source.getAllElements(key); Elements elements = source.getElements(key);
for (Element element : elements) for (Element element : elements)
{ {
write(out, element); write(out, element);
@ -304,11 +300,8 @@ public class XMLSikevaDB
// //
for (String subkey : source.getSubkeys(key)) for (String subkey : source.getSubkeys(key))
{ {
Elements subElements = source.getAllElements(key, subkey); Element subElement = source.getElement(key, subkey);
for (Element subElement : subElements) write(out, subElement);
{
write(out, subElement);
}
} }
} }

View file

@ -0,0 +1,48 @@
/**
* Copyright (C) 2013-2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.filetree;
import fr.devinsy.sikevadb.core.SikevaDB;
/**
*
*
* @author Christian Pierre MOMON
*/
public class ArchiveManager
{
private SikevaDB database;
/**
*
* @param source
*/
public ArchiveManager(final SikevaDB source)
{
if (this.database == null)
{
throw new IllegalArgumentException("Null parameter.");
}
else
{
this.database = source;
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,212 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.filetree;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.xml.stream.XMLStreamException;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.sikevadb.core.Element;
import fr.devinsy.sikevadb.core.SikevaDBException;
import fr.devinsy.util.xml.XMLBadFormatException;
import fr.devinsy.util.xml.XMLReader;
import fr.devinsy.util.xml.XMLWriter;
/**
*
*
* @author Christian Pierre MOMON
*/
public class FileTreeSikevaDBTools
{
private static final Logger LOGGER = LoggerFactory.getLogger(FileTreeSikevaDBTools.class);
/**
*
* @param source
* @return
* @throws FileNotFoundException
* @throws XMLStreamException
* @throws XMLBadFormatException
*/
public static Element loadElement(final File source) throws SikevaDBException
{
Element result;
if (source == null)
{
result = null;
}
else if (!source.isFile())
{
result = null;
}
else
{
XMLReader in = null;
try
{
result = new Element();
in = new XMLReader(source);
in.readXMLHeader();
in.readStartTag("element");
{
// private long id; IN
long id = Long.parseLong(in.readContentTag("id").getContent());
result.setId(id);
// private DateTime creationDate; IN
DateTime creationDate = DateTime.parse(in.readContentTag("creation_date").getContent());
result.setCreationDate(creationDate);
// private DateTime editionDate; IN
DateTime editionDate = DateTime.parse(in.readContentTag("edition_date").getContent());
result.setEditionDate(editionDate);
// private long size; IN
long size = Long.parseLong(in.readContentTag("size").getContent());
result.setSize(size);
// private String digest; IN
String digest = in.readContentTag("digest").getContent();
result.setDigest(digest);
// private String value; IN
String value = in.readContentTag("value").getContent();
result.setValue(value);
}
in.readEndTag("element");
}
catch (XMLStreamException exception)
{
throw new SikevaDBException("Error loading element.", exception);
}
catch (XMLBadFormatException exception)
{
throw new SikevaDBException("Error loading element.", exception);
}
catch (FileNotFoundException exception)
{
throw new SikevaDBException("Error loading element.", exception);
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (XMLStreamException exception)
{
LOGGER.error("Finally close failed.", exception);
}
}
}
}
//
return result;
}
/**
*
* @param target
* @param source
* @throws SikevaDBException
*/
public static void saveElement(final File target, final Element source) throws SikevaDBException
{
LOGGER.debug("[target={}]", target);
if (target == null)
{
throw new IllegalArgumentException("Target file is null.");
}
else if (target.isDirectory())
{
throw new IllegalArgumentException("Target is a directory.");
}
else
{
XMLWriter out = null;
try
{
out = new XMLWriter(target);
out.writeXMLHeader();
out.writeStartTag("element");
{
// private long id; IN
out.writeTag("id", source.getId());
// private DateTime creationDate; IN
out.writeTag("creation_date", source.getCreationDate().toString());
// private DateTime editionDate; IN
out.writeTag("edition_date", source.getEditionDate().toString());
// private long size; IN
out.writeTag("size", source.getSize());
// private String digest; IN
out.writeTag("digest", source.getDigest());
// private String value; IN
out.writeTag("value", source.getValue());
}
out.writeEndTag("element");
}
catch (UnsupportedEncodingException exception)
{
throw new SikevaDBException("Error saving element.", exception);
}
catch (FileNotFoundException exception)
{
throw new SikevaDBException("File Not Found saving element.", exception);
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException exception)
{
LOGGER.error("Finally close failed.", exception);
}
}
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -22,13 +22,15 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.net.URL; import java.net.URL;
import java.util.Date;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.util.FileTools; import fr.devinsy.util.FileTools;
import fr.devinsy.util.StringList; import fr.devinsy.util.strings.StringList;
/** /**
* *
@ -117,4 +119,70 @@ public class SQLSikevaDBTools
// //
return result; return result;
} }
/**
*
* @param source
* @return
*/
public static DateTime toDateTime(final java.sql.Timestamp source)
{
DateTime result;
if (source == null)
{
result = null;
}
else
{
result = new DateTime(source.getTime());
}
//
return result;
}
/**
*
* @param source
* @return
*/
public static java.sql.Timestamp toTimestamp(final Date source)
{
java.sql.Timestamp result;
if (source == null)
{
result = null;
}
else
{
result = new java.sql.Timestamp(source.getTime());
}
//
return result;
}
/**
*
* @param source
* @return
*/
public static java.sql.Timestamp toTimestamp(final DateTime source)
{
java.sql.Timestamp result;
if (source == null)
{
result = null;
}
else
{
result = new java.sql.Timestamp(source.getMillis());
}
//
return result;
}
} }

View file

@ -0,0 +1,189 @@
/**
* Copyright (C) 2013-2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package utils;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
public class BuildInformation
{
private static class SingletonHolder
{
private static final BuildInformation instance = new BuildInformation();
}
private static final Logger logger = LoggerFactory.getLogger(BuildInformation.class);
private static String BUILD_INFORMATION_FILE = "/fr/devinsy/sikevadb/build_information.properties";
private String productName;
private String majorRevision;
private String minorRevision;
private String buildNumber;
private String buildDate;
private String generator;
private String buildAuthor;
/**
*
*/
private BuildInformation()
{
Properties build = new Properties();
try
{
//
URL buildInformationFile = BuildInformation.class.getResource(BUILD_INFORMATION_FILE);
if (buildInformationFile != null)
{
build.load(BuildInformation.class.getResource(BUILD_INFORMATION_FILE).openStream());
}
//
this.productName = build.getProperty("product.name", "DevInProgress");
this.majorRevision = build.getProperty("product.revision.major", "d");
this.minorRevision = build.getProperty("product.revision.minor", "e");
this.buildNumber = build.getProperty("product.revision.build", "v");
this.buildDate = build.getProperty("product.revision.date", "today");
this.generator = build.getProperty("product.revision.generator", "n/a");
this.buildAuthor = build.getProperty("product.revision.author", "n/a");
}
catch (IOException exception)
{
logger.error("Error loading the build.properties file: " + exception.getMessage());
logger.error(ExceptionUtils.getStackTrace(exception));
this.productName = "n/a";
this.majorRevision = "n/a";
this.minorRevision = "n/a";
this.buildNumber = "n/a";
this.buildDate = "n/a";
this.generator = "n/a";
this.buildAuthor = "n/a";
}
}
/**
*
* @return
*/
public String buildAuthor()
{
return this.buildAuthor;
}
public String buildDate()
{
return this.buildDate;
}
public String buildNumber()
{
return this.buildNumber;
}
public String generator()
{
return this.generator;
}
public String majorRevision()
{
return this.majorRevision;
}
public String minorRevision()
{
return this.minorRevision;
}
public String productName()
{
return this.productName;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = String.format("%s %s.%s.%s built on %s by %s", this.productName, this.majorRevision, this.minorRevision, this.buildNumber, this.buildDate, this.buildAuthor);
//
return result;
}
/**
*
* @return
*/
public String version()
{
String result;
result = String.format("%s.%s.%s", this.majorRevision, this.minorRevision, this.buildNumber);
//
return result;
}
/**
*
* @return
*/
public static BuildInformation instance()
{
return SingletonHolder.instance;
}
/**
*
*/
public static boolean isDefined()
{
boolean result;
if (BuildInformation.class.getResource(BUILD_INFORMATION_FILE) == null)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
}

View file

@ -0,0 +1,644 @@
/**
* Copyright (C) 2013-2017 Christian Pierre MOMON, DEVINSY
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* SikevaDB is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.filetree;
import java.io.File;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import fr.devinsy.sikevadb.core.Element;
import fr.devinsy.sikevadb.core.Elements;
import fr.devinsy.sikevadb.core.SikevaDBException;
import fr.devinsy.util.strings.StringList;
/**
*
* @author Christian Pierre MOMON
*/
public class TreeFileSikevaDBTest
{
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TreeFileSikevaDBTest.class);
private static FileTreeSikevaDB database;
/**
* @throws Exception
*/
@Test
public void testGetKeyse01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
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("alpha01s", "bravo1", "1234567890");
database.put("alpha01s", "bravo1", "qlskjfmlqj");
database.put("alpha01s", "bravo2", "qlskjfmlqj");
database.put("alpha01s", "bravo3", "qlskjfmlqj");
database.put("alpha01s", "bravo4", "qlskjfmlqj");
database.put("alpha01s", "bravo5", "qlskjfmlqj");
Assert.assertEquals(0, database.getSubkeys("none").size());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testGetKeyse02() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
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("alpha01s", "bravo1", "1234567890");
database.put("alpha01s", "bravo1", "qlskjfmlqj");
database.put("alpha01s", "bravo2", "qlskjfmlqj");
database.put("alpha01s", "bravo3", "qlskjfmlqj");
database.put("alpha01s", "bravo4", "qlskjfmlqj");
database.put("alpha01s", "bravo5", "qlskjfmlqj");
StringList keys = database.getKeys();
Assert.assertEquals(5, keys.size());
Assert.assertTrue(keys.contains("alpha03"));
Assert.assertEquals(0, database.getSubkeys("alpha03s").size());
Assert.assertEquals(5, database.getSubkeys("alpha01s").size());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testMemorySize01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
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("alpha01s", "bravo1", "1234567890");
database.put("alpha01s", "bravo1", "qlskjfmlqj");
database.put("alpha01s", "bravo2", "qlskjfmlqj");
database.put("alpha01s", "bravo3", "qlskjfmlqj");
database.put("alpha01s", "bravo4", "qlskjfmlqj");
database.put("alpha01s", "bravo5", "qlskjfmlqj");
Assert.assertEquals(100, database.memorySize());
Assert.assertEquals(10, database.memorySize("alpha03"));
Assert.assertEquals(50, database.memorySize("alpha01s"));
Assert.assertEquals(10, database.memorySize("alpha01s", "bravo1"));
database.clear();
Assert.assertEquals(0, database.memorySize());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPut01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha01", source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPut02() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha01", source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test(expected = IllegalArgumentException.class)
public void testPut03() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
database.getValue("foo", null);
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPut04() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha02", "bravo", source);
String target = database.getValue("alpha02", "bravo");
Assert.assertEquals(source, target);
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPut05() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha01", source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
String source2 = "au revoir";
database.put("alpha01", source2);
target = database.getValue("alpha01");
Assert.assertEquals(source2, target);
// TODO StringList targets = database.getArchivedValues("alpha01");
// TODO Assert.assertEquals(1, targets.size());
// TODO Assert.assertEquals(source, targets.get(0));
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPut06() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha01", "bravo", source);
String target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source, target);
String source2 = "au revoir";
database.put("alpha01", "bravo", source2);
target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source2, target);
// TODO StringList targets = database.getArchivedValues("alpha01",
// "bravo");
// TODO Assert.assertEquals(1, targets.size());
// TODO Assert.assertEquals(source, targets.get(0));
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPutElement01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
Element element = new Element();
element.setKey("alpha");
element.setSubkey(null);
element.setSize(10);
element.setDigest("qsdkfqskjf");
element.setCreationDate(DateTime.now().minusDays(11));
element.setEditionDate(DateTime.now().minusDays(11));
element.setArchiveDate(DateTime.now().minusDays(10));
element.setValue("bonjour");
database.put(element);
Assert.assertEquals(1, database.countOfElements());
// TODO Assert.assertEquals(1, database.countOfArchivedElements());
// TODO Assert.assertEquals(1, database.countOfAllElements());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPutElement02() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
logger.debug("count={}", database.countOfElements());
Element element = new Element();
element.setId(123);
element.setKey("alpha");
element.setSubkey(null);
element.setSize(10);
element.setDigest("qsdkfqskjf");
element.setCreationDate(DateTime.now().minusDays(11));
element.setEditionDate(DateTime.now().minusDays(11));
element.setArchiveDate(DateTime.now().minusDays(10));
element.setValue("bonjour");
database.put(element);
Assert.assertEquals(1, database.countOfElements());
// TODO Assert.assertEquals(1, database.countOfArchivedElements());
// TODO Assert.assertEquals(1, database.countOfAllElements());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testPutElement03() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
{
Element element = new Element();
element.setId(123);
element.setKey("alpha");
element.setSubkey(null);
element.setSize(10);
element.setDigest("qsdkfqskjf");
element.setCreationDate(DateTime.now().minusDays(11));
element.setEditionDate(DateTime.now().minusDays(11));
element.setArchiveDate(DateTime.now().minusDays(10));
element.setValue("bonjour");
database.put(element);
}
{
Element element = new Element();
element.setKey("bravo");
element.setSubkey(null);
element.setSize(10);
element.setDigest("qsdkfqskjf");
element.setCreationDate(DateTime.now().minusDays(11));
element.setEditionDate(DateTime.now().minusDays(11));
element.setArchiveDate(DateTime.now().minusDays(10));
element.setValue("bonjour");
database.put(element);
}
// TODO Elements elements = database.getAllElements();
Elements elements = database.getElements();
Assert.assertEquals(2, elements.size());
Assert.assertEquals(2, database.countOfElements());
// TODO Assert.assertEquals(2, database.countOfArchivedElements());
// TODO Assert.assertEquals(2, database.countOfAllElements());
// TODO Assert.assertEquals(123, elements.get(0).getId());
// TODO Assert.assertEquals(124, elements.get(1).getId());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testRandom01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String surSource = RandomStringUtils.random(128);
String source = org.apache.commons.codec.binary.Base64.encodeBase64String(surSource.getBytes());
database.put("alpha01", source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
String surTarget = new String(Base64.decodeBase64(target));
Assert.assertEquals(surSource, surTarget);
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testRemove01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "bonjour";
database.put("alpha01", "bravo", source);
String target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source, target);
String source2 = "au revoir";
database.put("alpha01", "bravo", source2);
target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source2, target);
// TODO StringList targets = database.getArchivedValues("alpha01",
// "bravo");
// TODO Assert.assertEquals(1, targets.size());
// TODO Assert.assertEquals(source, targets.get(0));
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testRemoveMany01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
database.put("alpha01", "alpha", "Allo");
database.put("alpha01", "bravo", "Bonjour");
database.put("alpha01", "charlie", "Courage");
database.put("alpha01", "delta", "Droiture");
database.put("alpha01", "echo", "Europe");
database.put("alpha01", "fox", "Force");
database.put("alpha02", "alpha", "Allo");
database.put("alpha02", "bravo", "Bonjour");
database.put("alpha02", "charlie", "Courage");
database.put("alpha02", "delta", "Droiture");
database.put("alpha02", "echo", "Europe");
database.put("alpha02", "fox", "Force");
Assert.assertEquals(12, database.countOfElements());
database.removeMany("alpha01", "bravo", "delta", "fox");
Assert.assertEquals(9, database.countOfElements());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testRenameKey01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
database.put("alpha01", "val-alpha01");
database.put("alpha01s", "sub-alpha01", "val-alpha01");
database.put("alpha01s", "sub-alpha02", "val-alpha02");
database.put("alpha01s", "sub-alpha03", "val-alpha03");
database.put("alpha02s", "sub-alpha01", "val-alpha01");
database.put("alpha03s", "sub-alpha02", "val-alpha02");
database.put("alpha04s", "sub-alpha03", "val-alpha03");
database.renameKey("alpha01s", "november");
Elements targets = database.getElements();
Assert.assertEquals(7, targets.size());
Assert.assertEquals(3, database.getValues("november").size());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testSize01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
Assert.assertEquals(0, database.countOfElements());
// TODO Assert.assertEquals(0, database.countOfArchivedElements());
// TODO Assert.assertEquals(0, database.countOfAllElements());
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.remove("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.remove("alpha01s", "bravo3");
// System.out.println(database.countOfElements() + " " +
// database.countOfArchivedElements() + " " +
// database.countOfAllElements());
Assert.assertEquals(8, database.countOfElements());
// TODO Assert.assertEquals(4, database.countOfArchivedElements());
// TODO Assert.assertEquals(10, database.countOfAllElements());
database.clear();
Assert.assertEquals(0, database.countOfElements());
// TODO Assert.assertEquals(0, database.countOfArchivedElements());
// TODO Assert.assertEquals(0, database.countOfAllElements());
//
logger.debug("===== test done.");
}
/**
* @throws Exception
*/
@Test
public void testTittle01() throws Exception
{
//
logger.debug("===== test starting...");
database.clear();
String source = "ME ME MEààààà ıııı éééé";
database.put("alpha01", source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
//
logger.debug("===== test done.");
}
/**
*
*/
@AfterClass
public static void afterClass()
{
if (database != null)
{
database.close();
}
}
/**
* @throws SikevaDBException
*/
@BeforeClass
public static void beforeClass() throws SikevaDBException
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.DEBUG);
// Add ?profileSQL=true to generate huge logs.
// database = new SQLSikevaDB("com.mysql.jdbc.Driver",
// "jdbc:mysql://localhost:3306/sikevadb-test", "sikevadb-test",
// "12345678");
File rootDirectory = new File("/tmp/footest");
database = new FileTreeSikevaDB(rootDirectory, null, null);
if (!database.isCreated())
{
database.create();
}
database.open();
}
}

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * Copyright (C) 2013-2017 Christian Pierre MOMON, DEVINSY
* *
* This file is part of SikevaDB, simple key value database. * This file is part of SikevaDB, simple key value database.
* *
@ -18,11 +18,6 @@
*/ */
package fr.devinsy.sikevadb.sql; package fr.devinsy.sikevadb.sql;
import java.io.IOException;
import java.sql.SQLException;
import javax.naming.NamingException;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.log4j.BasicConfigurator; import org.apache.log4j.BasicConfigurator;
@ -34,10 +29,10 @@ import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import fr.devinsy.sikevadb.Element; import fr.devinsy.sikevadb.core.Element;
import fr.devinsy.sikevadb.Elements; import fr.devinsy.sikevadb.core.Elements;
import fr.devinsy.sikevadb.sql.SQLSikevaDB; import fr.devinsy.sikevadb.core.SikevaDBException;
import fr.devinsy.util.StringList; import fr.devinsy.util.strings.StringList;
/** /**
* *
@ -57,7 +52,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Element element = new Element(); Element element = new Element();
@ -74,11 +69,11 @@ public class SQLSikevaDBTest
database.put("alpha", "bravo", "toto"); database.put("alpha", "bravo", "toto");
database.clearArchive(5); // TODO database.clearArchive(5);
Assert.assertEquals(1, database.countOfElements()); Assert.assertEquals(1, database.countOfElements());
Assert.assertEquals(0, database.countOfArchivedElements()); // TODO Assert.assertEquals(0, database.countOfArchivedElements());
Assert.assertEquals(1, database.countOfAllElements()); // TODO Assert.assertEquals(1, database.countOfAllElements());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -86,7 +81,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testClearArchive02() throws Exception public void testClearArchive02() throws Exception
@ -94,7 +88,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Element element = new Element(); Element element = new Element();
@ -111,11 +105,11 @@ public class SQLSikevaDBTest
database.put("alpha", "bravo", "toto"); database.put("alpha", "bravo", "toto");
database.clearArchive(DateTime.now().minusDays(5)); // TODO database.clearArchive(DateTime.now().minusDays(5));
Assert.assertEquals(1, database.countOfElements()); Assert.assertEquals(1, database.countOfElements());
Assert.assertEquals(0, database.countOfArchivedElements()); // TODO Assert.assertEquals(0, database.countOfArchivedElements());
Assert.assertEquals(1, database.countOfAllElements()); // TODO Assert.assertEquals(1, database.countOfAllElements());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -123,7 +117,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testGeKeyse01() throws Exception public void testGeKeyse01() throws Exception
@ -131,7 +124,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
database.put("alpha01", "1234567890"); database.put("alpha01", "1234567890");
database.put("alpha01", "qlskjfmlqj"); database.put("alpha01", "qlskjfmlqj");
@ -154,7 +147,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testGeKeyse02() throws Exception public void testGeKeyse02() throws Exception
@ -162,7 +154,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
database.put("alpha01", "1234567890"); database.put("alpha01", "1234567890");
database.put("alpha01", "qlskjfmlqj"); database.put("alpha01", "qlskjfmlqj");
@ -190,7 +182,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testMemorySize01() throws Exception public void testMemorySize01() throws Exception
@ -198,7 +189,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Assert.assertEquals(0, database.memorySize()); Assert.assertEquals(0, database.memorySize());
@ -215,12 +206,12 @@ public class SQLSikevaDBTest
database.put("alpha01", "bravo4", "qlskjfmlqj"); database.put("alpha01", "bravo4", "qlskjfmlqj");
database.put("alpha01", "bravo5", "qlskjfmlqj"); database.put("alpha01", "bravo5", "qlskjfmlqj");
Assert.assertEquals(120, database.memorySize()); Assert.assertEquals(100, database.memorySize());
Assert.assertEquals(60, database.memorySize("alpha01")); Assert.assertEquals(60, database.memorySize("alpha01"));
Assert.assertEquals(10, database.memorySize("alpha03")); Assert.assertEquals(10, database.memorySize("alpha03"));
Assert.assertEquals(10, database.memorySize("alpha01", "bravo1")); Assert.assertEquals(10, database.memorySize("alpha01", "bravo1"));
database.clearDatabase(); database.clear();
Assert.assertEquals(0, database.memorySize()); Assert.assertEquals(0, database.memorySize());
@ -230,7 +221,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPut01() throws Exception public void testPut01() throws Exception
@ -238,7 +228,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha01", source); database.put("alpha01", source);
@ -251,7 +241,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPut02() throws Exception public void testPut02() throws Exception
@ -259,7 +248,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha01", source); database.put("alpha01", source);
@ -267,33 +256,22 @@ public class SQLSikevaDBTest
String target = database.getValue("alpha01"); String target = database.getValue("alpha01");
Assert.assertEquals(source, target); Assert.assertEquals(source, target);
target = database.getValue("alpha01", null);
Assert.assertEquals(source, target);
// //
logger.debug("===== test done."); logger.debug("===== test done.");
} }
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test(expected = IllegalArgumentException.class)
public void testPut03() throws Exception public void testPut03() throws Exception
{ {
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; database.getValue("foo", null);
database.put("alpha01", null, source);
String target = database.getValue("alpha01");
Assert.assertEquals(source, target);
target = database.getValue("alpha01", null);
Assert.assertEquals(source, target);
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -301,7 +279,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPut04() throws Exception public void testPut04() throws Exception
@ -309,7 +286,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha02", "bravo", source); database.put("alpha02", "bravo", source);
@ -323,7 +300,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPut05() throws Exception public void testPut05() throws Exception
@ -331,7 +307,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha01", source); database.put("alpha01", source);
@ -345,9 +321,9 @@ public class SQLSikevaDBTest
target = database.getValue("alpha01"); target = database.getValue("alpha01");
Assert.assertEquals(source2, target); Assert.assertEquals(source2, target);
StringList targets = database.getArchivedValues("alpha01"); // TODO StringList targets = database.getArchivedValues("alpha01");
Assert.assertEquals(1, targets.size()); // TODO Assert.assertEquals(1, targets.size());
Assert.assertEquals(source, targets.get(0)); // TODO Assert.assertEquals(source, targets.get(0));
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -355,7 +331,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPut06() throws Exception public void testPut06() throws Exception
@ -363,7 +338,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha01", "bravo", source); database.put("alpha01", "bravo", source);
@ -377,9 +352,10 @@ public class SQLSikevaDBTest
target = database.getValue("alpha01", "bravo"); target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source2, target); Assert.assertEquals(source2, target);
StringList targets = database.getArchivedValues("alpha01", "bravo"); // TODO StringList targets = database.getArchivedValues("alpha01",
Assert.assertEquals(1, targets.size()); // "bravo");
Assert.assertEquals(source, targets.get(0)); // TODO Assert.assertEquals(1, targets.size());
// TODO Assert.assertEquals(source, targets.get(0));
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -387,7 +363,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPutElement01() throws Exception public void testPutElement01() throws Exception
@ -395,7 +370,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Element element = new Element(); Element element = new Element();
@ -411,8 +386,8 @@ public class SQLSikevaDBTest
database.put(element); database.put(element);
Assert.assertEquals(0, database.countOfElements()); Assert.assertEquals(0, database.countOfElements());
Assert.assertEquals(1, database.countOfArchivedElements()); // TODO Assert.assertEquals(1, database.countOfArchivedElements());
Assert.assertEquals(1, database.countOfAllElements()); // TODO Assert.assertEquals(1, database.countOfAllElements());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -420,7 +395,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPutElement02() throws Exception public void testPutElement02() throws Exception
@ -428,7 +402,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Element element = new Element(); Element element = new Element();
@ -445,8 +419,8 @@ public class SQLSikevaDBTest
database.put(element); database.put(element);
Assert.assertEquals(0, database.countOfElements()); Assert.assertEquals(0, database.countOfElements());
Assert.assertEquals(1, database.countOfArchivedElements()); // TODO Assert.assertEquals(1, database.countOfArchivedElements());
Assert.assertEquals(1, database.countOfAllElements()); // TODO Assert.assertEquals(1, database.countOfAllElements());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -454,7 +428,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testPutElement03() throws Exception public void testPutElement03() throws Exception
@ -462,7 +435,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
{ {
Element element = new Element(); Element element = new Element();
@ -495,14 +468,15 @@ public class SQLSikevaDBTest
database.put(element); database.put(element);
} }
Elements elements = database.getAllElements(); // TODO Elements elements = database.getAllElements();
Elements elements = database.getElements();
Assert.assertEquals(0, database.countOfElements()); Assert.assertEquals(0, database.countOfElements());
Assert.assertEquals(2, database.countOfArchivedElements()); // TODO Assert.assertEquals(2, database.countOfArchivedElements());
Assert.assertEquals(2, database.countOfAllElements()); // TODO Assert.assertEquals(2, database.countOfAllElements());
Assert.assertEquals(123, elements.get(0).getId()); // TODO Assert.assertEquals(123, elements.get(0).getId());
Assert.assertEquals(124, elements.get(1).getId()); // TODO Assert.assertEquals(124, elements.get(1).getId());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -510,7 +484,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testRandom01() throws Exception public void testRandom01() throws Exception
@ -518,11 +491,11 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String surSource = RandomStringUtils.random(128); String surSource = RandomStringUtils.random(128);
String source = org.apache.commons.codec.binary.Base64.encodeBase64String(surSource.getBytes()); String source = org.apache.commons.codec.binary.Base64.encodeBase64String(surSource.getBytes());
database.put("alpha01", null, source); database.put("alpha01", source);
String target = database.getValue("alpha01"); String target = database.getValue("alpha01");
Assert.assertEquals(source, target); Assert.assertEquals(source, target);
@ -536,7 +509,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testRemove01() throws Exception public void testRemove01() throws Exception
@ -544,7 +516,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "bonjour"; String source = "bonjour";
database.put("alpha01", "bravo", source); database.put("alpha01", "bravo", source);
@ -558,9 +530,10 @@ public class SQLSikevaDBTest
target = database.getValue("alpha01", "bravo"); target = database.getValue("alpha01", "bravo");
Assert.assertEquals(source2, target); Assert.assertEquals(source2, target);
StringList targets = database.getArchivedValues("alpha01", "bravo"); // TODO StringList targets = database.getArchivedValues("alpha01",
Assert.assertEquals(1, targets.size()); // "bravo");
Assert.assertEquals(source, targets.get(0)); // TODO Assert.assertEquals(1, targets.size());
// TODO Assert.assertEquals(source, targets.get(0));
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -568,7 +541,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testRemoveMany01() throws Exception public void testRemoveMany01() throws Exception
@ -576,7 +548,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
database.put("alpha01", "alpha", "Allo"); database.put("alpha01", "alpha", "Allo");
database.put("alpha01", "bravo", "Bonjour"); database.put("alpha01", "bravo", "Bonjour");
@ -604,7 +576,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testRenameKey01() throws Exception public void testRenameKey01() throws Exception
@ -612,7 +583,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
database.put("alpha01", "val-alpha01"); database.put("alpha01", "val-alpha01");
database.put("alpha01", "sub-alpha01", "val-alpha01"); database.put("alpha01", "sub-alpha01", "val-alpha01");
@ -624,7 +595,7 @@ public class SQLSikevaDBTest
database.renameKey("alpha01", "november"); database.renameKey("alpha01", "november");
Elements targets = database.getAllElements(); Elements targets = database.getElements();
Assert.assertEquals(7, targets.size()); Assert.assertEquals(7, targets.size());
Assert.assertEquals(3, database.getValues("november").size()); Assert.assertEquals(3, database.getValues("november").size());
@ -635,7 +606,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testSize01() throws Exception public void testSize01() throws Exception
@ -643,11 +613,11 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
Assert.assertEquals(0, database.countOfElements()); Assert.assertEquals(0, database.countOfElements());
Assert.assertEquals(0, database.countOfArchivedElements()); // TODO Assert.assertEquals(0, database.countOfArchivedElements());
Assert.assertEquals(0, database.countOfAllElements()); // TODO Assert.assertEquals(0, database.countOfAllElements());
database.put("alpha01", "qlskjfmlqja"); database.put("alpha01", "qlskjfmlqja");
database.put("alpha01", "qlskjfmlqjb"); database.put("alpha01", "qlskjfmlqjb");
@ -655,7 +625,6 @@ public class SQLSikevaDBTest
database.put("alpha03", "qlskjfmlqj"); database.put("alpha03", "qlskjfmlqj");
database.put("alpha04", "qlskjfmlqj"); database.put("alpha04", "qlskjfmlqj");
database.put("alpha05", "qlskjfmlqj"); database.put("alpha05", "qlskjfmlqj");
database.archive("alpha02");
database.remove("alpha03"); database.remove("alpha03");
database.put("alpha01", "bravo1", "qlskjfmlqja"); database.put("alpha01", "bravo1", "qlskjfmlqja");
database.put("alpha01", "bravo1", "qlskjfmlqjb"); database.put("alpha01", "bravo1", "qlskjfmlqjb");
@ -663,22 +632,21 @@ public class SQLSikevaDBTest
database.put("alpha01", "bravo3", "qlskjfmlqj"); database.put("alpha01", "bravo3", "qlskjfmlqj");
database.put("alpha01", "bravo4", "qlskjfmlqj"); database.put("alpha01", "bravo4", "qlskjfmlqj");
database.put("alpha01", "bravo5", "qlskjfmlqj"); database.put("alpha01", "bravo5", "qlskjfmlqj");
database.archive("alpha01", "bravo2");
database.remove("alpha01", "bravo3"); database.remove("alpha01", "bravo3");
// System.out.println(database.countOfElements() + " " + // System.out.println(database.countOfElements() + " " +
// database.countOfArchivedElements() + " " + // database.countOfArchivedElements() + " " +
// database.countOfAllElements()); // database.countOfAllElements());
Assert.assertEquals(6, database.countOfElements()); Assert.assertEquals(8, database.countOfElements());
Assert.assertEquals(4, database.countOfArchivedElements()); // TODO Assert.assertEquals(4, database.countOfArchivedElements());
Assert.assertEquals(10, database.countOfAllElements()); // TODO Assert.assertEquals(10, database.countOfAllElements());
database.clearDatabase(); database.clear();
Assert.assertEquals(0, database.countOfElements()); Assert.assertEquals(0, database.countOfElements());
Assert.assertEquals(0, database.countOfArchivedElements()); // TODO Assert.assertEquals(0, database.countOfArchivedElements());
Assert.assertEquals(0, database.countOfAllElements()); // TODO Assert.assertEquals(0, database.countOfAllElements());
// //
logger.debug("===== test done."); logger.debug("===== test done.");
@ -686,7 +654,6 @@ public class SQLSikevaDBTest
/** /**
* @throws Exception * @throws Exception
*
*/ */
@Test @Test
public void testTittle01() throws Exception public void testTittle01() throws Exception
@ -694,7 +661,7 @@ public class SQLSikevaDBTest
// //
logger.debug("===== test starting..."); logger.debug("===== test starting...");
database.clearDatabase(); database.clear();
String source = "ME ME MEààààà ıııı éééé"; String source = "ME ME MEààààà ıııı éééé";
database.put("alpha01", source); database.put("alpha01", source);
@ -718,16 +685,10 @@ public class SQLSikevaDBTest
} }
/** /**
* @throws NamingException * @throws SikevaDBException
* @throws SQLException
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws IOException
*
*/ */
@BeforeClass @BeforeClass
public static void beforeClass() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException, IOException public static void beforeClass() throws SikevaDBException
{ {
BasicConfigurator.configure(); BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR); Logger.getRootLogger().setLevel(Level.ERROR);
@ -740,6 +701,6 @@ public class SQLSikevaDBTest
database = new SQLSikevaDB("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:sikevadb-unittest;sql.syntax_mys=true", "sa", ""); database = new SQLSikevaDB("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:sikevadb-unittest;sql.syntax_mys=true", "sa", "");
database.open(); database.open();
database.createSchema(); database.create();
} }
} }