Class LiquibaseUtils

java.lang.Object
net.lbruun.springboot.preliquibase.utils.LiquibaseUtils

public class LiquibaseUtils extends Object
Utility methods for Liquibase
Author:
lbruun
  • Method Details

    • getLiquibaseDatabaseShortName

      public static String getLiquibaseDatabaseShortName(DataSource dataSource)
      Finds the Liquibase database shortname for a DataSource.

      Non-complete list of possible return values:

      • postgresql. PostgreSQL
      • mysql. MySQL
      • mariadb. MariaDB
      • mssql. Microsoft SQL Server
      • h2. H2 database
      • hsqldb. HyperSQL database
      • oracle. Oracle Database
      • db2. IBM Db2 on Linux, Unix and Windows
      • db2z. IBM Db2 on zOS
      • derby. Apache Derby
      • sqlite. SQLite
      • sybase. Sybase Adaptive Server Enterprise
      • unsupported. Database not supported by Liquibase
      (These are the same values as those which can be used in a Liquibase dbms Precondition. Refer to Liquibase documentation for further information on possible values.)

      The method invokes liquibase.database.DatabaseFactory#findCorrectDatabaseImplementation() and therefore requires Liquibase library on the classpath.

      The method works like this: The database is determined by connecting to it and retrieving DatabaseMetaData which is then matched against known database platforms in Liquibase. If there's any error during this operation then PreLiquibaseException will be thrown. If there are no errors, but the type of database simply isn't supported by Liquibase then "unsupported" is returned. If all goes well a Liquibase database shortname is returned as per the list above. The connection used to determine the database type is closed again before the method exits.

      Note that this is a fairly heavy operation as it involves a round-trip to the database. As the information does not change it is best to use this method only once and then cache the result.

      Parameters:
      dataSource - input
      Returns:
      Liquibase database shortname, always lower case, never null;
      Throws:
      PreLiquibaseException.ResolveDbPlatformError - on all kinds of errors