Skip to content

Commit

Permalink
Updated code to work with Liquibase 4.0.0-beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Jul 2, 2020
1 parent fb21824 commit 50dab33
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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()));

Expand Down Expand Up @@ -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());
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import liquibase.Scope;
import liquibase.command.CommandResult;
import liquibase.command.core.DropAllCommand;
import liquibase.database.Database;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<MongoChangeLogLock> rows = (List<MongoChangeLogLock>) executor.queryForList(stmt, Document.class).stream()
.map(d -> MongoChangeLogLock.from((Document)d)).collect(Collectors.toList());
Expand All @@ -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());
{
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? super String>) c -> mongoConnection.getDb().getCollection(c).drop());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import liquibase.Liquibase;
import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.RanChangeSet;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import liquibase.Scope;
import liquibase.executor.Executor;
import liquibase.executor.ExecutorService;
import liquibase.ext.AbstractMongoIntegrationTest;
Expand All @@ -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));
}
Expand Down

0 comments on commit 50dab33

Please sign in to comment.