Package de.xima.fc.liquibase
Class LiquibaseDBUtils
- java.lang.Object
-
- de.xima.fc.liquibase.LiquibaseDBUtils
-
public class LiquibaseDBUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description LiquibaseDBUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcreateBlobTable(IEntityContext ec, String tableName, ArrayList<String> colNames)static voidcreateClobTable(IEntityContext ec, String tableName, ArrayList<String> colNames)static voidcreateClobTable(Connection connection, String tableName, List<String> columnNames, boolean createForeignKeyConstraint)Creates a CLOB table.static voidcreateTable(IEntityContext ec, String tableName, ArrayList<String> colNames)Deprecated.static voidcreateTable(IEntityContext ec, String tableName, ArrayList<String> colNames, String colType)Method to create a table while using the underlying database connection.static voidcreateTable(IEntityContext ec, String tableName, ArrayList<String> colNames, String colType, boolean autoIncrement)Deprecated.static voidcreateTable(Connection connection, String tableName, List<String> columnNames, String columnType, boolean createForeignKeyConstraint)Creates a table.static voiddropTable(IEntityContext ec, String tableName)Method to drop a table while using the underlying database connection.static voiddropTable(Connection connection, String tableName)Drops a table.static liquibase.sql.Sql[]getAddForeignKeyConstraintStatement(liquibase.database.Database db, String tableName)static liquibase.precondition.core.ForeignKeyExistsPreconditiongetForeignKeyExistsPrecondition(liquibase.database.Database db, String tableName, String foreignKey)Method to create a ForeignKeyExistsPrecondition check if a foreign key existsstatic StringgetForeignKeyName(String tableName)static StringgetPrimaryKeyName(String tableName)static liquibase.precondition.core.TableExistsPreconditiongetTableExistsPrecondition(liquibase.database.Database db, String tableName)Method to create a TableExistsPrecondition to checks if a table exists.static voidrenameTable(Connection connection, String oldTableName, String newTableName)Renames a table.
-
-
-
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 usetableName- the name of the table to delete- Throws:
Exception- on errors while dropping the table
-
createTable
@Deprecated public static void createTable(IEntityContext ec, String tableName, ArrayList<String> colNames) throws Exception
Deprecated.- Throws:
Exception
-
createTable
@Deprecated public static void createTable(IEntityContext ec, String tableName, ArrayList<String> colNames, String colType, boolean autoIncrement) throws Exception
Deprecated.- Throws:
Exception
-
createBlobTable
public static void createBlobTable(IEntityContext ec, String tableName, ArrayList<String> colNames) throws Exception
- Throws:
Exception
-
createClobTable
public static void createClobTable(IEntityContext ec, String tableName, ArrayList<String> colNames) throws Exception
- Throws:
Exception
-
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 connectiontableName- table namecolumnNames- column namescreateForeignKeyConstraint- true, if foreign key should be created- Throws:
SQLException- if an error during database operation occursliquibase.exception.PreconditionFailedException- if table already existsliquibase.exception.DatabaseException- if database connection cannot be establishedliquibase.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 usetableName- the name of the table to createcolNames- the names of the columns to use for this tablecolType- 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.DatabaseExceptionMethod to create a TableExistsPrecondition to checks if a table exists.- Parameters:
db- the database to check the table existence fortableName- 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.DatabaseExceptionMethod to create a ForeignKeyExistsPrecondition check if a foreign key exists- Parameters:
db- the database to usetableName- the name of the table to check for the foreign keyforeignKey- 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)
-
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- connectionoldTableName- old table namenewTableName- new table name- Throws:
SQLException- if generated SQL cannot be executedliquibase.exception.DatabaseException- if database connection cannot be establishedliquibase.exception.PreconditionFailedException- if table does not exist or table with new name already existsliquibase.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 connectiontableName- table name- Throws:
liquibase.exception.DatabaseException- if database connection cannot be establishedliquibase.exception.PreconditionFailedException- if the table does not existliquibase.exception.PreconditionErrorException- if precondition cannot be checkedSQLException- 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 connectiontableName- table namecolumnNames- column namescolumnType- column typecreateForeignKeyConstraint- true, if foreign key constraint to form record should be created- Throws:
liquibase.exception.DatabaseException- if database connection cannot be establishedliquibase.exception.PreconditionFailedException- if table already existsliquibase.exception.PreconditionErrorException- if precondition cannot be checkedSQLException- if an error during database operation occurs
-
-