diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a644a9b..0a6814bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,20 +7,23 @@
* Jetty 9.4.48.v20220622
* Joda-Time 2.11.1
* ActiveMQ 5.16.5
- * Log4J 2.18.0
- * Guava 31.1
- * Commons Codec 1.15
- * Mongo Java Server 1.40.0
+ * Log4J 2.18.0
+ * Guava 31.1
+ * Commons Codec 1.15
+ * Mongo Java Server 1.40.0
* Liquibase 4.11.0
- * Mongo Java Driver 3.12.11
+ * Mongo Java Driver 4.7.0
+ * Bson 2.13.1
* Nimbus JOSE+JWT 9.23
* JSON Small and Fast Parser 2.4.8
* Swagger 2.2.2
- * etcd4j 2.18.0
- * Hazelcast 5.1.3
- * XDocReport 2.0.4
+ * etcd4j 2.18.0
+ * Hazelcast 5.1.3
+ * XDocReport 2.0.4
* Bouncycastle Provider 1.71.1
-* Moved Mongo Java Server to optional dependency (in most cases Fake Mongo is not needed or can be added)
+
+* Moved Mongo Java Server to optional dependency (in most cases Fake Mongo is not needed or can be added)
+* BREAKING: replaced mongobee with Mongock (5.0.36), mostly backwards compatibility but configuration(see Class `MongoDBConfig`) and annotations (@Changelog and @ChangeSet) have to be replaced by Mongock equivalent https://docs.mongock.io/v5/features/legacy-migration/index.html
## 1.32
* Update dependencies
diff --git a/mongodb/dvalin-mongodb.iml b/mongodb/dvalin-mongodb.iml
index d93caf3c..5fd4ebfe 100644
--- a/mongodb/dvalin-mongodb.iml
+++ b/mongodb/dvalin-mongodb.iml
@@ -47,16 +47,31 @@
-
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -86,6 +101,6 @@
-
+
\ No newline at end of file
diff --git a/mongodb/pom.xml b/mongodb/pom.xml
index 13a75353..80fb2bc9 100644
--- a/mongodb/pom.xml
+++ b/mongodb/pom.xml
@@ -10,6 +10,17 @@
2015
+
+
+
+ io.mongock
+ mongock-bom
+ ${mongock.version}
+ pom
+ import
+
+
+
de.taimos
@@ -43,7 +54,7 @@
org.mongodb
- mongo-java-driver
+ mongodb-driver-legacy
org.jongo
@@ -69,32 +80,14 @@
- com.github.mongobee
- mongobee
- ${mongobee.version}
-
-
- org.springframework
- *
-
-
- org.springframework.data
- *
-
-
- org.slf4j
- *
-
-
- org.mongodb
- *
-
-
- org.jongo
- *
-
-
-
+ io.mongock
+ mongock-standalone
+
+
+ io.mongock
+ mongodb-sync-v4-driver
+
+
de.bwaldvogel
mongo-java-server
diff --git a/mongodb/src/main/java/de/taimos/dvalin/mongo/MongoDBInit.java b/mongodb/src/main/java/de/taimos/dvalin/mongo/MongoDBInit.java
index ffc79f35..999e4190 100644
--- a/mongodb/src/main/java/de/taimos/dvalin/mongo/MongoDBInit.java
+++ b/mongodb/src/main/java/de/taimos/dvalin/mongo/MongoDBInit.java
@@ -25,6 +25,12 @@
import javax.annotation.PostConstruct;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import de.taimos.daemon.spring.conditional.OnSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,14 +38,6 @@
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;
-import com.mongodb.DBObject;
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-import com.mongodb.util.JSON;
-
-import de.taimos.daemon.spring.conditional.OnSystemProperty;
-
/**
* Copyright 2014 Taimos GmbH
@@ -86,14 +84,8 @@ public void initDatabase() {
int lines = 0;
while (scan.hasNextLine()) {
String json = scan.nextLine();
- Object parse = JSON.parse(json);
- if (parse instanceof DBObject) {
- DBObject dbObject = (DBObject) parse;
- dbCollection.insertOne(dbObject);
- } else {
- MongoDBInit.LOGGER.error("Invalid object found: {}", parse);
- throw new RuntimeException("Invalid object");
- }
+ DBObject parse = BasicDBObject.parse(json);
+ dbCollection.insertOne(parse);
lines++;
}
MongoDBInit.LOGGER.info("Imported {} objects into collection {}", lines, collection);
diff --git a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/FakeClientConfig.java b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/FakeClientConfig.java
index 4778ddc8..f713c3ca 100644
--- a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/FakeClientConfig.java
+++ b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/FakeClientConfig.java
@@ -20,8 +20,10 @@
* #L%
*/
+import com.mongodb.ConnectionString;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
+import com.mongodb.client.MongoClients;
import de.bwaldvogel.mongo.MongoServer;
import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
@@ -45,4 +47,11 @@ public MongoClient mongoClient(MongoServer mongoServer) {
return new MongoClient(new ServerAddress(mongoServer.bind()));
}
+ @Bean
+ public com.mongodb.client.MongoClient mongoClient2(MongoServer mongoServer) {
+ ServerAddress serverAddress = new ServerAddress(mongoServer.bind());
+ ConnectionString uri = new ConnectionString(String.format("mongodb://%s:%d", serverAddress.getHost(), serverAddress.getPort()));
+ return MongoClients.create(uri);
+ }
+
}
diff --git a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/MongoDBConfig.java b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/MongoDBConfig.java
index 8d739328..a4993dbe 100644
--- a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/MongoDBConfig.java
+++ b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/MongoDBConfig.java
@@ -20,10 +20,19 @@
* #L%
*/
-import com.github.mongobee.Mongobee;
+import java.util.concurrent.TimeUnit;
+
+import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ReadConcern;
+import com.mongodb.ReadPreference;
+import com.mongodb.WriteConcern;
import com.mongodb.client.MongoDatabase;
import de.taimos.dvalin.mongo.JongoFactory;
+import io.mongock.api.config.LegacyMigration;
+import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
+import io.mongock.runner.standalone.MongockStandalone;
+import io.mongock.runner.standalone.RunnerStandaloneBuilder;
import org.jongo.Jongo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -32,23 +41,34 @@
@Configuration
public class MongoDBConfig {
- @Value("${mongobee.enabled:false}")
- private boolean beeEnabled;
+ @Value("${mongock.enabled:false}")
+ private boolean mongockEnabled;
+
+ @Value("${mongock.legacyMigration.table:dbchangelog}")
+ private String mongockLegacyTable;
@Value("${mongodb.name}")
private String dbName;
- @Value("${mongobee.basepackage:${mongobee.basePackage:}}")
- private String beeBasePackage;
+ @Value("${mongock.basepackage:${mongock.basePackage:}}")
+ private String basePackage;
@Bean
- public Mongobee mongobee(MongoClient mongoClient, Jongo jongo) {
- Mongobee bee = new Mongobee(mongoClient);
- bee.setDbName(this.dbName);
- bee.setEnabled(this.beeEnabled);
- bee.setChangeLogsScanPackage(this.beeBasePackage);
- bee.setJongo(jongo);
- return bee;
+ public RunnerStandaloneBuilder mongockRunner(com.mongodb.client.MongoClient mongoClient, Jongo jongo) {
+
+ MongoSync4Driver driver = MongoSync4Driver.withDefaultLock(mongoClient, this.dbName);
+ driver.setWriteConcern(WriteConcern.MAJORITY.withJournal(true).withWTimeout(1000, TimeUnit.MILLISECONDS));
+ driver.setReadConcern(ReadConcern.MAJORITY);
+ driver.setReadPreference(ReadPreference.primary());
+ driver.disableTransaction();
+
+
+ LegacyMigration legacyMigration = new LegacyMigration();
+ legacyMigration.setOrigin(this.mongockLegacyTable);
+ RunnerStandaloneBuilder runnerStandaloneBuilder = MongockStandalone.builder().setDriver(driver).setTransactionEnabled(false).addMigrationScanPackage(this.basePackage);
+ runnerStandaloneBuilder.setLegacyMigration(legacyMigration).addDependency(jongo).buildRunner().execute();
+
+ return runnerStandaloneBuilder;
}
@Bean
@@ -58,7 +78,11 @@ public MongoDatabase mongoDatabase(MongoClient mongoClient) {
@Bean
public Jongo jongo(MongoClient mongoClient) {
- return JongoFactory.createDefault(mongoClient.getDB(dbName));
+ return JongoFactory.createDefault(mongoClient.getDB(this.dbName));
}
+ @Bean
+ public DB mongoDB(MongoClient mongoClient){
+ return mongoClient.getDB(this.dbName);
+ }
}
diff --git a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/RealClientConfig.java b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/RealClientConfig.java
index 17591230..207b228d 100644
--- a/mongodb/src/main/java/de/taimos/dvalin/mongo/config/RealClientConfig.java
+++ b/mongodb/src/main/java/de/taimos/dvalin/mongo/config/RealClientConfig.java
@@ -20,15 +20,14 @@
* #L%
*/
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
-
+import com.mongodb.client.MongoClients;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
@OnSystemProperty(propertyName = "mongodb.type", propertyValue = "real")
@@ -54,6 +53,14 @@ public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI(this.mongoURI, builder));
}
+ @Bean
+ public com.mongodb.client.MongoClient mongoClient2() {
+ MongoClientOptions.Builder builder = MongoClientOptions.builder();
+ builder.socketTimeout(this.socketTimeout);
+ builder.connectTimeout(this.connectTimeout);
+ return MongoClients.create(new MongoClientURI(this.mongoURI, builder).getURI());
+ }
+
}
diff --git a/mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
deleted file mode 100644
index 51cf2b5d..00000000
--- a/mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.springframework.data.mongodb.core;
-
-/*-
- * #%L
- * MongoDB support for dvalin
- * %%
- * Copyright (C) 2015 - 2017 Taimos GmbH
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * #L%
- */
-
-import com.mongodb.Mongo;
-
-/**
- * Overriding MongoTemplate from Spring Data because Mongobee has class binding at startup fails without this class.
- * Dvalin does not use Spring Data so this class is not available.
- */
-public class MongoTemplate {
-
- private final Mongo mongo;
- private final String dbName;
-
- public MongoTemplate(Mongo mongo, String dbName) {
- this.mongo = mongo;
- this.dbName = dbName;
- }
-
- public Mongo getMongo() {
- return this.mongo;
- }
-
- public String getDbName() {
- return this.dbName;
- }
-}
diff --git a/mongodb/src/test/java/de/taimos/dvalin/mongo/ABaseTest.java b/mongodb/src/test/java/de/taimos/dvalin/mongo/ABaseTest.java
index c78e08af..7aa7f075 100644
--- a/mongodb/src/test/java/de/taimos/dvalin/mongo/ABaseTest.java
+++ b/mongodb/src/test/java/de/taimos/dvalin/mongo/ABaseTest.java
@@ -25,10 +25,14 @@
import java.math.BigDecimal;
-import com.mongodb.MongoClient;
+import com.mongodb.ConnectionString;
+import com.mongodb.DB;
import com.mongodb.ServerAddress;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.ServerVersion;
import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.taimos.daemon.log4j.Log4jLoggingConfigurer;
import org.jongo.Jongo;
@@ -43,8 +47,13 @@
public class ABaseTest {
protected static final String dbName = "dvalin-mongo";
- public static final MongoClient mongo = new MongoClient(new ServerAddress(new MongoServer(new MemoryBackend()).bind()));;
- public static final Jongo jongo = JongoFactory.createDefault(ABaseTest.mongo.getDB(ABaseTest.dbName));
+ private static final ServerAddress serverAddress = new ServerAddress(new MongoServer(new MemoryBackend().version(ServerVersion.MONGO_3_6)).bind());
+
+ public static final MongoClient mongo = MongoClients.create(new ConnectionString(String.format("mongodb://%s:%d", ABaseTest.serverAddress.getHost(), ABaseTest.serverAddress.getPort())));
+ public static final com.mongodb.MongoClient oldMongo = new com.mongodb.MongoClient(new ServerAddress(new MongoServer(new MemoryBackend().version(ServerVersion.MONGO_3_6)).bind()));;
+
+ public static final DB oldDB = ABaseTest.oldMongo.getDB(ABaseTest.dbName);
+ public static final Jongo jongo = JongoFactory.createDefault(ABaseTest.oldMongo.getDB(ABaseTest.dbName));
public static final MongoDatabase database = ABaseTest.mongo.getDatabase(ABaseTest.dbName);
static {
diff --git a/mongodb/src/test/java/de/taimos/dvalin/mongo/LinkTester.java b/mongodb/src/test/java/de/taimos/dvalin/mongo/LinkTester.java
index b9b102cd..4d690d2a 100644
--- a/mongodb/src/test/java/de/taimos/dvalin/mongo/LinkTester.java
+++ b/mongodb/src/test/java/de/taimos/dvalin/mongo/LinkTester.java
@@ -26,15 +26,14 @@
import java.lang.reflect.Field;
import java.util.List;
+import de.taimos.dvalin.daemon.spring.InjectionUtils;
+import de.taimos.dvalin.mongo.links.DLinkDAO;
+import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
+import io.mongock.runner.standalone.MongockStandalone;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.github.mongobee.Mongobee;
-
-import de.taimos.dvalin.daemon.spring.InjectionUtils;
-import de.taimos.dvalin.mongo.links.DLinkDAO;
-
/**
* Copyright 2015 Taimos GmbH
*
@@ -59,11 +58,10 @@ public static void init() {
dao2Field.set(LinkTester.dao, new MongoDBDataAccess(ABaseTest.jongo, ABaseTest.database, InjectionUtils.createDependencyDescriptor(dao2Field, LinkTester.dao)));
dao2Field.set(LinkTester.ldao, new MongoDBDataAccess(ABaseTest.jongo, ABaseTest.database, InjectionUtils.createDependencyDescriptor(dao2Field, LinkTester.ldao)));
- Mongobee bee = new Mongobee(ABaseTest.mongo);
- bee.setChangeLogsScanPackage("de.taimos.dvalin.mongo.changelog");
- bee.setDbName(ABaseTest.dbName);
- bee.setEnabled(true);
- bee.execute();
+
+ MongoSync4Driver driver = MongoSync4Driver.withDefaultLock(ABaseTest.mongo, ABaseTest.dbName);
+ driver.disableTransaction();
+ MongockStandalone.builder().setDriver(driver).addMigrationScanPackage("de.taimos.dvalin.mongo.changelog").setTransactionEnabled(false).setEnabled(true).buildRunner().execute();
LinkTester.dao.init();
LinkTester.ldao.init();
} catch (Exception e) {
diff --git a/mongodb/src/test/java/de/taimos/dvalin/mongo/Tester.java b/mongodb/src/test/java/de/taimos/dvalin/mongo/Tester.java
index befc5f25..2f84a770 100644
--- a/mongodb/src/test/java/de/taimos/dvalin/mongo/Tester.java
+++ b/mongodb/src/test/java/de/taimos/dvalin/mongo/Tester.java
@@ -23,6 +23,15 @@
import java.lang.reflect.Field;
import java.math.BigDecimal;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.client.ListIndexesIterable;
+import de.taimos.dvalin.daemon.spring.InjectionUtils;
+import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
+import io.mongock.runner.standalone.MongockStandalone;
import org.bson.Document;
import org.joda.time.DateTime;
import org.jongo.Mapper;
@@ -32,17 +41,6 @@
import org.junit.BeforeClass;
import org.junit.Test;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.github.mongobee.Mongobee;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-import com.mongodb.client.ListIndexesIterable;
-import com.mongodb.util.JSON;
-
-import de.taimos.dvalin.daemon.spring.InjectionUtils;
-
public class Tester extends ABaseTest {
private static final TestDAO dao = new TestDAO();
@@ -52,7 +50,7 @@ public static void init() {
try {
Field mongoField = AbstractMongoDAO.class.getDeclaredField("mongo");
mongoField.setAccessible(true);
- mongoField.set(Tester.dao, ABaseTest.mongo);
+ mongoField.set(Tester.dao, ABaseTest.oldMongo);
Field jongoField = AbstractMongoDAO.class.getDeclaredField("jongo");
jongoField.setAccessible(true);
@@ -66,11 +64,9 @@ public static void init() {
daoField.setAccessible(true);
daoField.set(Tester.dao, new MongoDBDataAccess(ABaseTest.jongo, ABaseTest.database, InjectionUtils.createDependencyDescriptor(daoField, Tester.dao)));
- Mongobee bee = new Mongobee(ABaseTest.mongo);
- bee.setChangeLogsScanPackage("de.taimos.dvalin.mongo.changelog");
- bee.setDbName(ABaseTest.dbName);
- bee.setEnabled(true);
- bee.execute();
+ MongoSync4Driver driver = MongoSync4Driver.withDefaultLock(ABaseTest.mongo, ABaseTest.dbName);
+ driver.disableTransaction();
+ MongockStandalone.builder().setDriver(driver).addMigrationScanPackage("de.taimos.dvalin.mongo.changelog").setTransactionEnabled(false).setEnabled(true).buildRunner().execute();
Tester.dao.init();
} catch (Exception e) {
e.printStackTrace();
@@ -140,10 +136,10 @@ public void serialize() throws Exception {
DBObject dbObject = this.createMapper().getMarshaller().marshall(o).toDBObject();
System.out.println(dbObject);
- String json = JSON.serialize(dbObject);
+ String json = dbObject.toString();
System.out.println(json);
- Object parse = JSON.parse(json);
+ Object parse = BasicDBObject.parse(json);
System.out.println(parse);
Assert.assertEquals(BasicDBObject.class, parse.getClass());
Assert.assertEquals(Double.class, ((DBObject) parse).get("value").getClass());
diff --git a/mongodb/src/test/java/de/taimos/dvalin/mongo/changelog/TestChangelog.java b/mongodb/src/test/java/de/taimos/dvalin/mongo/changelog/TestChangelog.java
index a5d82baf..fbd5b541 100644
--- a/mongodb/src/test/java/de/taimos/dvalin/mongo/changelog/TestChangelog.java
+++ b/mongodb/src/test/java/de/taimos/dvalin/mongo/changelog/TestChangelog.java
@@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,17 +20,20 @@
* #L%
*/
-import com.github.mongobee.changeset.ChangeLog;
-import com.github.mongobee.changeset.ChangeSet;
-import com.mongodb.DB;
-
+import de.taimos.dvalin.mongo.ABaseTest;
import de.taimos.dvalin.mongo.ChangelogUtil;
+import io.mongock.api.annotations.ChangeUnit;
+import io.mongock.api.annotations.Execution;
+import io.mongock.api.annotations.RollbackExecution;
-@ChangeLog
+@ChangeUnit(order = "001", id = "index1", author = "thoeger", transactional = false)
public class TestChangelog {
- @ChangeSet(order = "001", id = "index1", author = "thoeger")
- public void index1(DB db) {
- ChangelogUtil.addIndex(db.getCollection("TestObject"), "name", true, true);
+ @Execution
+ public void index1() {
+ ChangelogUtil.addIndex(ABaseTest.oldDB.getCollection("TestObject"), "name", true, true);
}
+
+ @RollbackExecution
+ public void index1Rollback(){}
}
diff --git a/pom.xml b/pom.xml
index d3ef7960..f483d153 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,10 +65,10 @@
5.5.9.Final
2.2
2.3
- 2.12.0
+ 2.13.1
1.5.0
- 3.12.11
- 0.12
+ 4.7.0
+ 5.0.36
1.40.0
2.0.4
@@ -352,7 +352,7 @@
org.mongodb
- mongo-java-driver
+ mongodb-driver-legacy
${mongo.version}