Delete unopened database check in close method.

This commit is contained in:
Christian P. MOMON 2018-02-28 11:15:47 +01:00
parent a17ca91389
commit 40e49a3bbb

View file

@ -115,13 +115,9 @@ public class FileTreeSikevaDB implements SikevaDB
* @see fr.devinsy.sikevadb.core.SikevaDB#close()
*/
@Override
public void close() throws UnopenedDatabaseException
public void close()
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else
if (this.status != Status.CLOSED)
{
this.journalizer = null;
@ -271,6 +267,99 @@ public class FileTreeSikevaDB implements SikevaDB
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#remove(java.lang.String)
*/
@Override
public void delete(final String key) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else 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() + "]");
}
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#remove(java.lang.String, java.lang.String)
*/
@Override
public void delete(final String key, final String subkey) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else 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() + "]");
}
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#removeMany(java.lang.String, java.lang.String[])
*/
@Override
public void deleteMany(final String key, final String... subkeys) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else if (key == null)
{
throw new IllegalArgumentException("Null key detected.");
}
else
{
if ((subkeys != null) && (subkeys.length > 0))
{
for (String subkey : subkeys)
{
delete(key, subkey);
}
}
}
}
/**
* Gets the config directory.
*
@ -1001,99 +1090,6 @@ public class FileTreeSikevaDB implements SikevaDB
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#remove(java.lang.String)
*/
@Override
public void delete(final String key) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else 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() + "]");
}
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#remove(java.lang.String, java.lang.String)
*/
@Override
public void delete(final String key, final String subkey) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else 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() + "]");
}
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#removeMany(java.lang.String, java.lang.String[])
*/
@Override
public void deleteMany(final String key, final String... subkeys) throws SikevaDBException
{
if (this.status == Status.CLOSED)
{
throw new UnopenedDatabaseException();
}
else if (key == null)
{
throw new IllegalArgumentException("Null key detected.");
}
else
{
if ((subkeys != null) && (subkeys.length > 0))
{
for (String subkey : subkeys)
{
delete(key, subkey);
}
}
}
}
/* (non-Javadoc)
* @see fr.devinsy.sikevadb.core.SikevaDB#renameKey(java.lang.String, java.lang.String)
*/