
metridoc.camel.component.liquibase.LiquibaseComponent 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 metridoc.utils.Assert;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.impl.ProcessorEndpoint;
import javax.sql.DataSource;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*
*
* @author Tommy Barker
*/
public class LiquibaseComponent extends DefaultComponent{
private static Pattern pattern = Pattern.compile("liquibase://([^\\?]+)");
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
String contexts = (String) parameters.remove("contexts"); //ok if contexts is null
DataSource dataSource = getDataSource(parameters);
LiquibaseProcessor processor = new LiquibaseProcessor(getLiquibaseFilePath(uri), dataSource, contexts);
return new ProcessorEndpoint(uri, getCamelContext(), processor);
}
static String getLiquibaseFilePath(String uri) {
Matcher m = pattern.matcher(uri);
m.lookingAt();
return m.group(1) + ".xml";
}
DataSource getDataSource(Map parameters) {
String dataSourceReference = (String) parameters.remove("dataSource");
Assert.notEmpty(dataSourceReference, "the dataSource parameter must be provided when using the "
+ "liquibase component");
return getCamelContext().getRegistry().lookup(dataSourceReference, DataSource.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy