com.googlecode.flyway.core.dbsupport
Class DbSupport

java.lang.Object
  extended by com.googlecode.flyway.core.dbsupport.DbSupport
Direct Known Subclasses:
DB2DbSupport, DerbyDbSupport, H2DbSupport, HsqlDbSupport, MySQLDbSupport, OracleDbSupport, PostgreSQLDbSupport, SQLServerDbSupport

public abstract class DbSupport
extends java.lang.Object

Abstraction for database-specific functionality.


Field Summary
protected  JdbcTemplate jdbcTemplate
          The JDBC template available for use.
 
Constructor Summary
DbSupport(JdbcTemplate jdbcTemplate)
          Creates a new DbSupport instance with this JdbcTemplate.
 
Method Summary
abstract  SqlScript createCleanScript(java.lang.String schema)
          Creates a new sql script which clean this schema, by dropping all objects.
abstract  SqlScript createSqlScript(java.lang.String sqlScriptSource, PlaceholderReplacer placeholderReplacer)
          Creates a new sql script from this resource with these placeholders to replace.
abstract  java.lang.String getBooleanFalse()
           
abstract  java.lang.String getBooleanTrue()
           
abstract  java.lang.String getCurrentSchema()
          Retrieves the current schema.
abstract  java.lang.String getCurrentUserFunction()
           
 JdbcTemplate getJdbcTemplate()
           
abstract  java.lang.String getScriptLocation()
          Returns the location on the classpath where the scripts for this database reside.
abstract  boolean isSchemaEmpty(java.lang.String schema)
          Checks if this database schema is empty.
abstract  void lockTable(java.lang.String schema, java.lang.String table)
          Locks this table in this schema using a read/write pessimistic lock until the end of the current transaction.
abstract  boolean supportsDdlTransactions()
          Checks whether ddl transactions are supported for this database.
abstract  boolean tableExists(java.lang.String schema, java.lang.String table)
          Checks whether this table is already present in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jdbcTemplate

protected final JdbcTemplate jdbcTemplate
The JDBC template available for use.

Constructor Detail

DbSupport

public DbSupport(JdbcTemplate jdbcTemplate)
Creates a new DbSupport instance with this JdbcTemplate.

Parameters:
jdbcTemplate - The JDBC template to use.
Method Detail

getJdbcTemplate

public JdbcTemplate getJdbcTemplate()
Returns:
The DB-specific JdbcTemplate instance.

createSqlScript

public abstract SqlScript createSqlScript(java.lang.String sqlScriptSource,
                                          PlaceholderReplacer placeholderReplacer)
Creates a new sql script from this resource with these placeholders to replace.

Parameters:
sqlScriptSource - The sql script as a text block with all placeholders still present.
placeholderReplacer - The placeholder replacer to apply to sql migration scripts.
Returns:
A new sql script, containing the statements from this resource, with all placeholders replaced.
Throws:
java.lang.IllegalStateException - Thrown when the script could not be read from this resource.

createCleanScript

public abstract SqlScript createCleanScript(java.lang.String schema)
                                     throws java.sql.SQLException
Creates a new sql script which clean this schema, by dropping all objects.

Parameters:
schema - The schema to clean.
Returns:
A new sql script, containing drop statements for all objects
Throws:
java.sql.SQLException - when querying the database for generating the clean script failed.

getScriptLocation

public abstract java.lang.String getScriptLocation()
Returns the location on the classpath where the scripts for this database reside.

Returns:
The folder on the classpath, including a trailing slash.

isSchemaEmpty

public abstract boolean isSchemaEmpty(java.lang.String schema)
                               throws java.sql.SQLException
Checks if this database schema is empty.

Parameters:
schema - The schema to check.
Returns:
true if it is empty, false if it is not.
Throws:
java.sql.SQLException - when there was an error checking whether the schema is empty.

tableExists

public abstract boolean tableExists(java.lang.String schema,
                                    java.lang.String table)
                             throws java.sql.SQLException
Checks whether this table is already present in the database.

Parameters:
schema - The schema in which to look.
table - The table to look for.
Returns:
true if the table exists, false if it doesn't.
Throws:
java.sql.SQLException - when there was an error checking whether this table exists in this schema.

getCurrentSchema

public abstract java.lang.String getCurrentSchema()
                                           throws java.sql.SQLException
Retrieves the current schema.

Returns:
The current schema for this connection.
Throws:
java.sql.SQLException - when the current schema could not be retrieved.

getCurrentUserFunction

public abstract java.lang.String getCurrentUserFunction()
Returns:
The database function that returns the current user.

supportsDdlTransactions

public abstract boolean supportsDdlTransactions()
Checks whether ddl transactions are supported for this database.

Returns:
true if ddl transactions are supported, false if not.

lockTable

public abstract void lockTable(java.lang.String schema,
                               java.lang.String table)
                        throws java.sql.SQLException
Locks this table in this schema using a read/write pessimistic lock until the end of the current transaction.

Parameters:
schema - The schema of the table to lock.
table - The table to lock.
Throws:
java.sql.SQLException - when this table in this schema could not be locked.

getBooleanTrue

public abstract java.lang.String getBooleanTrue()
Returns:
The representation of the value true in a boolean column.

getBooleanFalse

public abstract java.lang.String getBooleanFalse()
Returns:
The representation of the value false in a boolean column.


Copyright © 2012. All Rights Reserved.