Skip to content

Commit

Permalink
Updated code to work with Liquibase 4.0.0-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Apr 22, 2020
1 parent 8600da0 commit 6dc5f3b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<liquibase.version>3.8.9</liquibase.version>
<liquibase.version>4.0.0-beta1</liquibase.version>
<jupiter.version>5.5.1</jupiter.version>
<jupiter.surefire.version>1.3.2</jupiter.surefire.version>
<mongodb-driver.version>3.10.2</mongodb-driver.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -152,7 +151,7 @@ public void execute(final SqlStatement sql, final List<SqlVisitor> 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();
Expand All @@ -175,7 +174,7 @@ public int update(final SqlStatement sql, final List<SqlVisitor> sqlVisitors) {

@Override
public void comment(final String message) {
LogService.getLog(getClass()).debug(message);
Scope.getCurrentScope().getLog(getClass()).fine(message);
}

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

import liquibase.Scope;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/services/liquibase.change.Change
Original file line number Diff line number Diff line 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
8 changes: 4 additions & 4 deletions src/test/java/liquibase/ext/AbstractMongoIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
* #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;

import java.util.function.Consumer;

import static liquibase.ext.mongodb.TestUtils.getMongoConnection;

@Slf4j
public abstract class AbstractMongoIntegrationTest {

protected static MongoConnection mongoConnection;
Expand All @@ -58,11 +58,11 @@ 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);

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/liquibase/ext/mongodb/TestUtils.java
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.ChangeLogParameters;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
Expand All @@ -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;
Expand All @@ -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 }";
Expand All @@ -66,7 +65,6 @@ public static List<String> 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);
}
Expand Down

0 comments on commit 6dc5f3b

Please sign in to comment.