diff --git a/pom.xml b/pom.xml
index fb478726..defb987f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
org.liquibase.ext
liquibase-mongodb
jar
- 3.10.1-SNAPSHOT
+ 4.0.0-SNAPSHOT
Liquibase MongoDB Extension
Liquibase extension for MongoDB
http://www.liquibase.org
@@ -37,7 +37,7 @@
UTF-8
2.22.2
2.22.2
- 3.10.1
+ 4.0.0
5.6.2
1.3.2
3.12.6
diff --git a/src/main/java/liquibase/ext/mongodb/changelog/ChangeSetUtils.java b/src/main/java/liquibase/ext/mongodb/changelog/ChangeSetUtils.java
index 0492299d..6ec5d995 100644
--- a/src/main/java/liquibase/ext/mongodb/changelog/ChangeSetUtils.java
+++ b/src/main/java/liquibase/ext/mongodb/changelog/ChangeSetUtils.java
@@ -28,7 +28,7 @@
import org.bson.Document;
import static java.util.Objects.nonNull;
-import static liquibase.util.StringUtils.isNotEmpty;
+import static liquibase.util.StringUtil.isNotEmpty;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ChangeSetUtils {
diff --git a/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java b/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java
index 8a2dfb37..fef1fbc6 100644
--- a/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java
+++ b/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java
@@ -22,6 +22,7 @@
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
+import liquibase.Scope;
import liquibase.changelog.AbstractChangeLogHistoryService;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.RanChangeSet;
@@ -37,7 +38,6 @@
import liquibase.ext.mongodb.statement.CountCollectionByNameStatement;
import liquibase.ext.mongodb.statement.DropCollectionStatement;
import liquibase.logging.LogService;
-import liquibase.logging.LogType;
import org.bson.Document;
import org.bson.conversions.Bson;
@@ -99,7 +99,7 @@ public void reset() {
public boolean hasDatabaseChangeLogTable() {
if (hasDatabaseChangeLogTable == null) {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
hasDatabaseChangeLogTable =
executor.queryForLong(new CountCollectionByNameStatement(getDatabase().getDatabaseChangeLogTableName())) == 1L;
} catch (LiquibaseException e) {
@@ -114,7 +114,7 @@ public void init() throws DatabaseException {
return;
}
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
final boolean createdTable = hasDatabaseChangeLogTable();
@@ -127,12 +127,12 @@ public void init() throws DatabaseException {
new CreateChangeLogCollectionStatement(getDatabase().getDatabaseChangeLogTableName());
// If there is no table in the database for recording change history create one.
- LogService.getLog(getClass()).info(LogType.LOG, "Creating database history collection with name: " +
+ Scope.getCurrentScope().getLog(getClass()).info("Creating database history collection with name: " +
getDatabase().getLiquibaseCatalogName() + "." + getDatabase().getDatabaseChangeLogTableName());
executor.execute(createChangeLogCollectionStatement);
- LogService.getLog(getClass()).info(LogType.LOG, "Created database history collection : " +
+ Scope.getCurrentScope().getLog(getClass()).info("Created database history collection : " +
createChangeLogCollectionStatement.toJs());
}
@@ -168,7 +168,7 @@ protected void replaceChecksum(final ChangeSet changeSet) throws DatabaseExcepti
((MongoLiquibaseDatabase) getDatabase()).getConnection().getDb().getCollection(getDatabaseChangeLogTableName())
.updateOne(filter, update);
- ExecutorService.getInstance().getExecutor(getDatabase())
+ Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase())
.comment(String.format("Replace checksum executed. Changeset: [filename: %s, id: %s, author: %s]",
changeSet.getFilePath(), changeSet.getId(), changeSet.getAuthor()));
@@ -278,14 +278,14 @@ public void clearAllCheckSums() throws DatabaseException {
((MongoLiquibaseDatabase) getDatabase()).getConnection().getDb().getCollection(getDatabaseChangeLogTableName())
.updateMany(CLEAR_CHECKSUM_FILTER, CLEAR_CHECKSUM_UPDATE);
- ExecutorService.getInstance().getExecutor(getDatabase()).comment("Clear all checksums executed");
+ Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).comment("Clear all checksums executed");
}
@Override
public void destroy() {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
executor.comment("Dropping Collection Database Change Log: " + getDatabaseChangeLogTableName());
{
diff --git a/src/main/java/liquibase/ext/mongodb/database/DropCollectionsCommand.java b/src/main/java/liquibase/ext/mongodb/database/DropCollectionsCommand.java
index f58c98de..f35448a8 100644
--- a/src/main/java/liquibase/ext/mongodb/database/DropCollectionsCommand.java
+++ b/src/main/java/liquibase/ext/mongodb/database/DropCollectionsCommand.java
@@ -20,6 +20,7 @@
* #L%
*/
+import liquibase.Scope;
import liquibase.command.CommandResult;
import liquibase.command.core.DropAllCommand;
import liquibase.database.Database;
@@ -49,7 +50,7 @@ protected CommandResult run() throws Exception {
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
try {
lockService.waitForLock();
- final Executor executor = ExecutorService.getInstance().getExecutor(database);
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
executor.execute(new DropAllCollectionsStatement());
} catch (DatabaseException e) {
diff --git a/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java b/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java
index 903c55c4..658ae670 100644
--- a/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java
+++ b/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java
@@ -22,6 +22,7 @@
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Projections;
+import liquibase.Scope;
import liquibase.change.ColumnConfig;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.database.Database;
@@ -31,8 +32,6 @@
import liquibase.ext.mongodb.database.MongoConnection;
import liquibase.ext.mongodb.statement.AbstractMongoDocumentStatement;
import liquibase.ext.mongodb.statement.AbstractMongoStatement;
-import liquibase.logging.LogService;
-import liquibase.logging.LogType;
import liquibase.servicelocator.LiquibaseService;
import liquibase.sql.visitor.SqlVisitor;
import liquibase.statement.SqlStatement;
@@ -51,6 +50,7 @@
import static java.util.Collections.emptyList;
import static liquibase.ext.mongodb.database.MongoLiquibaseDatabase.DATABASE_CHANGE_LOG_LOCK_TABLE_NAME;
+import static liquibase.servicelocator.PrioritizedService.PRIORITY_DATABASE;
@NoArgsConstructor
@LiquibaseService
@@ -152,7 +152,7 @@ public void execute(final SqlStatement sql, final List sqlVisitors)
try {
ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(this.database).clearAllCheckSums();
} catch (LiquibaseException e) {
- LogService.getLog(getClass()).severe("Execution exception ", e);
+ Scope.getCurrentScope().getLog(getClass()).severe("Execution exception ", e);
}
} else {
throw new IllegalArgumentException();
@@ -175,7 +175,7 @@ public int update(final SqlStatement sql, final List sqlVisitors) {
@Override
public void comment(final String message) {
- LogService.getLog(getClass()).debug(message);
+ Scope.getCurrentScope().getLog(getClass()).fine(message);
}
@Override
@@ -194,13 +194,11 @@ private static boolean isClearChecksumStatement(final SqlStatement sqlStatement)
@Override
public String getName() {
- // TODO Auto-generated method stub
- return null;
+ return "mongodb";
}
@Override
public int getPriority() {
- // TODO Auto-generated method stub
- return 0;
+ return PRIORITY_DATABASE;
}
}
diff --git a/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java b/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java
index f1dec376..c52b789d 100644
--- a/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java
+++ b/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java
@@ -20,6 +20,7 @@
* #L%
*/
+import liquibase.Scope;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
@@ -34,8 +35,6 @@
import liquibase.ext.mongodb.statement.FindAllStatement;
import liquibase.lockservice.DatabaseChangeLogLock;
import liquibase.lockservice.LockService;
-import liquibase.logging.LogService;
-import liquibase.logging.LogType;
import liquibase.statement.SqlStatement;
import lombok.Getter;
import org.bson.Document;
@@ -84,7 +83,7 @@ public void init() throws DatabaseException {
if (!hasDatabaseChangeLogLockTable()) {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", Scope.getCurrentScope().getDatabase());
executor.comment("Create Database Lock Collection");
final CreateChangelogLockCollectionStatement createChangeLogLockCollectionStatement =
@@ -94,11 +93,11 @@ public void init() throws DatabaseException {
database.commit();
- LogService.getLog(getClass()).debug(LogType.LOG, "Created database lock collection: " + createChangeLogLockCollectionStatement.toJs());
+ Scope.getCurrentScope().getLog(getClass()).fine("Created database lock collection: " + createChangeLogLockCollectionStatement.toJs());
} catch (DatabaseException e) {
if ((e.getMessage() != null) && e.getMessage().contains("exists")) {
//hit a race condition where the table got created by another node.
- LogService.getLog(getClass()).debug(LogType.LOG, "Database lock collection already appears to exist " +
+ Scope.getCurrentScope().getLog(getClass()).fine("Database lock collection already appears to exist " +
"due to exception: " + e.getMessage() + ". Continuing on");
} else {
throw e;
@@ -121,7 +120,7 @@ public void waitForLock() throws LockException {
while (!locked && (new Date().getTime() < timeToGiveUp)) {
locked = acquireLock();
if (!locked) {
- LogService.getLog(getClass()).info(LogType.LOG, "Waiting for changelog lock....");
+ Scope.getCurrentScope().getLog(getClass()).info("Waiting for changelog lock....");
try {
Thread.sleep(getChangeLogLockRecheckTime() * 1000);
} catch (InterruptedException e) {
@@ -150,7 +149,7 @@ public void waitForLock() throws LockException {
public boolean acquireLock() throws LockException {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", Scope.getCurrentScope().getDatabase());
database.rollback();
this.init();
@@ -174,7 +173,7 @@ public boolean acquireLock() throws LockException {
}
database.commit();
- LogService.getLog(getClass()).info(LogType.LOG, coreBundle.getString("successfully.acquired.change.log.lock"));
+ Scope.getCurrentScope().getLog(getClass()).info(coreBundle.getString("successfully.acquired.change.log.lock"));
this.hasChangeLogLock = true;
this.database.setCanCacheLiquibaseTableInfo(true);
@@ -187,7 +186,7 @@ public boolean acquireLock() throws LockException {
try {
database.rollback();
} catch (DatabaseException e) {
- LogService.getLog(getClass()).severe(LogType.LOG, "Error on acquire change log lock Rollback.", e);
+ Scope.getCurrentScope().getLog(getClass()).severe("Error on acquire change log lock Rollback.", e);
}
}
}
@@ -198,7 +197,7 @@ public void releaseLock() throws LockException {
try {
if (this.hasDatabaseChangeLogLockTable()) {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
executor.comment("Release Database Lock");
database.rollback();
@@ -223,10 +222,10 @@ public void releaseLock() throws LockException {
} finally {
try {
database.setCanCacheLiquibaseTableInfo(false);
- LogService.getLog(getClass()).info(LogType.LOG, "Successfully released change log lock");
+ Scope.getCurrentScope().getLog(getClass()).info("Successfully released change log lock");
database.rollback();
} catch (DatabaseException e) {
- LogService.getLog(getClass()).severe(LogType.LOG, "Error on released change log lock Rollback.", e);
+ Scope.getCurrentScope().getLog(getClass()).severe("Error on released change log lock Rollback.", e);
}
}
}
@@ -242,7 +241,7 @@ public DatabaseChangeLogLock[] listLocks() throws LockException {
getDatabaseChangeLogLockTableName()
);
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
@SuppressWarnings("unchecked")
List rows = (List) executor.queryForList(stmt, Document.class).stream()
.map(d -> MongoChangeLogLock.from((Document)d)).collect(Collectors.toList());
@@ -269,7 +268,7 @@ public void reset() {
@Override
public void destroy() {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
executor.comment("Dropping Collection Database Change Log Lock: " + getDatabaseChangeLogLockTableName());
{
@@ -321,7 +320,7 @@ public void setChangeLogLockWaitTime(long changeLogLockWaitTime) {
private boolean hasDatabaseChangeLogLockTable() throws DatabaseException {
if (hasDatabaseChangeLogLockTable == null) {
try {
- final Executor executor = ExecutorService.getInstance().getExecutor(getDatabase());
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase());
hasDatabaseChangeLogLockTable =
executor.queryForLong(new CountDocumentsInCollectionStatement(getDatabase().getDatabaseChangeLogLockTableName())) == 1L;
} catch (Exception e) {
diff --git a/src/main/java/liquibase/ext/mongodb/statement/BsonUtils.java b/src/main/java/liquibase/ext/mongodb/statement/BsonUtils.java
index 0ffaff6e..9233b502 100644
--- a/src/main/java/liquibase/ext/mongodb/statement/BsonUtils.java
+++ b/src/main/java/liquibase/ext/mongodb/statement/BsonUtils.java
@@ -34,7 +34,7 @@
import java.util.List;
import static java.util.Optional.ofNullable;
-import static liquibase.util.StringUtils.trimToNull;
+import static liquibase.util.StringUtil.trimToNull;
import static lombok.AccessLevel.PRIVATE;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
diff --git a/src/main/resources/META-INF/services/liquibase.change.Change b/src/main/resources/META-INF/services/liquibase.change.Change
new file mode 100644
index 00000000..07b3791d
--- /dev/null
+++ b/src/main/resources/META-INF/services/liquibase.change.Change
@@ -0,0 +1,6 @@
+liquibase.ext.mongodb.change.AdminCommandChange
+liquibase.ext.mongodb.change.CreateCollectionChange
+liquibase.ext.mongodb.change.CreateIndexChange
+liquibase.ext.mongodb.change.InsertManyChange
+liquibase.ext.mongodb.change.InsertOneChange
+liquibase.ext.mongodb.change.RunCommandChange
diff --git a/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java b/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java
index d0edb5e0..2da4f5a5 100644
--- a/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java
+++ b/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java
@@ -20,13 +20,14 @@
* #L%
*/
+import liquibase.Scope;
import liquibase.database.DatabaseFactory;
import liquibase.exception.DatabaseException;
import liquibase.executor.ExecutorService;
+import liquibase.ext.mongodb.TestUtils;
import liquibase.ext.mongodb.database.MongoConnection;
import liquibase.ext.mongodb.database.MongoLiquibaseDatabase;
import liquibase.ext.mongodb.executor.MongoExecutor;
-import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
@@ -34,7 +35,6 @@
import static liquibase.ext.mongodb.TestUtils.getMongoConnection;
-@Slf4j
public abstract class AbstractMongoIntegrationTest {
protected static MongoConnection mongoConnection;
@@ -58,13 +58,13 @@ protected void setUp() throws DatabaseException {
database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().findCorrectDatabaseImplementation(mongoConnection);
database.setConnection(mongoConnection);
- log.debug("database is initialized...");
+ Scope.getCurrentScope().getLog(TestUtils.class).fine("database is initialized...");
mongoExecutor = new MongoExecutor();
mongoExecutor.setDatabase(database);
- log.debug("mongoExecutor is initialized...");
+ Scope.getCurrentScope().getLog(TestUtils.class).fine("mongoExecutor is initialized...");
- ExecutorService.getInstance().setExecutor(database, mongoExecutor);
+ Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor(database, mongoExecutor);
database.getConnection().getDb().listCollectionNames()
.forEach((Consumer super String>) c -> mongoConnection.getDb().getCollection(c).drop());
diff --git a/src/test/java/liquibase/ext/mongodb/TestUtils.java b/src/test/java/liquibase/ext/mongodb/TestUtils.java
index c10debe1..9d2465f5 100644
--- a/src/test/java/liquibase/ext/mongodb/TestUtils.java
+++ b/src/test/java/liquibase/ext/mongodb/TestUtils.java
@@ -21,6 +21,7 @@
*/
import liquibase.Liquibase;
+import liquibase.Scope;
import liquibase.changelog.ChangeLogParameters;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
@@ -33,7 +34,6 @@
import liquibase.util.file.FilenameUtils;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import java.util.List;
@@ -44,7 +44,6 @@
import static lombok.AccessLevel.PRIVATE;
import static org.assertj.core.api.Assertions.assertThat;
-@Slf4j
@NoArgsConstructor(access = PRIVATE)
public final class TestUtils {
public static final String BUILD_INFO_1 = "{ buildInfo: 1 }";
@@ -66,7 +65,6 @@ public static List getCollections(final MongoConnection connection) {
public static MongoConnection getMongoConnection(final String propertyFile) {
final Properties properties = new Properties();
properties.load(TestUtils.class.getClassLoader().getResourceAsStream(propertyFile));
- log.debug("Actual connection properties:\n{}", properties);
return getMongoConnection(properties);
}
diff --git a/src/test/java/liquibase/ext/mongodb/changelog/MongoHistoryServiceIT.java b/src/test/java/liquibase/ext/mongodb/changelog/MongoHistoryServiceIT.java
index 67848052..f1cebc95 100644
--- a/src/test/java/liquibase/ext/mongodb/changelog/MongoHistoryServiceIT.java
+++ b/src/test/java/liquibase/ext/mongodb/changelog/MongoHistoryServiceIT.java
@@ -21,6 +21,7 @@
*/
import liquibase.Liquibase;
+import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.RanChangeSet;
@@ -61,7 +62,7 @@ private static void initLiquibase() throws Exception {
LIQUIBASE = new Liquibase(FILE_PATH, new ClassLoaderResourceAccessor(), database);
LIQUIBASE.update("");
- ExecutorService.getInstance().setExecutor(database, mongoExecutor);
+ Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor(database, mongoExecutor);
}
@Test
@@ -120,7 +121,7 @@ void testReplaceChecksum() throws Exception {
final ChangeSet changeSet = LIQUIBASE.getDatabaseChangeLog().getChangeSet(FILE_PATH, "alex", "1");
assertTrue(mongoHistoryService.isServiceInitialized());
- ExecutorService.getInstance().setExecutor(database, mongoExecutor);
+ Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor(database, mongoExecutor);
mongoHistoryService.replaceChecksum(changeSet);
diff --git a/src/test/java/liquibase/ext/mongodb/executor/MongoExecutorIT.java b/src/test/java/liquibase/ext/mongodb/executor/MongoExecutorIT.java
index 746709a2..7d7f6d88 100644
--- a/src/test/java/liquibase/ext/mongodb/executor/MongoExecutorIT.java
+++ b/src/test/java/liquibase/ext/mongodb/executor/MongoExecutorIT.java
@@ -20,6 +20,7 @@
* #L%
*/
+import liquibase.Scope;
import liquibase.executor.Executor;
import liquibase.executor.ExecutorService;
import liquibase.ext.AbstractMongoIntegrationTest;
@@ -33,7 +34,7 @@ class MongoExecutorIT extends AbstractMongoIntegrationTest {
@Test
void testGetInstance() {
- final Executor executor = ExecutorService.getInstance().getExecutor(database);
+ final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(database);
assertThat(executor, notNullValue());
assertThat(executor, instanceOf(MongoExecutor.class));
}