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" />
 
 </bean>
 
 

Author:
Rob Schoening

Nested Class Summary
 class SpringLiquibase.SpringResourceOpener
           
 
Field Summary
protected  String beanName
           
protected  String changeLog
           
protected  String contexts
           
protected  DataSource dataSource
           
protected  String defaultSchema
           
protected  boolean dropFirst
           
protected  String labels
           
protected  Logger log
           
protected  Map<String,String> parameters
           
protected  org.springframework.core.io.ResourceLoader resourceLoader
           
protected  File rollbackFile
           
protected  boolean shouldRun
           
protected  String tag
           
 
Constructor Summary
SpringLiquibase()
           
 
Method Summary
 void afterPropertiesSet()
          Executed automatically when the bean is initialized.
protected  Database createDatabase(Connection c, ResourceAccessor resourceAccessor)
          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()
           
 String getLabels()
           
 org.springframework.core.io.ResourceLoader getResourceLoader()
           
 String getTag()
           
 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 setLabels(String labels)
           
 void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
           
 void setRollbackFile(File rollbackFile)
           
 void setShouldRun(boolean shouldRun)
           
 void setTag(String tag)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

beanName

protected String beanName

resourceLoader

protected org.springframework.core.io.ResourceLoader resourceLoader

dataSource

protected DataSource dataSource

log

protected final Logger log

changeLog

protected String changeLog

contexts

protected String contexts

labels

protected String labels

tag

protected String tag

parameters

protected Map<String,String> parameters

defaultSchema

protected String defaultSchema

dropFirst

protected boolean dropFirst

shouldRun

protected boolean shouldRun

rollbackFile

protected File rollbackFile
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)

getLabels

public String getLabels()

setLabels

public void setLabels(String labels)

getTag

public String getTag()

setTag

public void setTag(String tag)

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,
                                  ResourceAccessor resourceAccessor)
                           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 © 2015 Liquibase.org. All rights reserved.