
metridoc.camel.component.liquibase.LiquibaseProcessor Maven / Gradle / Ivy
/*
* Copyright 2010 Trustees of the University of Pennsylvania Licensed under the
* Educational Community License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package metridoc.camel.component.liquibase;
import liquibase.integration.spring.SpringLiquibase;
import metridoc.utils.Assert;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.springframework.core.io.DefaultResourceLoader;
import javax.sql.DataSource;
/**
*
* provides a liquibase processor that can be used directly or via a component. If the passed exchange includes
*
* @author Tommy Barker
*/
public class LiquibaseProcessor implements Processor{
private DataSource dataSource;
private String liquibaseFile;
private String contexts;
private SpringLiquibase springLiquibase;
/**
* creates a liquibase processor that will run a liquibase file with a specified dataSource
*
* @param liquibaseFile
* @param dataSource
*/
public LiquibaseProcessor(String liquibaseFile, DataSource dataSource) {
this(liquibaseFile, dataSource, null);
}
public LiquibaseProcessor(String liquibaseFile, DataSource dataSource,
String defaultContexts) {
Assert.notNull(dataSource, "dataSource must not be null");
Assert.notEmpty(liquibaseFile, "liquibaseFile must not be null");
this.liquibaseFile = liquibaseFile;
this.contexts = defaultContexts;
this.dataSource = dataSource;
}
@Override
public void process(Exchange exchange) throws Exception {
getSpringLiquibase().afterPropertiesSet();
}
SpringLiquibase getSpringLiquibase() {
if (springLiquibase == null) {
springLiquibase = new SpringLiquibase();
springLiquibase.setChangeLog("classpath:" + liquibaseFile);
springLiquibase.setContexts(contexts);
springLiquibase.setDataSource(dataSource);
springLiquibase.setResourceLoader(new DefaultResourceLoader());
}
return springLiquibase;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy