Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6

The GarinDriver supports JDBC driver level integration with LiquiBase.

Overview

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.

Install:

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. http://code.google.com/p/garindriver/

Example code:

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");
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 "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 farnsworth2008@gmail.com. http://code.google.com/p/garindriver/

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

  • No labels