use of org.flywaydb.core.api.callback.Callback in project flyway by flyway.
the class ClassicConfiguration method loadCallbackLocation.
/**
* Scan this location for classes that implement Callback.
*
* @param path The path to scan.
* @param errorOnNotFound Whether to show an error if the location is not found.
*/
public void loadCallbackLocation(String path, boolean errorOnNotFound) {
List<String> callbackClasses = classScanner.scanForType(path, Callback.class, errorOnNotFound);
for (String callback : callbackClasses) {
Class<? extends Callback> callbackClass;
try {
callbackClass = ClassUtils.loadClass(Callback.class, callback, classLoader);
} catch (Throwable e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
LOG.warn("Skipping " + Callback.class + ": " + ClassUtils.formatThrowable(e) + (rootCause == e ? "" : " caused by " + ClassUtils.formatThrowable(rootCause) + " at " + ExceptionUtils.getThrowLocation(rootCause)));
callbackClass = null;
}
if (callbackClass != null) {
// Filter out abstract classes
Callback callbackObj = ClassUtils.instantiate(callback, classLoader);
this.callbacks.add(callbackObj);
}
}
}
use of org.flywaydb.core.api.callback.Callback in project flyway by flyway.
the class FlywayExecutor method prepareCallbacks.
private List<Callback> prepareCallbacks(Database database, ResourceProvider resourceProvider, JdbcConnectionFactory jdbcConnectionFactory, SqlScriptFactory sqlScriptFactory, StatementInterceptor statementInterceptor, Schema schema, ParsingContext parsingContext) {
List<Callback> effectiveCallbacks = new ArrayList<>();
CallbackExecutor callbackExecutor = NoopCallbackExecutor.INSTANCE;
effectiveCallbacks.addAll(Arrays.asList(configuration.getCallbacks()));
if (!configuration.isSkipDefaultCallbacks()) {
SqlScriptExecutorFactory sqlScriptExecutorFactory = jdbcConnectionFactory.getDatabaseType().createSqlScriptExecutorFactory(jdbcConnectionFactory, callbackExecutor, statementInterceptor);
effectiveCallbacks.addAll(new SqlScriptCallbackFactory(resourceProvider, sqlScriptExecutorFactory, sqlScriptFactory, configuration).getCallbacks());
}
return effectiveCallbacks;
}
use of org.flywaydb.core.api.callback.Callback in project spring-boot by spring-projects.
the class Flyway6xAutoConfigurationTests method callbacksAreConfiguredAndOrdered.
@Test
void callbacksAreConfiguredAndOrdered() {
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class);
Callback callbackOne = context.getBean("callbackOne", Callback.class);
Callback callbackTwo = context.getBean("callbackTwo", Callback.class);
assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2);
assertThat(flyway.getConfiguration().getCallbacks()).containsExactly(callbackTwo, callbackOne);
InOrder orderedCallbacks = inOrder(callbackOne, callbackTwo);
orderedCallbacks.verify(callbackTwo).handle(any(Event.class), any(Context.class));
orderedCallbacks.verify(callbackOne).handle(any(Event.class), any(Context.class));
});
}
use of org.flywaydb.core.api.callback.Callback in project spring-boot by spring-projects.
the class FlywayAutoConfigurationTests method callbacksAreConfiguredAndOrderedByName.
@Test
void callbacksAreConfiguredAndOrderedByName() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, CallbackConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class);
Callback callbackOne = context.getBean("callbackOne", Callback.class);
Callback callbackTwo = context.getBean("callbackTwo", Callback.class);
assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2);
InOrder orderedCallbacks = inOrder(callbackOne, callbackTwo);
orderedCallbacks.verify(callbackTwo).handle(any(Event.class), any(Context.class));
orderedCallbacks.verify(callbackOne).handle(any(Event.class), any(Context.class));
});
}
use of org.flywaydb.core.api.callback.Callback in project spring-boot by spring-projects.
the class Flyway7xAutoConfigurationTests method callbacksAreConfigured.
@Test
void callbacksAreConfigured() {
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class);
Callback callbackOne = context.getBean("callbackOne", Callback.class);
Callback callbackTwo = context.getBean("callbackTwo", Callback.class);
assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2);
assertThat(flyway.getConfiguration().getCallbacks()).containsExactlyInAnyOrder(callbackTwo, callbackOne);
then(callbackOne).should(atLeastOnce()).handle(any(Event.class), any(Context.class));
then(callbackTwo).should(atLeastOnce()).handle(any(Event.class), any(Context.class));
});
}
Aggregations