Class PreLiquibase
java.lang.Object
net.lbruun.springboot.preliquibase.PreLiquibase
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 Summary
ConstructorsConstructorDescriptionPreLiquibase(org.springframework.core.env.Environment environment, DataSource dataSource, PreLiquibaseProperties properties, org.springframework.core.io.ResourceLoader resourceLoader) Create a new instance with theDataSourceto initialize and its matchingconfiguration. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Executes PreLiquibase.Gets the DataSource used by PreLiquibase.Gets the resolveddbPlatformCodeas used by PreLiquibase.List<org.springframework.core.io.Resource>Gets the SQL scripts executed by PreLiquibase.List<org.springframework.core.io.Resource>Gets the SQL scripts executed by PreLiquibase.booleanIndicates if PreLiquibase has actually executed some SQL script(s) or not.
-
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 theDataSourceto initialize and its matchingconfiguration.- Parameters:
environment- the source for placeholder substitution in SQL scriptsdataSource- the JDBC datasource to initializeproperties- configuration for the Pre-Liquibase moduleresourceLoader- the resource loader to use for locating (and loading) SQL scripts. Can be null. This is typically yourApplicationContext. Ifnullthen aDefaultResourceLoaderis 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 thesqlScriptReferencesproperty cannot be found.org.springframework.jdbc.datasource.init.ScriptException- (or subclass) if there are script execution errors. In case of a SQL error theScriptExceptionwill wrap an exception of typeSQLException.
-
getDataSource
Gets the DataSource used by PreLiquibase.- Returns:
- datasource
-
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 toexecute().
-
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 toexecute().
-
getDbPlatformCode
Gets the resolveddbPlatformCodeas 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 thedbPlatformCodeproperty.- Returns:
- database platform code
- Throws:
PreLiquibaseException.UninitializedError- if the method is invoked prior toexecute().
-
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:PreLiquibasePropertiesenabledproperty was false.- No SQL files were found to execute.
- Returns:
- true if at least one SQL script was executed (successfully or with error)
- Throws:
PreLiquibaseException.UninitializedError- if the method is invoked prior toexecute().
-