Hi,
I am trying to invoke Liquibase through the Facade as described in http://liquibase.jira.com/wiki/display/CONTRIB/Liquibase+Facade by passing it a dataSource created by DBCP through Spring as follows,
I am using 2.0 RC1.
In my class, I am invoking Liquibase as follows,
// Create the database
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(ServletActionContext
.getServletContext());
BasicDataSource dataSource = ((BasicDataSource) ctx
.getBean(“dataSource”));
Connection connection = DataSourceUtils
.getTargetConnection(DataSourceUtils.getConnection(dataSource));
// Create the database
Liquibase liquibase = new Liquibase("db.xml",
new ClassLoaderResourceAccessor(), DatabaseFactory
.getInstance().findCorrectDatabaseImplementation(
(DatabaseConnection) connection));
liquibase.update(null);
The problem here is that when using DBCP, it becomes nigh on impossible to cast the connection to a DatabaseConnection and I get a ClassCastException.
I have tried using DriverManager to re-construct a datasource but it still fails noting that it just can’t cast whatever connection is returned by JDBC to DatabaseConnection. I can’t see a way to “create” a DatabaseConnection class in the documentation at all.
Creating another JNDI data source might work but it isn’t an option as I dont want to define 2 different datasources which our end users have to configure.
Any help from people who have experience or insight is appreciated.