Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a custom executor to be specified through a property on existing Executor implementations DAT-7531 #2374

Merged
merged 10 commits into from Jan 25, 2022
@@ -1,13 +1,11 @@
package liquibase.changelog;

import liquibase.ContextExpression;
import liquibase.Labels;
import liquibase.RuntimeEnvironment;
import liquibase.Scope;
import liquibase.*;
import liquibase.changelog.filter.ChangeSetFilter;
import liquibase.changelog.filter.ChangeSetFilterResult;
import liquibase.changelog.visitor.ChangeSetVisitor;
import liquibase.changelog.visitor.SkippedChangeSetVisitor;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.exception.LiquibaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.exception.ValidationErrors;
Expand Down Expand Up @@ -137,7 +135,8 @@ private void validateChangeSetExecutor(ChangeSet changeSet, RuntimeEnvironment e
if (changeSet.getRunWith() == null) {
return;
}
String executorName = changeSet.getRunWith();
String executorName = ChangeSet.lookupExecutor(changeSet.getRunWith());

Executor executor;
try {
executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(executorName, env.getTargetDatabase());
Expand Down
17 changes: 16 additions & 1 deletion liquibase-core/src/main/java/liquibase/changelog/ChangeSet.java
Expand Up @@ -8,6 +8,7 @@
import liquibase.change.core.EmptyChange;
import liquibase.change.core.RawSQLChange;
import liquibase.changelog.visitor.ChangeExecListener;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.DatabaseList;
import liquibase.database.ObjectQuotingStrategy;
Expand Down Expand Up @@ -719,7 +720,8 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
if (getRunWith() == null || originalExecutor instanceof LoggingExecutor) {
return originalExecutor;
}
Executor customExecutor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(getRunWith(), database);
String executorName = ChangeSet.lookupExecutor(getRunWith());
Executor customExecutor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(executorName, database);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, customExecutor);
List<Change> changes = getChanges();
for (Change change : changes) {
Expand All @@ -735,6 +737,19 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
return originalExecutor;
}

public static String lookupExecutor(String executorName) {
if (StringUtil.isEmpty(executorName)) {
return null;
}
String key = "liquibase." + executorName + ".executor";
String replacementExecutorName =
(String)Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getCurrentConfiguredValue(null, null, key).getValue();
if (replacementExecutorName != null) {
return replacementExecutorName;
}
return executorName;
}

public void rollback(Database database) throws RollbackFailedException {
rollback(database, null);
}
Expand Down
@@ -0,0 +1 @@
liquibase.executor.jvm.ExampleExecutor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this class be committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be okay. The liquibase-extension-examples are not shipped.