Skip to content

Commit

Permalink
Extract mongo version to interface (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgruber1 authored Mar 18, 2024
1 parent 03b38aa commit a6c1f22
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/de/bwaldvogel/mongo/MongoBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public interface MongoBackend {

MongoDatabase resolveDatabase(String database);

MongoBackend version(ServerVersion version);
MongoBackend version(MongoVersion version);

}
17 changes: 17 additions & 0 deletions core/src/main/java/de/bwaldvogel/mongo/MongoVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.bwaldvogel.mongo;

import java.util.List;

import de.bwaldvogel.mongo.backend.Utils;

public interface MongoVersion {

List<Integer> getVersionArray();

default String toVersionString() {
return Utils.join(getVersionArray(), ".");
}

int getWireVersion();

}
8 changes: 1 addition & 7 deletions core/src/main/java/de/bwaldvogel/mongo/ServerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> versionArray;
Expand All @@ -20,10 +18,6 @@ public List<Integer> getVersionArray() {
return Collections.unmodifiableList(versionArray);
}

public String toVersionString() {
return Utils.join(versionArray, ".");
}

public int getWireVersion() {
return wireVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +50,7 @@ public abstract class AbstractMongoBackend implements MongoBackend {

private final Map<String, MongoDatabase> 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;
Expand Down Expand Up @@ -434,7 +435,7 @@ public void close() {
}

@Override
public MongoBackend version(ServerVersion version) {
public MongoBackend version(MongoVersion version) {
this.version = version;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit a6c1f22

Please sign in to comment.