Class MigrationUtils
- java.lang.Object
-
- org.dspace.storage.rdbms.migration.MigrationUtils
-
public class MigrationUtils extends Object
This Utility class offers utility methods which may be of use to perform common Java database migration task(s) (via Flyway).NOTE: This class specifically CANNOT utilize Hibernate, because it is used for database migrations which take place PRIOR to Hibernate loading. However, as you'll see below, all methods are protected to ensure the rest of the API cannot bypass Hibernate.
- Author:
- Tim Donohue
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static IntegerdropDBConstraint(Connection connection, String tableName, String columnName, String constraintSuffix)Drop a given Database Constraint (based on the current database type).protected static IntegerdropDBSequence(Connection connection, String sequenceName)Drop a given Database Sequence (based on the current database type).protected static IntegerdropDBTable(Connection connection, String tableName)Drop a given Database Table (based on the current database type).protected static IntegerdropDBView(Connection connection, String viewName)Drop a given Database View (based on the current database type).static StringgetResourceAsString(String resourcePath)Read a given Resource, converting to a String.
-
-
-
Method Detail
-
dropDBConstraint
protected static Integer dropDBConstraint(Connection connection, String tableName, String columnName, String constraintSuffix) throws SQLException
Drop a given Database Constraint (based on the current database type). Returns a "checksum" for this migration which can be used as part of a Flyway Java migration- Parameters:
connection- the current Database connectiontableName- the name of the table the constraint applies tocolumnName- the name of the column the constraint applies toconstraintSuffix- Only used for PostgreSQL, whose constraint naming convention depends on a suffix (key, fkey, etc)- Returns:
- migration checksum as an Integer
- Throws:
SQLException- if a database error occurs
-
dropDBTable
protected static Integer dropDBTable(Connection connection, String tableName) throws SQLException
Drop a given Database Table (based on the current database type). Returns a "checksum" for this migration which can be used as part of a Flyway Java migrationNOTE: Ideally, if you need to do a DROP TABLE, you should just create a Flyway SQL migration. This method should ONLY be used if the table name needs to be dynamically determined via Java.
- Parameters:
connection- the current Database connectiontableName- the name of the table to drop- Returns:
- migration checksum as an Integer
- Throws:
SQLException- if a database error occurs
-
dropDBSequence
protected static Integer dropDBSequence(Connection connection, String sequenceName) throws SQLException
Drop a given Database Sequence (based on the current database type). Returns a "checksum" for this migration which can be used as part of a Flyway Java migrationNOTE: Ideally, if you need to do a DROP SEQUENCE, you should just create a Flyway SQL migration. This method should ONLY be used if the sequence name needs to be dynamically determined via Java.
- Parameters:
connection- the current Database connectionsequenceName- the name of the sequence to drop- Returns:
- migration checksum as an Integer
- Throws:
SQLException- if a database error occurs
-
dropDBView
protected static Integer dropDBView(Connection connection, String viewName) throws SQLException
Drop a given Database View (based on the current database type). Returns a "checksum" for this migration which can be used as part of a Flyway Java migrationNOTE: Ideally, if you need to do a DROP VIEW, you should just create a Flyway SQL migration. This method should ONLY be used if the view name needs to be dynamically determined via Java.
- Parameters:
connection- the current Database connectionviewName- the name of the view to drop- Returns:
- migration checksum as an Integer
- Throws:
SQLException- if a database error occurs
-
getResourceAsString
public static String getResourceAsString(String resourcePath)
Read a given Resource, converting to a String. This is used by several Java-based migrations to read a SQL migration into a string, so that it can be executed under specific scenarios.- Parameters:
resourcePath- relative path of resource to read- Returns:
- String contents of Resource
-
-