mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-26 20:55:41 +01:00
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:
parent
d5d6f20bb9
commit
1304f8bace
@ -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
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
}
|
||||
Gson gson = getGson();
|
||||
String toStore = gson.toJson(instance);
|
||||
processQueue.add(() -> {
|
||||
processQueue.add(() -> {
|
||||
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getSaveObjectSQL())) {
|
||||
preparedStatement.setString(1, toStore);
|
||||
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
|
||||
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user