Class LiquibaseDBUtils


  • public class LiquibaseDBUtils
    extends Object
    • Constructor Detail

      • LiquibaseDBUtils

        public LiquibaseDBUtils()
    • Method Detail

      • dropTable

        public static void dropTable​(IEntityContext ec,
                                     String tableName)
                              throws Exception
        Method to drop a table while using the underlying database connection. In order for the deletion to take place, the system first checks whether the table exists. If the table does not exist a log-entry is being written and processing is aborted.
        Parameters:
        ec - the entity context for the database-connection to use
        tableName - the name of the table to delete
        Throws:
        Exception - on errors while dropping the table
      • createClobTable

        public static void createClobTable​(Connection connection,
                                           String tableName,
                                           List<String> columnNames,
                                           boolean createForeignKeyConstraint)
                                    throws SQLException,
                                           liquibase.exception.PreconditionFailedException,
                                           liquibase.exception.DatabaseException,
                                           liquibase.exception.PreconditionErrorException
        Creates a CLOB table.
        Parameters:
        connection - database connection
        tableName - table name
        columnNames - column names
        createForeignKeyConstraint - true, if foreign key should be created
        Throws:
        SQLException - if an error during database operation occurs
        liquibase.exception.PreconditionFailedException - if table already exists
        liquibase.exception.DatabaseException - if database connection cannot be established
        liquibase.exception.PreconditionErrorException - if precondition cannot be checked
      • createTable

        public static void createTable​(IEntityContext ec,
                                       String tableName,
                                       ArrayList<String> colNames,
                                       String colType)
                                throws Exception
        Method to create a table while using the underlying database connection. In order for the table to be created, it is first checked whether the table does not exist. If the table already exists, a log message is displayed and processing is aborted.
        Parameters:
        ec - the entity context for the database-connection to use
        tableName - the name of the table to create
        colNames - the names of the columns to use for this table
        colType - the type of the columns to use for this table
        Throws:
        Exception
      • getTableExistsPrecondition

        public static liquibase.precondition.core.TableExistsPrecondition getTableExistsPrecondition​(liquibase.database.Database db,
                                                                                                     String tableName)
                                                                                              throws liquibase.exception.DatabaseException
        Method to create a TableExistsPrecondition to checks if a table exists.
        Parameters:
        db - the database to check the table existence for
        tableName - the name of the table to check for
        Returns:
        TableExistsPrecondition the resulting check
        Throws:
        liquibase.exception.DatabaseException
      • getForeignKeyExistsPrecondition

        public static liquibase.precondition.core.ForeignKeyExistsPrecondition getForeignKeyExistsPrecondition​(liquibase.database.Database db,
                                                                                                               String tableName,
                                                                                                               String foreignKey)
                                                                                                        throws liquibase.exception.DatabaseException
        Method to create a ForeignKeyExistsPrecondition check if a foreign key exists
        Parameters:
        db - the database to use
        tableName - the name of the table to check for the foreign key
        foreignKey - the name of the foreign key to check
        Returns:
        ForeignKeyExistsPrecondition the resulting check
        Throws:
        liquibase.exception.DatabaseException
      • getAddForeignKeyConstraintStatement

        public static liquibase.sql.Sql[] getAddForeignKeyConstraintStatement​(liquibase.database.Database db,
                                                                              String tableName)
      • getForeignKeyName

        public static String getForeignKeyName​(String tableName)
      • getPrimaryKeyName

        public static String getPrimaryKeyName​(String tableName)
      • renameTable

        public static void renameTable​(Connection connection,
                                       String oldTableName,
                                       String newTableName)
                                throws SQLException,
                                       liquibase.exception.DatabaseException,
                                       liquibase.exception.PreconditionFailedException,
                                       liquibase.exception.PreconditionErrorException
        Renames a table.
        Parameters:
        connection - connection
        oldTableName - old table name
        newTableName - new table name
        Throws:
        SQLException - if generated SQL cannot be executed
        liquibase.exception.DatabaseException - if database connection cannot be established
        liquibase.exception.PreconditionFailedException - if table does not exist or table with new name already exists
        liquibase.exception.PreconditionErrorException - if precondition cannot be checked
      • dropTable

        public static void dropTable​(Connection connection,
                                     String tableName)
                              throws liquibase.exception.DatabaseException,
                                     liquibase.exception.PreconditionFailedException,
                                     liquibase.exception.PreconditionErrorException,
                                     SQLException
        Drops a table.
        Parameters:
        connection - database connection
        tableName - table name
        Throws:
        liquibase.exception.DatabaseException - if database connection cannot be established
        liquibase.exception.PreconditionFailedException - if the table does not exist
        liquibase.exception.PreconditionErrorException - if precondition cannot be checked
        SQLException - if an error during database operation occurs
      • createTable

        public static void createTable​(Connection connection,
                                       String tableName,
                                       List<String> columnNames,
                                       String columnType,
                                       boolean createForeignKeyConstraint)
                                throws liquibase.exception.DatabaseException,
                                       liquibase.exception.PreconditionFailedException,
                                       liquibase.exception.PreconditionErrorException,
                                       SQLException
        Creates a table.
        Parameters:
        connection - database connection
        tableName - table name
        columnNames - column names
        columnType - column type
        createForeignKeyConstraint - true, if foreign key constraint to form record should be created
        Throws:
        liquibase.exception.DatabaseException - if database connection cannot be established
        liquibase.exception.PreconditionFailedException - if table already exists
        liquibase.exception.PreconditionErrorException - if precondition cannot be checked
        SQLException - if an error during database operation occurs