From 50dab33677f5f9753fdc743ceb08671b342272bc Mon Sep 17 00:00:00 2001 From: Nathan Voxland Date: Thu, 2 Jul 2020 16:11:27 -0500 Subject: [PATCH] Updated code to work with Liquibase 4.0.0-beta2 --- .../ext/mongodb/changelog/MongoHistoryService.java | 10 +++++----- .../ext/mongodb/database/DropCollectionsCommand.java | 3 ++- .../ext/mongodb/executor/MongoExecutor.java | 7 +++---- .../ext/mongodb/lockservice/MongoLockService.java | 12 ++++++------ .../liquibase/ext/AbstractMongoIntegrationTest.java | 2 +- .../ext/mongodb/changelog/MongoHistoryServiceIT.java | 5 +++-- .../ext/mongodb/executor/MongoExecutorIT.java | 3 ++- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java b/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java index 4bc1de56..fef1fbc6 100644 --- a/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java +++ b/src/main/java/liquibase/ext/mongodb/changelog/MongoHistoryService.java @@ -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(); @@ -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 e65ab4a9..658ae670 100644 --- a/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java +++ b/src/main/java/liquibase/ext/mongodb/executor/MongoExecutor.java @@ -50,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 @@ -193,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 6ee3c97f..c52b789d 100644 --- a/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java +++ b/src/main/java/liquibase/ext/mongodb/lockservice/MongoLockService.java @@ -83,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 = @@ -149,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(); @@ -197,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(); @@ -241,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()); @@ -268,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()); { @@ -320,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/test/java/liquibase/ext/AbstractMongoIntegrationTest.java b/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java index 8603dada..2da4f5a5 100644 --- a/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java +++ b/src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java @@ -64,7 +64,7 @@ protected void setUp() throws DatabaseException { mongoExecutor.setDatabase(database); 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) c -> mongoConnection.getDb().getCollection(c).drop()); 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)); }