Makes SQLite deletion of non-existent items fail silently

Adds JavaDoc to make this clear.

https://github.com/BentoBoxWorld/BentoBox/issues/1010
This commit is contained in:
tastybento 2019-10-26 11:56:12 -07:00
parent d5d6f20bb9
commit 1304f8bace
2 changed files with 6 additions and 7 deletions

View File

@ -148,7 +148,8 @@ public abstract class AbstractDatabaseHandler<T> {
public abstract void saveObject(T instance) throws IllegalAccessException, InvocationTargetException, IntrospectionException ;
/**
* Deletes the object with the unique id from the database
* Deletes the object with the unique id from the database. If the object does not exist, it will fail silently.
* Use {@link #objectExists(String)} if you need to know if the object is in the database beforehand.
* @param instance - object instance
*/
public abstract void deleteObject(T instance) throws IllegalAccessException, InvocationTargetException, IntrospectionException ;
@ -166,7 +167,8 @@ public abstract class AbstractDatabaseHandler<T> {
public abstract void close();
/**
* Attempts to delete the object with the uniqueId
* Attempts to delete the object with the uniqueId. If the object does not exist, it will fail silently.
* Use {@link #objectExists(String)} if you need to know if the object is in the database beforehand.
* @param uniqueId - uniqueId of object
* @since 1.1
*/

View File

@ -69,10 +69,7 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getDeleteObjectSQL())) {
// UniqueId must *not* be placed in quotes
preparedStatement.setString(1, uniqueId);
int result = preparedStatement.executeUpdate();
if (result != 1) {
throw new SQLException("Delete did not affect any rows!");
}
preparedStatement.executeUpdate();
} catch (Exception e) {
plugin.logError("Could not delete object " + dataObject.getCanonicalName() + " " + uniqueId + " " + e.getMessage());
}