The GarinDriver supports JDBC driver level integration with LiquiBase.
GarinDriver provides JDBC driver level support for schema migrations. The driver invokes LiquiBase and/or runs a stack of raw SQL scripts when the client creates the JDBC connection. The system ensures that migration code will run before the application code that depends on the migrations is invoked.
Unzip garinDriver.zip in a new directory and configure your app server to reference the jars in the lib folder (add the jars from the lib folder to your app server, system class path, or create appropriate soft links.). Configure your application JDBC URL with the GarinDriver in place of your existing JDBC URL.
01| String url = "garin:m=liquibase,s=myFolder/myChangeLog.xml;myContext:jdbc:mysql://localhost/garinDB";
02| Connection c = DriverManager.getConnection(url, "garinAgent","bigboy");
03| Statement s = c.createStatement();
04| ResultSet r = s.executeQuery("SELECT count( * ) FROM news");
06| int rowCount = r.getInt(1);
07| System.out.println("ROW COUNT: " + rowCount);
In this example the liquibase schema manager runs with "myChangeLog.xml" and a context of "myContext". The schema manger will run when line 02 is executed since GarinDriver automatically runs LiquiBase at connection initialization.
The benefit of this model is that code that depends on schema is not invoked until AFTER the schema manager has run. In the example provided line 04 requires that the news table exists. Since the news liquibase schema manager deploys the news table you can run this example against an empty database and it will still perform correctly (i.e. liquibase will initialize the database for you).
If you have any questions please visit the GarinDriver code site and/or email me at email@example.com.