liquibase.integration.spring
Class SpringLiquibase

java.lang.Object
  extended by liquibase.integration.spring.SpringLiquibase
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware

public class SpringLiquibase
extends Object
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ResourceLoaderAware

A Spring-ified wrapper for Liquibase.

Example Configuration:

This Spring configuration example will cause liquibase to run automatically when the Spring context is initialized. It will load db-changelog.xml from the classpath and apply it against myDataSource.

 <bean id="myLiquibase"
          class="liquibase.spring.SpringLiquibase"
          >

      <property name="dataSource" ref="myDataSource" />

      <property name="changeLog" value="classpath:db-changelog.xml" />

      <!-- The following configuration options are optional -->

      <property name="executeEnabled" value="true" />

      <!--
      If set to true, writeSqlFileEnabled will write the generated
      SQL to a file before executing it.
      -->
      <property name="writeSqlFileEnabled" value="true" />

      <!--
      sqlOutputDir specifies the directory into which the SQL file
      will be written, if so configured.
      -->
      <property name="sqlOutputDir" value="c:\sql" />

 </bean>

 

Author:
Rob Schoening

Nested Class Summary
 class SpringLiquibase.SpringResourceOpener
           
 
Constructor Summary
SpringLiquibase()
           
 
Method Summary
 void afterPropertiesSet()
          Executed automatically when the bean is initialized.
protected  Database createDatabase(Connection c)
          Subclasses may override this method add change some database settings such as default schema before returning the database object.
protected  Liquibase createLiquibase(Connection c)
           
protected  SpringLiquibase.SpringResourceOpener createResourceOpener()
          Create a new resourceOpener.
 String getBeanName()
          Gets the Spring-name of this instance.
 String getChangeLog()
          Returns a Resource that is able to resolve to a file or classpath resource.
 String getContexts()
           
 String getDatabaseProductName()
           
 DataSource getDataSource()
          The DataSource that liquibase will use to perform the migration.
 String getDefaultSchema()
           
 org.springframework.core.io.ResourceLoader getResourceLoader()
           
 boolean isDropFirst()
           
 boolean isIgnoreClasspathPrefix()
           
protected  void performUpdate(Liquibase liquibase)
           
 void setBeanName(String name)
          Spring sets this automatically to the instance's configured bean name.
 void setChangeLog(String dataModel)
          Sets a Spring Resource that is able to resolve to a file or classpath resource.
 void setChangeLogParameters(Map<String,String> parameters)
           
 void setContexts(String contexts)
           
 void setDataSource(DataSource dataSource)
          The DataSource that liquibase will use to perform the migration.
 void setDefaultSchema(String defaultSchema)
           
 void setDropFirst(boolean dropFirst)
           
 void setIgnoreClasspathPrefix(boolean ignoreClasspathPrefix)
           
 void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
           
 void setRollbackFile(File rollbackFile)
           
 void setShouldRun(boolean shouldRun)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpringLiquibase

public SpringLiquibase()
Method Detail

isDropFirst

public boolean isDropFirst()

setDropFirst

public void setDropFirst(boolean dropFirst)

setShouldRun

public void setShouldRun(boolean shouldRun)

getDatabaseProductName

public String getDatabaseProductName()
                              throws DatabaseException
Throws:
DatabaseException

getDataSource

public DataSource getDataSource()
The DataSource that liquibase will use to perform the migration.

Returns:

setDataSource

public void setDataSource(DataSource dataSource)
The DataSource that liquibase will use to perform the migration.


getChangeLog

public String getChangeLog()
Returns a Resource that is able to resolve to a file or classpath resource.

Returns:

setChangeLog

public void setChangeLog(String dataModel)
Sets a Spring Resource that is able to resolve to a file or classpath resource. An example might be classpath:db-changelog.xml.


getContexts

public String getContexts()

setContexts

public void setContexts(String contexts)

getDefaultSchema

public String getDefaultSchema()

setDefaultSchema

public void setDefaultSchema(String defaultSchema)

afterPropertiesSet

public void afterPropertiesSet()
                        throws LiquibaseException
Executed automatically when the bean is initialized.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
LiquibaseException

performUpdate

protected void performUpdate(Liquibase liquibase)
                      throws LiquibaseException
Throws:
LiquibaseException

createLiquibase

protected Liquibase createLiquibase(Connection c)
                             throws LiquibaseException
Throws:
LiquibaseException

createDatabase

protected Database createDatabase(Connection c)
                           throws DatabaseException
Subclasses may override this method add change some database settings such as default schema before returning the database object.

Parameters:
c -
Returns:
a Database implementation retrieved from the DatabaseFactory.
Throws:
DatabaseException

setChangeLogParameters

public void setChangeLogParameters(Map<String,String> parameters)

createResourceOpener

protected SpringLiquibase.SpringResourceOpener createResourceOpener()
Create a new resourceOpener.


setBeanName

public void setBeanName(String name)
Spring sets this automatically to the instance's configured bean name.

Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

getBeanName

public String getBeanName()
Gets the Spring-name of this instance.

Returns:

setResourceLoader

public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
Specified by:
setResourceLoader in interface org.springframework.context.ResourceLoaderAware

getResourceLoader

public org.springframework.core.io.ResourceLoader getResourceLoader()

setRollbackFile

public void setRollbackFile(File rollbackFile)

isIgnoreClasspathPrefix

public boolean isIgnoreClasspathPrefix()

setIgnoreClasspathPrefix

public void setIgnoreClasspathPrefix(boolean ignoreClasspathPrefix)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Liquibase.org. All Rights Reserved.