public class DatabaseUtils extends Object
Currently, we use Flyway DB (http://flywaydb.org/) for database management.
DatabaseManager| Constructor and Description |
|---|
DatabaseUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
canonicalize(Connection connection,
String dbIdentifier)
Return the canonical name for a database identifier based on whether this
database defaults to storing identifiers in uppercase or lowercase.
|
static void |
checkReindexDiscovery(IndexingService indexer)
Method to check whether we need to reindex in Discovery (i.e.
|
static void |
executeSql(Connection connection,
String sqlToExecute)
Execute a block of SQL against the current database connection.
|
static boolean |
getReindexDiscovery()
Whether or not reindexing is required in Discovery.
|
static String |
getSchemaName(Connection connection)
Get the Database Schema Name in use by this Connection, so that it can
be used to limit queries in other methods (e.g.
|
static void |
main(String[] argv)
Commandline tools for managing database changes, etc.
|
static boolean |
sequenceExists(Connection connection,
String sequenceName) |
static void |
setReindexDiscovery(boolean reindex)
Whether or not to tell Discovery to reindex itself based on the updated
database.
|
static boolean |
tableColumnExists(Connection connection,
String tableName,
String columnName)
Determine if a particular database column exists in our database
|
static boolean |
tableExists(Connection connection,
String tableName)
Determine if a particular database table exists in our database
|
static boolean |
tableExists(Connection connection,
String tableName,
boolean caseSensitive)
Determine if a particular database table exists in our database
|
protected static void |
updateDatabase(DataSource datasource,
Connection connection)
Ensures the current database is up-to-date with regards
to the latest DSpace DB schema.
|
protected static void |
updateDatabase(DataSource datasource,
Connection connection,
String targetVersion,
boolean outOfOrder)
Ensures the current database is up-to-date with regards
to the latest DSpace DB schema.
|
public static void main(String[] argv)
argv - protected static void updateDatabase(DataSource datasource, Connection connection) throws SQLException
FlywayDB (http://flywaydb.org/) is used to perform database migrations. If a Flyway DB migration fails it will be rolled back to the last successful migration, and any errors will be logged.
datasource - DataSource object (retrieved from DatabaseManager())connection - Database connectionSQLException - If database cannot be upgraded.protected static void updateDatabase(DataSource datasource, Connection connection, String targetVersion, boolean outOfOrder) throws SQLException
FlywayDB (http://flywaydb.org/) is used to perform database migrations. If a Flyway DB migration fails it will be rolled back to the last successful migration, and any errors will be logged.
datasource - DataSource object (retrieved from DatabaseManager())connection - Database connectiontargetVersion - If specified, only migrate the database to a particular *version* of DSpace. This is mostly just useful for testing.
If null, the database is migrated to the latest version.outOfOrder - If true, Flyway will run any lower version migrations that were previously "ignored".
If false, Flyway will only run new migrations with a higher version number.SQLException - If database cannot be upgraded.public static boolean tableExists(Connection connection, String tableName)
connection - Current Database ConnectiontableName - The name of the tablepublic static boolean tableExists(Connection connection, String tableName, boolean caseSensitive)
connection - Current Database ConnectiontableName - The name of the tablecaseSensitive - When "true", the case of the tableName will not be changed.
When "false, the name may be uppercased or lowercased based on DB type.public static boolean tableColumnExists(Connection connection, String tableName, String columnName)
connection - Current Database ConnectiontableName - The name of the tablecolumnName - The name of the column in the tablepublic static boolean sequenceExists(Connection connection, String sequenceName)
public static void executeSql(Connection connection, String sqlToExecute) throws SQLException
The SQL is executed using the Flyway SQL parser.
connection - Current Database ConnectionsqlToExecute - The actual SQL to execute as a StringSQLException - If a database error occurspublic static String getSchemaName(Connection connection) throws SQLException
For PostgreSQL, schema is simply what is configured in db.schema or "public" For Oracle, schema is actually the database *USER* or owner.
connection - Current Database ConnectionSQLExceptionpublic static String canonicalize(Connection connection, String dbIdentifier) throws SQLException
connection - Current Database ConnectiondbIdentifier - Identifier to canonicalize (may be a table name, column name, etc)SQLExceptionpublic static void setReindexDiscovery(boolean reindex)
Whenever a DB migration occurs this is set to "true" to ensure the Discovery index is updated. When Discovery initializes it calls checkReindexDiscovery() to reindex if this flag is true.
Because the DB migration may be initialized by commandline or any one of the many DSpace webapps, setting this to "true" actually writes a temporary file which lets Solr know when reindex is needed.
reindex - true or falsepublic static boolean getReindexDiscovery()
Because the DB migration may be initialized by commandline or any one of the many DSpace webapps, this checks for the existence of a temporary file to know when Discovery/Solr needs reindexing.
public static void checkReindexDiscovery(IndexingService indexer)
This method is called by Discovery whenever it initializes a connection to Solr.
indexer - The actual indexer to use to reindex Discovery, if neededSolrServiceImplCopyright © 2014 DuraSpace. All Rights Reserved.