Class LiquibaseUtils
- Author:
- lbruun
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetLiquibaseDatabaseShortName(DataSource dataSource) Finds the Liquibase databaseshortnamefor a DataSource.
-
Method Details
-
getLiquibaseDatabaseShortName
Finds the Liquibase databaseshortnamefor a DataSource.Non-complete list of possible return values:
postgresql. PostgreSQLmysql. MySQLmariadb. MariaDBmssql. Microsoft SQL Serverh2. H2 databasehsqldb. HyperSQL databaseoracle. Oracle Databasedb2. IBM Db2 on Linux, Unix and Windowsdb2z. IBM Db2 on zOSderby. Apache Derbysqlite. SQLitesybase. Sybase Adaptive Server Enterpriseunsupported. Database not supported by Liquibase
dbmsPrecondition. 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
DatabaseMetaDatawhich is then matched against known database platforms in Liquibase. If there's any error during this operation thenPreLiquibaseExceptionwill 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
-