Return true if database save executed.

Fixes bug where if no change was made it was reporting an error.
This commit is contained in:
tastybento 2020-05-01 16:04:25 -07:00 committed by Florian CUNY
parent 6a28ba0b1d
commit 7bfbfe78a3
4 changed files with 8 additions and 4 deletions

View File

@ -133,7 +133,8 @@ public class MongoDBDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
// Set the options to upsert (update or insert if doc is not there)
FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().upsert(true);
// Do the deed
completableFuture.complete(collection.findOneAndReplace(filter, document, options) != null);
collection.findOneAndReplace(filter, document, options);
completableFuture.complete(true);
} catch (Exception e) {
plugin.logError("Could not save object " + instance.getClass().getName() + " " + e.getMessage());
completableFuture.complete(false);

View File

@ -169,7 +169,8 @@ public class SQLDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
preparedStatement.setString(1, toStore);
preparedStatement.setString(2, toStore);
completableFuture.complete(preparedStatement.execute());
preparedStatement.execute();
completableFuture.complete(true);
} catch (SQLException e) {
plugin.logError("Could not save object " + name + " " + e.getMessage());
completableFuture.complete(false);

View File

@ -73,7 +73,8 @@ public class PostgreSQLDatabaseHandler<T> extends SQLDatabaseHandler<T> {
preparedStatement.setString(1, uniqueId); // INSERT
preparedStatement.setString(2, toStore); // INSERT
preparedStatement.setString(3, toStore); // ON CONFLICT
completableFuture.complete(preparedStatement.execute());
preparedStatement.execute();
completableFuture.complete(true);
} catch (SQLException e) {
plugin.logError("Could not save object " + instance.getClass().getName() + " " + e.getMessage());
completableFuture.complete(false);

View File

@ -60,7 +60,8 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
preparedStatement.setString(1, toStore);
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
preparedStatement.setString(3, toStore);
completableFuture.complete(preparedStatement.execute());
preparedStatement.execute();
completableFuture.complete(true);
} catch (SQLException e) {
plugin.logError("Could not save object " + instance.getClass().getName() + " " + e.getMessage());
completableFuture.complete(false);