From 40e49a3bbb0ef730483c94df290ba461a3633f26 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 28 Feb 2018 11:15:47 +0100 Subject: [PATCH] Delete unopened database check in close method. --- .../sikevadb/filetree/FileTreeSikevaDB.java | 194 +++++++++--------- 1 file changed, 95 insertions(+), 99 deletions(-) diff --git a/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java b/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java index 9a00e99..68603d2 100644 --- a/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java +++ b/src/fr/devinsy/sikevadb/filetree/FileTreeSikevaDB.java @@ -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) */