Class AsyncSpringLiquibase

java.lang.Object
liquibase.integration.spring.SpringLiquibase
org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase
tech.jhipster.config.liquibase.AsyncSpringLiquibase
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware

public class AsyncSpringLiquibase extends org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase
Specific liquibase.integration.spring.SpringLiquibase that will update the database asynchronously and close DataSource if necessary.

By default, this asynchronous version only works when using the "dev" profile.

The standard liquibase.integration.spring.SpringLiquibase starts Liquibase in the current thread:

  • This is needed if you want to do some database requests at startup
  • This ensure that the database is ready when the application starts
But as this is a rather slow process, we use this asynchronous version to speed up our start-up time:
  • On a recent MacBook Pro, start-up time is down from 14 seconds to 8 seconds
  • In production, this can help your application run on platforms like Heroku, where it must start/restart very quickly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant DISABLED_MESSAGE="Liquibase is disabled"
    static final String
    Constant EXCEPTION_MESSAGE="Liquibase could not start correctly, yo"{trunked}
    static final String
    Constant SLOWNESS_MESSAGE="Warning, Liquibase took more than {} se"{trunked}
    static final long
    Constant SLOWNESS_THRESHOLD=5
    static final String
    Constant STARTED_MESSAGE="Liquibase has updated your database in "{trunked}
    static final String
    Constant STARTING_ASYNC_MESSAGE="Starting Liquibase asynchronously, your"{trunked}
    static final String
    Constant STARTING_SYNC_MESSAGE="Starting Liquibase synchronously"

    Fields inherited from class liquibase.integration.spring.SpringLiquibase

    beanName, changeLog, clearCheckSums, contexts, databaseChangeLogLockTable, databaseChangeLogTable, dataSource, defaultSchema, dropFirst, labelFilter, liquibaseSchema, liquibaseTablespace, log, parameters, resourceLoader, rollbackFile, shouldRun, tag, testRollbackOnUpdate
  • Constructor Summary

    Constructors
    Constructor
    Description
    AsyncSpringLiquibase(Executor executor, org.springframework.core.env.Environment env)
    Constructor for AsyncSpringLiquibase.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    protected void
    initDb.

    Methods inherited from class org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase

    destroy, setCloseDataSourceOnceMigrated

    Methods inherited from class liquibase.integration.spring.SpringLiquibase

    createDatabase, createLiquibase, createResourceOpener, getBeanName, getChangeLog, getContexts, getDatabaseChangeLogLockTable, getDatabaseChangeLogTable, getDatabaseProductName, getDataSource, getDefaultSchema, getLabelFilter, getLabels, getLiquibaseSchema, getLiquibaseTablespace, getResourceLoader, getTag, isClearCheckSums, isDropFirst, isIgnoreClasspathPrefix, isTestRollbackOnUpdate, performUpdate, setBeanName, setChangeLog, setChangeLogParameters, setClearCheckSums, setContexts, setDatabaseChangeLogLockTable, setDatabaseChangeLogTable, setDataSource, setDefaultSchema, setDropFirst, setIgnoreClasspathPrefix, setLabelFilter, setLabels, setLiquibaseSchema, setLiquibaseTablespace, setResourceLoader, setRollbackFile, setShouldRun, setTag, setTestRollbackOnUpdate, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DISABLED_MESSAGE

      public static final String DISABLED_MESSAGE
      Constant DISABLED_MESSAGE="Liquibase is disabled"
      See Also:
    • STARTING_ASYNC_MESSAGE

      public static final String STARTING_ASYNC_MESSAGE
      Constant STARTING_ASYNC_MESSAGE="Starting Liquibase asynchronously, your"{trunked}
      See Also:
    • STARTING_SYNC_MESSAGE

      public static final String STARTING_SYNC_MESSAGE
      Constant STARTING_SYNC_MESSAGE="Starting Liquibase synchronously"
      See Also:
    • STARTED_MESSAGE

      public static final String STARTED_MESSAGE
      Constant STARTED_MESSAGE="Liquibase has updated your database in "{trunked}
      See Also:
    • EXCEPTION_MESSAGE

      public static final String EXCEPTION_MESSAGE
      Constant EXCEPTION_MESSAGE="Liquibase could not start correctly, yo"{trunked}
      See Also:
    • SLOWNESS_THRESHOLD

      public static final long SLOWNESS_THRESHOLD
      Constant SLOWNESS_THRESHOLD=5
      See Also:
    • SLOWNESS_MESSAGE

      public static final String SLOWNESS_MESSAGE
      Constant SLOWNESS_MESSAGE="Warning, Liquibase took more than {} se"{trunked}
      See Also:
  • Constructor Details

    • AsyncSpringLiquibase

      public AsyncSpringLiquibase(Executor executor, org.springframework.core.env.Environment env)

      Constructor for AsyncSpringLiquibase.

      Parameters:
      executor - a Executor object.
      env - a Environment object.
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws liquibase.exception.LiquibaseException
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase
      Throws:
      liquibase.exception.LiquibaseException
    • initDb

      protected void initDb() throws liquibase.exception.LiquibaseException

      initDb.

      Throws:
      liquibase.exception.LiquibaseException - if any.