Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The GarinDriver supports JDBC driver level integration with LiquiBase.

Overview:

Simply place garin.jar in your class path and configure your JDBC URL to ensure that LiquiBase schema manager runs automatically as part of the connection life cycle. http://code.google.com/p/garindriver/

Example code:

01| String url = "garin:m=liquibase,s=tst/liquidbase/changelog.xml;demo:jdbc:mysql://localhost/garinDB";
02| Connection c = DriverManager.getConnection(url, "garinAgent","bigboy");
03| Statement s = c.createStatement();
04| ResultSet r = s.executeQuery("SELECT count(star) FROM news");
05| r.next();
06| int rowCount = r.getInt(1);
07| System.out.println("ROW COUNT: " + rowCount);
08| r.close();
09| s.close();
10| c.close();

In this example the liquibase schema manager runs with "changelog.xml" and a context of "demo". 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 farnsworth2008@gmail.com. http://code.google.com/p/garindriver/

Mark Farnsworth
farnsworth2008@gmail.com
markfarnsworth.wordpress.com