Reviewed Javadoc fo SikevaDB interface. Renamed remove method with
delete.
This commit is contained in:
parent
70ed239209
commit
cea1dd448e
6 changed files with 685 additions and 324 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 Christian Pierre MOMON <christian.momon@devinsy.fr>
|
||||
* Copyright (C) 2013-2018 Christian Pierre MOMON <christian.momon@devinsy.fr>
|
||||
*
|
||||
* This file is part of SikevaDB, simple key value database.
|
||||
*
|
||||
|
@ -27,89 +27,450 @@ import fr.devinsy.util.strings.StringList;
|
|||
*/
|
||||
public interface SikevaDB
|
||||
{
|
||||
/**
|
||||
* Archiver.
|
||||
*
|
||||
* @return the archiver
|
||||
* @throws SikevaDBException
|
||||
* the sikeva DB exception
|
||||
*/
|
||||
public Archiver archiver() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Delete all elements of current opened database.
|
||||
*
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public void clear() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Close the current database session.
|
||||
*
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public void close() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Count of elements in current database.
|
||||
*
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long countOfElements() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Count of elements by key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long countOfElements(String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Count of elements by key and sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long countOfElements(String key, long subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Count of elements by key and sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the subkey
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long countOfElements(String key, String subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Creates the database.
|
||||
*
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public void create() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Delete an database element with its key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void delete(final String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Delete an database element with its key and subkey.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void delete(final String key, final long subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Delete an database element with its key and subkey.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void delete(final String key, final String subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Delete many database elements from key and sub keys.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkeys
|
||||
* the subkeys
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void deleteMany(final String key, final String... subkeys) throws SikevaDBException;
|
||||
|
||||
public void destroy() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets an element by key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the element
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public Element getElement(String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets an element by key and sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the element
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public Element getElement(String key, long subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets an element by key and sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the element
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public Element getElement(String key, String subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets all elements in current database.
|
||||
*
|
||||
* @return the elements
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public Elements getElements() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets all elements of a top key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the elements
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public Elements getElements(String key) throws SikevaDBException;
|
||||
|
||||
public fr.devinsy.util.strings.StringList getKeys() throws SikevaDBException;
|
||||
/**
|
||||
* Gets all the top keys.
|
||||
*
|
||||
* @return the keys
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public StringList getKeys() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets all the sub keys of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the subkeys
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public StringList getSubkeys(String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets the value of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public String getValue(String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets the value of a key and a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public String getValue(String key, long subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets the value of a key and a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public String getValue(String key, String subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Gets the values of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the values
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public StringList getValues(String key) throws SikevaDBException;
|
||||
|
||||
boolean isArchiveActivated();
|
||||
|
||||
boolean isArchiveSuspended();
|
||||
|
||||
/**
|
||||
* Checks if is closed.
|
||||
*
|
||||
* @return true, if is closed
|
||||
*/
|
||||
public boolean isClosed();
|
||||
|
||||
/**
|
||||
* Checks if is created.
|
||||
*
|
||||
* @return true, if is created
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public boolean isCreated() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Checks if is opened.
|
||||
*
|
||||
* @return true, if is opened
|
||||
*/
|
||||
public boolean isOpened();
|
||||
|
||||
/**
|
||||
* Returns the memory size of the elements in database.
|
||||
*
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long memorySize() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Returns the memory size of elements of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long memorySize(String key) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Returns the memory size of element of a key and a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long memorySize(String key, long subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Returns the memory size of element of a key and a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @return the long
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
public long memorySize(String key, String subkey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Open a database.
|
||||
*
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void open() throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Put an element in database.
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void put(Element element) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Put a value for a key and a sub key in current opened database.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @param value
|
||||
* the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void put(String key, long subkey, String value) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Put a value for a key in current opened database.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param value
|
||||
* the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void put(String key, String value) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Put a value for a key and a sub key in current opened database.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param subkey
|
||||
* the sub key
|
||||
* @param value
|
||||
* the value
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void put(String key, String subkey, String value) throws SikevaDBException;
|
||||
|
||||
void remove(final String key) throws SikevaDBException;
|
||||
|
||||
void remove(final String key, final long subkey) throws SikevaDBException;
|
||||
|
||||
void remove(final String key, final String subkey) throws SikevaDBException;
|
||||
|
||||
void removeMany(final String key, final String... subkeys) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Rename a key.
|
||||
*
|
||||
* @param oldKey
|
||||
* the old key
|
||||
* @param newKey
|
||||
* the new key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void renameKey(final String oldKey, final String newKey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Rename a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param oldSubKey
|
||||
* the old sub key
|
||||
* @param newSubKey
|
||||
* the new sub key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void renameSubkey(final String key, final long oldSubKey, final long newSubKey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Rename a sub key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param oldSubKey
|
||||
* the old sub key
|
||||
* @param newSubKey
|
||||
* the new sub key
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void renameSubkey(final String key, final String oldSubKey, final String newSubKey) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Replace a substring in a value of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param tokens
|
||||
* the tokens
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void replaceInValue(final String key, final String... tokens) throws SikevaDBException;
|
||||
|
||||
/**
|
||||
* Replace a substring in values of all sub keys of a key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param tokens
|
||||
* the tokens
|
||||
* @throws SikevaDBException
|
||||
* the SikevaDB exception
|
||||
*/
|
||||
void replaceInValues(final String key, final String... tokens) throws SikevaDBException;
|
||||
}
|
||||
|
|
|
@ -87,14 +87,14 @@ public final class SikevaDBDemo
|
|||
}
|
||||
|
||||
//
|
||||
database.remove("alpha");
|
||||
database.delete("alpha");
|
||||
if (database.getValue("alpha") == null)
|
||||
{
|
||||
System.out.println("alpha is correctly removed.");
|
||||
System.out.println("alpha is correctly deleted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("alpha is NOT correctly removed.");
|
||||
System.out.println("alpha is NOT correctly deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,14 +116,14 @@ public final class SikevaDBDemo
|
|||
}
|
||||
|
||||
//
|
||||
database.remove("victor", 5);
|
||||
database.delete("victor", 5);
|
||||
if (database.getValue("victor", 5) == null)
|
||||
{
|
||||
System.out.println("(victor, 5) is correctly removed.");
|
||||
System.out.println("(victor, 5) is correctly deleted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("(victor, 5) is NOT correctly removed.");
|
||||
System.out.println("(victor, 5) is NOT correctly deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ public class FileTreeSikevaDB implements SikevaDB
|
|||
CLOSED
|
||||
};
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(FileTreeSikevaDB.class);
|
||||
private static final DateTimeFormatter ISOFormatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
|
||||
private final Logger logger = LoggerFactory.getLogger(FileTreeSikevaDB.class);
|
||||
|
||||
private Status status;
|
||||
private String login;
|
||||
|
@ -323,6 +323,121 @@ public class FileTreeSikevaDB implements SikevaDB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
File targetFile = new File(this.dataDirectory, key);
|
||||
|
||||
if (targetFile.isFile())
|
||||
{
|
||||
boolean result = targetFile.delete();
|
||||
if (!result)
|
||||
{
|
||||
throw new SikevaDBException("Error removing [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid target to remove [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key, final long subkey) throws SikevaDBException
|
||||
{
|
||||
delete(key, String.valueOf(subkey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key, final String subkey) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if ((key == null) || (subkey == null))
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected [key=" + key + "][subkey=" + subkey + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
File targetDirectory = new File(this.dataDirectory, key);
|
||||
File targetFile = new File(targetDirectory, subkey);
|
||||
|
||||
if (targetFile.isFile())
|
||||
{
|
||||
boolean result = targetFile.delete();
|
||||
if (!result)
|
||||
{
|
||||
throw new SikevaDBException("Error removing [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid target to remove [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void deleteMany(final String key, final String... subkeys) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((subkeys != null) && (subkeys.length > 0))
|
||||
{
|
||||
for (String subkey : subkeys)
|
||||
{
|
||||
delete(key, subkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (opened).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -1260,121 +1375,6 @@ public class FileTreeSikevaDB implements SikevaDB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
File targetFile = new File(this.dataDirectory, key);
|
||||
|
||||
if (targetFile.isFile())
|
||||
{
|
||||
boolean result = targetFile.delete();
|
||||
if (!result)
|
||||
{
|
||||
throw new SikevaDBException("Error removing [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid target to remove [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key, final long subkey) throws SikevaDBException
|
||||
{
|
||||
remove(key, String.valueOf(subkey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key, final String subkey) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if ((key == null) || (subkey == null))
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected [key=" + key + "][subkey=" + subkey + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
File targetDirectory = new File(this.dataDirectory, key);
|
||||
File targetFile = new File(targetDirectory, subkey);
|
||||
|
||||
if (targetFile.isFile())
|
||||
{
|
||||
boolean result = targetFile.delete();
|
||||
if (!result)
|
||||
{
|
||||
throw new SikevaDBException("Error removing [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid target to remove [" + targetFile.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void removeMany(final String key, final String... subkeys) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null key detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((subkeys != null) && (subkeys.length > 0))
|
||||
{
|
||||
for (String subkey : subkeys)
|
||||
{
|
||||
remove(key, subkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (opened).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -500,6 +500,192 @@ public class SQLSikevaDB implements SikevaDB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, key);
|
||||
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing element.", exception);
|
||||
try
|
||||
{
|
||||
connection.rollback();
|
||||
}
|
||||
catch (SQLException exception1)
|
||||
{
|
||||
logger.error("Rollback failed.", exception);
|
||||
}
|
||||
throw new SikevaDBException("Error removing element", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key, final long subkey) throws SikevaDBException
|
||||
{
|
||||
delete(key, String.valueOf(subkey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String key, final String subkey) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else if (subkey == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Subkey is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing subkey.", exception);
|
||||
throw new SikevaDBException("Error removing subkey", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (opened).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void deleteMany(final String key, final String... subkeys) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else if ((subkeys != null) && (subkeys.length > 0))
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
|
||||
//
|
||||
String questionMarks = new StringList(subkeys.length).append('?').repeatLast(subkeys.length - 1).toStringWithCommas();
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IN (" + questionMarks + ") AND ARCHIVE_DATE IS NULL");
|
||||
//
|
||||
statement.setString(1, key);
|
||||
|
||||
//
|
||||
for (int index = 0; index < subkeys.length; index++)
|
||||
{
|
||||
statement.setString(2 + index, subkeys[index]);
|
||||
}
|
||||
|
||||
//
|
||||
int rowCount = statement.executeUpdate();
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "][subkeys=" + new StringList(subkeys).toStringWithCommas() + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing subkeys.", exception);
|
||||
throw new SikevaDBException("Error removing subkeys", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -1974,192 +2160,6 @@ public class SQLSikevaDB implements SikevaDB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, key);
|
||||
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing element.", exception);
|
||||
try
|
||||
{
|
||||
connection.rollback();
|
||||
}
|
||||
catch (SQLException exception1)
|
||||
{
|
||||
logger.error("Rollback failed.", exception);
|
||||
}
|
||||
throw new SikevaDBException("Error removing element", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key, final long subkey) throws SikevaDBException
|
||||
{
|
||||
remove(key, String.valueOf(subkey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void remove(final String key, final String subkey) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else if (subkey == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Subkey is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL");
|
||||
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
|
||||
int rowCount = statement.executeUpdate();
|
||||
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing subkey.", exception);
|
||||
throw new SikevaDBException("Error removing subkey", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (opened).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void removeMany(final String key, final String... subkeys) throws SikevaDBException
|
||||
{
|
||||
if (isOpened())
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Key is null.");
|
||||
}
|
||||
else if ((subkeys != null) && (subkeys.length > 0))
|
||||
{
|
||||
//
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
connection = getConnection();
|
||||
|
||||
//
|
||||
String questionMarks = new StringList(subkeys.length).append('?').repeatLast(subkeys.length - 1).toStringWithCommas();
|
||||
statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IN (" + questionMarks + ") AND ARCHIVE_DATE IS NULL");
|
||||
//
|
||||
statement.setString(1, key);
|
||||
|
||||
//
|
||||
for (int index = 0; index < subkeys.length; index++)
|
||||
{
|
||||
statement.setString(2 + index, subkeys[index]);
|
||||
}
|
||||
|
||||
//
|
||||
int rowCount = statement.executeUpdate();
|
||||
if (rowCount == 0)
|
||||
{
|
||||
logger.warn("Remove action without existing target [key=" + key + "][subkeys=" + new StringList(subkeys).toStringWithCommas() + "]");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("Error removing subkeys.", exception);
|
||||
throw new SikevaDBException("Error removing subkeys", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeQuietly(connection, statement, resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SikevaDBException("Invalid database status (closed).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -544,7 +544,7 @@ public class TreeFileSikevaDBTest
|
|||
|
||||
Assert.assertEquals(12, database.countOfElements());
|
||||
|
||||
database.removeMany("alpha01", "bravo", "delta", "fox");
|
||||
database.deleteMany("alpha01", "bravo", "delta", "fox");
|
||||
|
||||
Assert.assertEquals(9, database.countOfElements());
|
||||
|
||||
|
@ -609,14 +609,14 @@ public class TreeFileSikevaDBTest
|
|||
database.put("alpha03", "qlskjfmlqj");
|
||||
database.put("alpha04", "qlskjfmlqj");
|
||||
database.put("alpha05", "qlskjfmlqj");
|
||||
database.remove("alpha03");
|
||||
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.remove("alpha01s", "bravo3");
|
||||
database.delete("alpha01s", "bravo3");
|
||||
|
||||
// System.out.println(database.countOfElements() + " " +
|
||||
// database.countOfArchivedElements() + " " +
|
||||
|
|
|
@ -567,7 +567,7 @@ public class SQLSikevaDBTest
|
|||
|
||||
Assert.assertEquals(12, database.countOfElements());
|
||||
|
||||
database.removeMany("alpha01", "bravo", "delta", "fox");
|
||||
database.deleteMany("alpha01", "bravo", "delta", "fox");
|
||||
|
||||
Assert.assertEquals(9, database.countOfElements());
|
||||
|
||||
|
@ -626,14 +626,14 @@ public class SQLSikevaDBTest
|
|||
database.put("alpha03", "qlskjfmlqj");
|
||||
database.put("alpha04", "qlskjfmlqj");
|
||||
database.put("alpha05", "qlskjfmlqj");
|
||||
database.remove("alpha03");
|
||||
database.delete("alpha03");
|
||||
database.put("alpha01", "bravo1", "qlskjfmlqja");
|
||||
database.put("alpha01", "bravo1", "qlskjfmlqjb");
|
||||
database.put("alpha01", "bravo2", "qlskjfmlqj");
|
||||
database.put("alpha01", "bravo3", "qlskjfmlqj");
|
||||
database.put("alpha01", "bravo4", "qlskjfmlqj");
|
||||
database.put("alpha01", "bravo5", "qlskjfmlqj");
|
||||
database.remove("alpha01", "bravo3");
|
||||
database.delete("alpha01", "bravo3");
|
||||
|
||||
// System.out.println(database.countOfElements() + " " +
|
||||
// database.countOfArchivedElements() + " " +
|
||||
|
|
Loading…
Reference in a new issue