From a6c1f2259ecf21bc7ab3eed29e6dfe87c74fc401 Mon Sep 17 00:00:00 2001 From: Robert Gruber Date: Mon, 18 Mar 2024 11:01:06 +0000 Subject: [PATCH] Extract mongo version to interface (#228) --- .../java/de/bwaldvogel/mongo/MongoBackend.java | 2 +- .../java/de/bwaldvogel/mongo/MongoVersion.java | 17 +++++++++++++++++ .../java/de/bwaldvogel/mongo/ServerVersion.java | 8 +------- .../mongo/backend/AbstractMongoBackend.java | 5 +++-- .../bwaldvogel/mongo/backend/ReadOnlyProxy.java | 4 ++-- 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/de/bwaldvogel/mongo/MongoVersion.java diff --git a/core/src/main/java/de/bwaldvogel/mongo/MongoBackend.java b/core/src/main/java/de/bwaldvogel/mongo/MongoBackend.java index 92e53ce5..1c003a9a 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/MongoBackend.java +++ b/core/src/main/java/de/bwaldvogel/mongo/MongoBackend.java @@ -38,6 +38,6 @@ public interface MongoBackend { MongoDatabase resolveDatabase(String database); - MongoBackend version(ServerVersion version); + MongoBackend version(MongoVersion version); } diff --git a/core/src/main/java/de/bwaldvogel/mongo/MongoVersion.java b/core/src/main/java/de/bwaldvogel/mongo/MongoVersion.java new file mode 100644 index 00000000..a1cdb6e3 --- /dev/null +++ b/core/src/main/java/de/bwaldvogel/mongo/MongoVersion.java @@ -0,0 +1,17 @@ +package de.bwaldvogel.mongo; + +import java.util.List; + +import de.bwaldvogel.mongo.backend.Utils; + +public interface MongoVersion { + + List getVersionArray(); + + default String toVersionString() { + return Utils.join(getVersionArray(), "."); + } + + int getWireVersion(); + +} diff --git a/core/src/main/java/de/bwaldvogel/mongo/ServerVersion.java b/core/src/main/java/de/bwaldvogel/mongo/ServerVersion.java index 2b99936c..3c295d73 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/ServerVersion.java +++ b/core/src/main/java/de/bwaldvogel/mongo/ServerVersion.java @@ -3,9 +3,7 @@ import java.util.Collections; import java.util.List; -import de.bwaldvogel.mongo.backend.Utils; - -public enum ServerVersion { +public enum ServerVersion implements MongoVersion { MONGO_3_6(List.of(3, 6, 0), 6); private final List versionArray; @@ -20,10 +18,6 @@ public List getVersionArray() { return Collections.unmodifiableList(versionArray); } - public String toVersionString() { - return Utils.join(versionArray, "."); - } - public int getWireVersion() { return wireVersion; } diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java index 45055bf4..a78cb8d7 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java @@ -22,6 +22,7 @@ import de.bwaldvogel.mongo.MongoBackend; import de.bwaldvogel.mongo.MongoCollection; import de.bwaldvogel.mongo.MongoDatabase; +import de.bwaldvogel.mongo.MongoVersion; import de.bwaldvogel.mongo.ServerVersion; import de.bwaldvogel.mongo.bson.Document; import de.bwaldvogel.mongo.exception.MongoServerException; @@ -49,7 +50,7 @@ public abstract class AbstractMongoBackend implements MongoBackend { private final Map databases = new ConcurrentHashMap<>(); - private ServerVersion version = ServerVersion.MONGO_3_6; + private MongoVersion version = ServerVersion.MONGO_3_6; private final Clock clock; private final Instant started; @@ -434,7 +435,7 @@ public void close() { } @Override - public MongoBackend version(ServerVersion version) { + public MongoBackend version(MongoVersion version) { this.version = version; return this; } diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/ReadOnlyProxy.java b/core/src/main/java/de/bwaldvogel/mongo/backend/ReadOnlyProxy.java index d27d94b0..390690e9 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/ReadOnlyProxy.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/ReadOnlyProxy.java @@ -7,7 +7,7 @@ import de.bwaldvogel.mongo.MongoBackend; import de.bwaldvogel.mongo.MongoDatabase; -import de.bwaldvogel.mongo.ServerVersion; +import de.bwaldvogel.mongo.MongoVersion; import de.bwaldvogel.mongo.backend.aggregation.Aggregation; import de.bwaldvogel.mongo.bson.Document; import de.bwaldvogel.mongo.exception.MongoServerException; @@ -104,7 +104,7 @@ public void dropDatabase(String database) { } @Override - public MongoBackend version(ServerVersion version) { + public MongoBackend version(MongoVersion version) { throw new ReadOnlyException("not supported"); }