From bff4d871648824fc6c3151ce98ba9a55556b275c Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 22 May 2022 00:32:08 +0200 Subject: [PATCH] Code cleanup --- .../java/it/cavallium/dbengine/database/LLUtils.java | 5 +++-- .../database/collections/DatabaseMapDictionary.java | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/database/LLUtils.java b/src/main/java/it/cavallium/dbengine/database/LLUtils.java index c87e86f..5f21710 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLUtils.java +++ b/src/main/java/it/cavallium/dbengine/database/LLUtils.java @@ -809,8 +809,8 @@ public class LLUtils { public static Mono> mapLLDelta(Mono mono, SerializationFunction<@NotNull Buffer, @Nullable U> mapper) { return Mono.usingWhen(mono, delta -> Mono.fromCallable(() -> { - Buffer prev = delta.previousUnsafe(); - Buffer curr = delta.currentUnsafe(); + try (Buffer prev = delta.previousUnsafe(); + Buffer curr = delta.currentUnsafe()) { U newPrev; U newCurr; if (prev != null) { @@ -824,6 +824,7 @@ public class LLUtils { newCurr = null; } return new Delta<>(newPrev, newCurr); + } }), delta -> Mono.fromRunnable(delta::close)); } diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java index ab645d6..e2725e4 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -281,10 +281,10 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep putValue(T keySuffix, U value) { var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix)).single(); var valueMono = Mono.fromCallable(() -> serializeValue(value)).single(); - return dictionary - .put(keyMono, valueMono, LLDictionaryResultType.VOID) - .doOnNext(Resource::close) - .then(); + return Mono.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.VOID), + v -> Mono.empty(), + v -> Mono.fromRunnable(v::close) + ); } @Override @@ -316,7 +316,9 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep