Class PreLiquibase

java.lang.Object
net.lbruun.springboot.preliquibase.PreLiquibase

public class PreLiquibase extends Object
DataSource initializer for Pre-Liquibase module.

This class locates and executes SQL scripts against a DataSource. It is meant as a companion to Liquibase.

The SQL scripts to be executed are specified via the sqlScriptReferences configuration property.

Prior to execution the SQL scripts are 'filtered through the environment'. This means that placeholders in the SQL scripts on the form ${propertname} or ${propertname:defaultvalue} are replaced with the appropriate value from the Spring Environment.

Author:
lbruun
  • Constructor Details

    • PreLiquibase

      public PreLiquibase(org.springframework.core.env.Environment environment, DataSource dataSource, PreLiquibaseProperties properties, org.springframework.core.io.ResourceLoader resourceLoader)
      Create a new instance with the DataSource to initialize and its matching configuration.
      Parameters:
      environment - the source for placeholder substitution in SQL scripts
      dataSource - the JDBC datasource to initialize
      properties - configuration for the Pre-Liquibase module
      resourceLoader - the resource loader to use for locating (and loading) SQL scripts. Can be null. This is typically your ApplicationContext. If null then a DefaultResourceLoader is used.
  • Method Details

    • execute

      public void execute()
      Executes PreLiquibase.
      Throws:
      PreLiquibaseException.ResolveDbPlatformError - if there are errors while determining the type of database platform.
      PreLiquibaseException.SqlScriptReadError - if SQL script cannot be read (as part of the variable substitution process)
      PreLiquibaseException.SqlScriptVarError - if placeholder variables in a SQL script cannot be resolved or if there are circular references in these placeholders.
      PreLiquibaseException.SqlScriptRefError - if a SQL script specified in the sqlScriptReferences property cannot be found.
      org.springframework.jdbc.datasource.init.ScriptException - (or subclass) if there are script execution errors. In case of a SQL error the ScriptException will wrap an exception of type SQLException.
    • getDataSource

      public DataSource getDataSource()
      Gets the DataSource used by PreLiquibase.
      Returns:
      datasource
    • getUnfilteredResources

      public List<org.springframework.core.io.Resource> getUnfilteredResources()
      Gets the SQL scripts executed by PreLiquibase. (these are the "raw" SQL scripts, meaning before substitution of variables in the script)
      Returns:
      sql scripts
      Throws:
      PreLiquibaseException.UninitializedError - if the method is invoked prior to execute().
    • getFilteredResources

      public List<org.springframework.core.io.Resource> getFilteredResources()
      Gets the SQL scripts executed by PreLiquibase. (these are the "filtered" SQL scripts, meaning after substitution of variables in the script)
      Returns:
      sql scripts
      Throws:
      PreLiquibaseException.UninitializedError - if the method is invoked prior to execute().
    • getDbPlatformCode

      public String getDbPlatformCode()
      Gets the resolved dbPlatformCode as used by PreLiquibase. This can either be a value which PreLiquibase has decided based on auto-detection of the database platform in use, or it can be a value which was set explicitly by the user via the dbPlatformCode property.
      Returns:
      database platform code
      Throws:
      PreLiquibaseException.UninitializedError - if the method is invoked prior to execute().
    • hasExecutedScripts

      public boolean hasExecutedScripts()
      Indicates if PreLiquibase has actually executed some SQL script(s) or not. Reasons why nothing was executed are one of the following:
      Returns:
      true if at least one SQL script was executed (successfully or with error)
      Throws:
      PreLiquibaseException.UninitializedError - if the method is invoked prior to execute().