I want to be able to call the LiquiBase directly from Java and go to all the trouble of calling it from command line via JNI or to call it via the main(String[] args) method. Is there a way (and a howto/example)
Thanks in advance
Orlin
Hi Orlin,
Yes you can call perfectly liquibase directly in your code.
As example you can look at the integration test sourcecode. Look at class liquibase.dbtest.AbstractIntegrationTest
Ok,
so I tried but unfortunatly I have the following problem - in the SpringLiquibase there is the following line:
Database database =
DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));
which I cannot recreate since I just don’t have liquibase.database.JdbcConnection.
I am using maven: http://mvnrepository.com/artifact/org.liquibase/liquibase-core/1.9.5
So, what to do?
I am currently migrating from 1.9.5 to 2.0 RC2. The code loads the JTDS driver using DriverManager and then passed in the java.sql.Connection to the constructor of Liquibase.
In 2.0 the API has changes and its not clear to me how I can go about doing it as it seems to rely on internal Liquibase Database classes for each type of database.
Nathan, do you maybe have a sample on how to use a driver like JTDS with the 2.0 API?
The job of the Database classes is to support all the database-type specific logic (which support deferrable foreign key constraints, etc). Whether you use JTDS or the MS JDBC driver, you can use the same liquibase.database.core.MSSQLDatase class. The easiest way to get an instance is with:
Nathan, this would be more elegant if the Liquibase class had a constructor that would take a Connection and set its own FileSystemResourceAccessor. It would then be:
I explicitly require the ResourceAccessor to be passed because I don’t think we should assume any given resource accessor, including FileSystemResorceAccessor. If we had to pick one, I think ClassLoaderResourceAccessor is the more standard one, but there are a lot of use cases that do not use it.
Therefore, I think it’s best to make choosing it a conscious choice of anyone using the liquibase API.