/*
Copyright 2011-2014 Red Hat, Inc
This file is part of PressGang CCMS.
PressGang CCMS is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PressGang CCMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PressGang CCMS. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jboss.pressgang.ccms.server;
import javax.annotation.Resource;
import javax.enterprise.inject.Produces;
import javax.sql.DataSource;
import java.sql.SQLException;
import liquibase.integration.cdi.CDILiquibaseConfig;
import liquibase.integration.cdi.annotations.LiquibaseType;
import liquibase.resource.ClassLoaderResourceAccessor;
/**
* A Simple CDI Producer to configure the CDI Liquibase integration
*/
public class LiquibaseProducer {
@Resource(lookup = "java:/PressGangCCMSDatasource")
private DataSource myDataSource;
@Produces
@LiquibaseType
public CDILiquibaseConfig createConfig() {
final CDILiquibaseConfig config = new CDILiquibaseConfig();
config.setChangeLog("db/db.changelog.xml");
return config;
}
@Produces
@LiquibaseType
public DataSource createDataSource() throws SQLException {
return myDataSource;
}
@Produces
@LiquibaseType
public liquibase.resource.ResourceAccessor create() {
return new ClassLoaderResourceAccessor(getClass().getClassLoader());
}
}