mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-2758] Fixing the database setup so that migration depends on the DatabaseUtils commands. Migration will no longer occur on kernel init.
This commit is contained in:
@@ -28,7 +28,7 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class HibernateDBConnection implements DBConnection<Session> {
|
||||
|
||||
@Autowired
|
||||
@Autowired(required = true)
|
||||
@Qualifier("sessionFactory")
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
|
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.core;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.FlywayException;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.*;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Flyway integrator for hibernate.
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public class HibernateFlywayIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
final Flyway flyway = new Flyway();
|
||||
String url = (String) sessionFactory.getProperties().get("hibernate.connection.url");
|
||||
String username = (String) sessionFactory.getProperties().get("hibernate.connection.username");
|
||||
String password = (String) sessionFactory.getProperties().get("hibernate.connection.password");
|
||||
|
||||
flyway.setDataSource(url, username, password);
|
||||
flyway.setEncoding("UTF-8");
|
||||
|
||||
ArrayList<String> scriptLocations = new ArrayList<>();
|
||||
|
||||
String hibernateType = "";
|
||||
Dialect dialect = Dialect.getDialect(sessionFactory.getProperties());
|
||||
if(dialect instanceof Oracle8iDialect)
|
||||
{
|
||||
hibernateType = "oracle";
|
||||
}else if (dialect instanceof PostgreSQL81Dialect)
|
||||
{
|
||||
hibernateType = "postgres";
|
||||
}else{
|
||||
hibernateType = "h2";
|
||||
}
|
||||
|
||||
|
||||
// Also add the Java package where Flyway will load SQL migrations from (based on DB Type)
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration." + hibernateType);
|
||||
|
||||
// Also add the Java package where Flyway will load Java migrations from
|
||||
// NOTE: this also loads migrations from any sub-package
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.migration");
|
||||
|
||||
//We cannot request services at this point, so we will have to do it the old fashioned way
|
||||
if (ConfigurationManager.getProperty("workflow", "workflow.framework").equals("xmlworkflow"))
|
||||
{
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration.workflow." + hibernateType + ".xmlworkflow");
|
||||
}else{
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration.workflow." + hibernateType + ".basicWorkflow");
|
||||
}
|
||||
|
||||
|
||||
flyway.setLocations(scriptLocations.toArray(new String[scriptLocations.size()]));
|
||||
try {
|
||||
flyway.migrate();
|
||||
} catch (FlywayException e) {
|
||||
throw new RuntimeException("Error while performing flyway migration", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
|
||||
}
|
||||
}
|
@@ -7,13 +7,15 @@
|
||||
*/
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.dspace.browse.IndexBrowse;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.search.DSIndexer;
|
||||
import org.dspace.services.KernelStartupCallbackService;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -27,11 +29,11 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Tim Donohue
|
||||
*/
|
||||
public class DatabaseLegacyReindexer implements KernelStartupCallbackService
|
||||
public class DatabaseLegacyReindexer implements FlywayCallback
|
||||
{
|
||||
/** logging category */
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseLegacyReindexer.class);
|
||||
|
||||
|
||||
/**
|
||||
* Method to actually reindex all database contents. This method is "smart"
|
||||
* in that it determines which indexing consumer(s) you have enabled,
|
||||
@@ -104,8 +106,74 @@ public class DatabaseLegacyReindexer implements KernelStartupCallbackService
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void executeCallback() {
|
||||
public void beforeClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMigrate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMigrate(Connection connection) {
|
||||
reindex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInfo(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInfo(Connection connection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,15 +8,16 @@
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
|
||||
import org.dspace.administer.MetadataImporter;
|
||||
import org.dspace.administer.RegistryLoader;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.services.KernelStartupCallbackService;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* This is a FlywayCallback class which automatically updates the
|
||||
@@ -33,14 +34,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*
|
||||
* @author Tim Donohue
|
||||
*/
|
||||
public class DatabaseRegistryUpdater implements KernelStartupCallbackService
|
||||
public class DatabaseRegistryUpdater implements FlywayCallback
|
||||
{
|
||||
/** logging category */
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseRegistryUpdater.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
protected GroupService groupService;
|
||||
|
||||
/**
|
||||
* Method to actually update our registries from latest configs
|
||||
*/
|
||||
@@ -93,8 +91,72 @@ public class DatabaseRegistryUpdater implements KernelStartupCallbackService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCallback()
|
||||
{
|
||||
public void beforeClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMigrate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMigrate(Connection connection) {
|
||||
updateRegistries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInfo(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInfo(Connection connection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -17,19 +17,22 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.DBConnection;
|
||||
import org.dspace.discovery.IndexingService;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.utils.DSpace;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.FlywayException;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.flywaydb.core.internal.dbsupport.DbSupport;
|
||||
import org.flywaydb.core.internal.dbsupport.DbSupportFactory;
|
||||
import org.flywaydb.core.internal.dbsupport.SqlScript;
|
||||
@@ -43,7 +46,7 @@ import org.flywaydb.core.internal.info.MigrationInfoDumper;
|
||||
* <p>
|
||||
* Currently, we use Flyway DB (http://flywaydb.org/) for database management.
|
||||
*
|
||||
* @see org.dspace.storage.rdbms.DatabaseManager
|
||||
* @see org.dspace.storage.rdbms.DatabaseUtils
|
||||
* @author Tim Donohue
|
||||
*/
|
||||
public class DatabaseUtils
|
||||
@@ -87,21 +90,40 @@ public class DatabaseUtils
|
||||
// Call initDataSource to JUST initialize the dataSource WITHOUT fully
|
||||
// initializing the DatabaseManager itself. This ensures we do NOT
|
||||
// immediately run our Flyway DB migrations on this database
|
||||
DBConnection dbConnection = new DSpace().getSingletonService(DBConnection.class);
|
||||
DataSource dataSource = dbConnection.getDataSource();
|
||||
DatabaseConfigVO databaseConfig = dbConnection.getDatabaseConfig();
|
||||
DataSource dataSource = new DSpace().getServiceManager().getServiceByName("dataSource", BasicDataSource.class);
|
||||
|
||||
// Get configured DB URL for reporting below
|
||||
String url = databaseConfig.getDatabaseUrl();
|
||||
|
||||
|
||||
|
||||
// Point Flyway API to our database
|
||||
Flyway flyway = setupFlyway(dataSource);
|
||||
|
||||
if(argv[0].equalsIgnoreCase("migrate"))
|
||||
// "test" = Test Database Connection
|
||||
if(argv[0].equalsIgnoreCase("test"))
|
||||
{
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
|
||||
|
||||
// Try to connect to the database
|
||||
System.out.println("\nAttempting to connect to database");
|
||||
try
|
||||
{
|
||||
// Just do a high level test by getting our configured DataSource and attempting to connect to it
|
||||
Connection connection = dataSource.getConnection();
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
System.out.println("Connected successfully!");
|
||||
System.out.println("Database Software: " + meta.getDatabaseProductName() + " version " + meta.getDatabaseProductVersion());
|
||||
System.out.println(" - URL: " + meta.getURL());
|
||||
System.out.println(" - Driver: " + meta.getDriverName() + " version " + meta.getDriverVersion());
|
||||
System.out.println(" - Username: " + meta.getUserName());
|
||||
System.out.println(" - Password: [hidden]");
|
||||
System.out.println(" - Schema: " + getSchemaName(connection));
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
System.err.println("\nError: ");
|
||||
System.err.println(" - " + sqle);
|
||||
System.err.println("\nPlease see the DSpace documentation for assistance.\n");
|
||||
System.exit(1);
|
||||
}
|
||||
}else
|
||||
if(argv[0].equalsIgnoreCase("info"))
|
||||
@@ -109,7 +131,7 @@ public class DatabaseUtils
|
||||
// Get basic Database info
|
||||
Connection connection = dataSource.getConnection();
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
System.out.println("\nDatabase URL: " + url);
|
||||
System.out.println("\nDatabase URL: " + meta.getURL());
|
||||
System.out.println("Database Schema: " + getSchemaName(connection));
|
||||
System.out.println("Database Software: " + meta.getDatabaseProductName() + " version " + meta.getDatabaseProductVersion());
|
||||
System.out.println("Database Driver: " + meta.getDriverName() + " version " + meta.getDriverVersion());
|
||||
@@ -134,10 +156,56 @@ public class DatabaseUtils
|
||||
}
|
||||
connection.close();
|
||||
}
|
||||
else if(argv[0].equalsIgnoreCase("migrate"))
|
||||
{
|
||||
try (Connection connection = dataSource.getConnection();){
|
||||
System.out.println("\nDatabase URL: " + connection.getMetaData().getURL());
|
||||
}
|
||||
|
||||
// "migrate" allows for an OPTIONAL second argument:
|
||||
// - "ignored" = Also run any previously "ignored" migrations during the migration
|
||||
// - [version] = ONLY run migrations up to a specific DSpace version (ONLY FOR TESTING)
|
||||
if(argv.length==2)
|
||||
{
|
||||
if(argv[1].equalsIgnoreCase("ignored"))
|
||||
{
|
||||
System.out.println("Migrating database to latest version AND running previously \"Ignored\" migrations... (Check logs for details)");
|
||||
Connection connection = dataSource.getConnection();
|
||||
// Update the database to latest version, but set "outOfOrder=true"
|
||||
// This will ensure any old migrations in the "ignored" state are now run
|
||||
updateDatabase(dataSource, connection, null, true);
|
||||
connection.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, we assume "argv[1]" is a valid migration version number
|
||||
// This is only for testing! Never specify for Production!
|
||||
System.out.println("Migrating database ONLY to version " + argv[1] + " ... (Check logs for details)");
|
||||
System.out.println("\nWARNING: It is highly likely you will see errors in your logs when the Metadata");
|
||||
System.out.println("or Bitstream Format Registry auto-update. This is because you are attempting to");
|
||||
System.out.println("use an OLD version " + argv[1] + " Database with a newer DSpace API. NEVER do this in a");
|
||||
System.out.println("PRODUCTION scenario. The resulting old DB is only useful for migration testing.\n");
|
||||
Connection connection = dataSource.getConnection();
|
||||
// Update the database, to the version specified.
|
||||
updateDatabase(dataSource, connection, argv[1], false);
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Migrating database to latest version... (Check logs for details)");
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
updateDatabase(dataSource, connection);
|
||||
}
|
||||
}
|
||||
System.out.println("Done.");
|
||||
}
|
||||
// "repair" = Run Flyway repair script
|
||||
else if(argv[0].equalsIgnoreCase("repair"))
|
||||
{
|
||||
System.out.println("\nDatabase URL: " + url);
|
||||
try (Connection connection = dataSource.getConnection();){
|
||||
System.out.println("\nDatabase URL: " + connection.getMetaData().getURL());
|
||||
}
|
||||
System.out.println("Attempting to repair any previously failed migrations via FlywayDB... (Check logs for details)");
|
||||
flyway.repair();
|
||||
System.out.println("Done.");
|
||||
@@ -146,7 +214,9 @@ public class DatabaseUtils
|
||||
else if(argv[0].equalsIgnoreCase("clean"))
|
||||
{
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
|
||||
System.out.println("\nDatabase URL: " + url);
|
||||
try (Connection connection = dataSource.getConnection();){
|
||||
System.out.println("\nDatabase URL: " + connection.getMetaData().getURL());
|
||||
}
|
||||
System.out.println("\nWARNING: ALL DATA AND TABLES IN YOUR DATABASE WILL BE PERMANENTLY DELETED.\n");
|
||||
System.out.println("There is NO turning back from this action. Backup your DB before continuing.");
|
||||
System.out.println("If you are using Oracle, your RECYCLEBIN will also be PURGED.\n");
|
||||
@@ -172,7 +242,6 @@ public class DatabaseUtils
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -235,10 +304,25 @@ public class DatabaseUtils
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.xmlworkflow");
|
||||
}
|
||||
|
||||
|
||||
//We cannot request services at this point, so we will have to do it the old fashioned way
|
||||
if (ConfigurationManager.getProperty("workflow", "workflow.framework").equals("xmlworkflow"))
|
||||
{
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration.workflow." + dbType + ".xmlworkflow");
|
||||
}else{
|
||||
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration.workflow." + dbType + ".basicWorkflow");
|
||||
}
|
||||
|
||||
// Now tell Flyway which locations to load SQL / Java migrations from
|
||||
log.info("Loading Flyway DB migrations from: " + StringUtils.join(scriptLocations, ", "));
|
||||
flywaydb.setLocations(scriptLocations.toArray(new String[scriptLocations.size()]));
|
||||
|
||||
// Set flyway callbacks (i.e. classes which are called post-DB migration and similar)
|
||||
// In this situation, we have a Registry Updater that runs PRE-migration
|
||||
// NOTE: DatabaseLegacyReindexer only indexes in Legacy Lucene & RDBMS indexes. It can be removed once those are obsolete.
|
||||
List<FlywayCallback> flywayCallbacks = new DSpace().getServiceManager().getServicesByType(FlywayCallback.class);
|
||||
flywaydb.setCallbacks(flywayCallbacks.toArray(new FlywayCallback[flywayCallbacks.size()]));
|
||||
|
||||
// Set flyway callbacks (i.e. classes which are called post-DB migration and similar)
|
||||
// In this situation, we have a Registry Updater that runs PRE-migration
|
||||
// NOTE: DatabaseLegacyReindexer only indexes in Legacy Lucene & RDBMS indexes. It can be removed once those are obsolete.
|
||||
@@ -440,8 +524,6 @@ public class DatabaseUtils
|
||||
*
|
||||
* @param connection
|
||||
* Current Database Connection
|
||||
* @param flyway
|
||||
* Our Flyway settings
|
||||
* @throws SQLException if DB status cannot be determined
|
||||
* @return DSpace version as a String (e.g. "4.0"), or null if database is empty
|
||||
*/
|
||||
@@ -977,7 +1059,7 @@ public class DatabaseUtils
|
||||
|
||||
/**
|
||||
* Constructor. Pass it an existing IndexingService
|
||||
* @param indexer
|
||||
* @param is
|
||||
*/
|
||||
ReindexerThread(IndexingService is)
|
||||
{
|
||||
|
@@ -9,24 +9,27 @@ package org.dspace.storage.rdbms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.services.KernelStartupCallbackService;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* Callback method to ensure that the default groups are created each time a kernel is created.
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public class GroupServiceInitializer implements KernelStartupCallbackService {
|
||||
public class GroupServiceInitializer implements FlywayCallback {
|
||||
|
||||
private final Logger log = Logger.getLogger(GroupServiceInitializer.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
protected GroupService groupService;
|
||||
|
||||
@Override
|
||||
public void executeCallback() {
|
||||
public void initGroups() {
|
||||
// After every migrate, ensure default Groups are setup correctly.
|
||||
Context context = null;
|
||||
try
|
||||
@@ -53,4 +56,74 @@ public class GroupServiceInitializer implements KernelStartupCallbackService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMigrate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMigrate(Connection connection) {
|
||||
initGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInfo(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInfo(Connection connection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,25 +8,29 @@
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.SiteService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.services.KernelStartupCallbackService;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* Callback method to ensure that the Site is created (if no site exists) each time a kernel is created.
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public class SiteServiceInitializer implements KernelStartupCallbackService {
|
||||
public class SiteServiceInitializer implements FlywayCallback {
|
||||
|
||||
private Logger log = Logger.getLogger(SiteServiceInitializer.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
protected SiteService siteService;
|
||||
|
||||
@Override
|
||||
public void executeCallback() {
|
||||
public void initializeSiteObject() {
|
||||
// After every migrate, ensure default Site is setup correctly.
|
||||
Context context = null;
|
||||
try
|
||||
@@ -55,5 +59,75 @@ public class SiteServiceInitializer implements KernelStartupCallbackService {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterClean(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMigrate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMigrate(Connection connection) {
|
||||
initializeSiteObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEachMigrate(Connection connection, MigrationInfo migrationInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterValidate(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInit(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRepair(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInfo(Connection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInfo(Connection connection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1 +0,0 @@
|
||||
org.dspace.core.HibernateFlywayIntegrator
|
@@ -33,7 +33,7 @@
|
||||
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
|
||||
</bean>
|
||||
|
||||
<bean name="org.dspace.core.DBConnection" class="org.dspace.core.HibernateDBConnection"/>
|
||||
<bean name="org.dspace.core.DBConnection" class="org.dspace.core.HibernateDBConnection" lazy-init="true"/>
|
||||
|
||||
<bean class="org.dspace.storage.rdbms.DatabaseLegacyReindexer"/>
|
||||
<bean class="org.dspace.storage.rdbms.DatabaseRegistryUpdater"/>
|
||||
|
@@ -3,7 +3,18 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" lazy-init="true">
|
||||
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true" destroy-method="close">
|
||||
<property name="driverClassName" value="org.h2.Driver"/>
|
||||
<property name="url" value="jdbc:h2:mem:test;LOCK_TIMEOUT=10000;MVCC=true"/>
|
||||
<property name="username" value="sa"/>
|
||||
<property name="password" value=""/>
|
||||
</bean>
|
||||
|
||||
<bean name="org.dspace.core.DBConnection" class="org.dspace.core.HibernateDBConnection" lazy-init="true"/>
|
||||
|
||||
</beans>
|
@@ -29,6 +29,7 @@ import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.EPersonService;
|
||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||
import org.dspace.servicemanager.DSpaceKernelInit;
|
||||
import org.dspace.storage.rdbms.DatabaseUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -108,6 +109,8 @@ public class AbstractUnitTest
|
||||
{
|
||||
kernelImpl.start(ConfigurationManager.getProperty("dspace.dir"));
|
||||
}
|
||||
//Migrate & setup our database
|
||||
DatabaseUtils.main(new String[]{"migrate"});
|
||||
|
||||
// Initialize mock indexer (which does nothing, since Solr isn't running)
|
||||
new MockIndexEventConsumer();
|
||||
|
@@ -1 +0,0 @@
|
||||
org.dspace.core.HibernateFlywayIntegrator
|
@@ -5,11 +5,7 @@
|
||||
<session-factory>
|
||||
|
||||
|
||||
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||
<property name="hibernate.connection.url">jdbc:h2:mem:test;LOCK_TIMEOUT=10000;MVCC=true</property>
|
||||
<property name="hibernate.connection.username">sa</property>
|
||||
<property name="hibernate.connection.password"></property>
|
||||
|
||||
|
||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||
@@ -17,12 +13,23 @@
|
||||
|
||||
|
||||
<!--<property name="hibernate.default_schema"></property>-->
|
||||
<property name="hibernate.connection.pool_size">10</property>
|
||||
<property name="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor</property>
|
||||
<property name="hibernate.connection.autocommit">false</property>
|
||||
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
|
||||
|
||||
|
||||
|
||||
<!--Connection pool parameters -->
|
||||
<!-- Maximum number of DB connections in pool -->
|
||||
<property name="hibernate.c3p0.max_size">30</property>
|
||||
<!-- Determine the number of statements to be cached. -->
|
||||
<property name="hibernate.c3p0.max_statements">50</property>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!--Debug property that can be used to display the sql-->
|
||||
<property name="show_sql">false</property>
|
||||
|
||||
|
||||
|
@@ -4,9 +4,7 @@
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
|
||||
<property name="hibernate.connection.driver_class">${db.driver}</property>
|
||||
<property name="hibernate.dialect">${db.dialect}</property>
|
||||
<property name="hibernate.connection.url">${db.url}</property>
|
||||
<!--
|
||||
Schema name - if your database contains multiple schemas, you can avoid
|
||||
problems with retrieving the definitions of duplicate object names by
|
||||
@@ -16,8 +14,6 @@
|
||||
UNLESS your Oracle DB Account (in db.username) has access to multiple schemas.
|
||||
-->
|
||||
<property name="hibernate.default_schema">${db.schema}</property>
|
||||
<property name="hibernate.connection.username">${db.username}</property>
|
||||
<property name="hibernate.connection.password">${db.password}</property>
|
||||
<property name="hibernate.hbm2ddl.auto">validate</property>
|
||||
<property name="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor</property>
|
||||
<property name="hibernate.connection.autocommit">false</property>
|
||||
|
@@ -3,7 +3,16 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" lazy-init="true">
|
||||
<property name="configLocation" value="file:${dspace.dir}/config/hibernate.cfg.xml"/>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true" destroy-method="close">
|
||||
<property name="driverClassName" value="${db.driver}"/>
|
||||
<property name="url" value="${db.url}"/>
|
||||
<property name="username" value="${db.username}"/>
|
||||
<property name="password" value="${db.password}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -59,6 +59,7 @@
|
||||
<exclude>config/hibernate.cfg.xml</exclude>
|
||||
<exclude>config/log4j.properties</exclude>
|
||||
<exclude>config/modules/**</exclude>
|
||||
<exclude>config/spring/**</exclude>
|
||||
</excludes>
|
||||
</fileSet>
|
||||
<!-- Copy over all module configs & filter them -->
|
||||
@@ -66,6 +67,7 @@
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<includes>
|
||||
<include>config/modules/**</include>
|
||||
<include>config/spring/**</include>
|
||||
<include>config/hibernate.cfg.xml</include>
|
||||
</includes>
|
||||
<filtered>true</filtered>
|
||||
|
@@ -789,6 +789,16 @@ Common usage:
|
||||
<!-- ============================================================= -->
|
||||
|
||||
<!-- Test the connection to the database -->
|
||||
<target name="test_database">
|
||||
<java classname="org.dspace.app.launcher.ScriptLauncher" classpathref="class.path" fork="yes" failonerror="yes">
|
||||
<sysproperty key="log4j.configuration" value="file:config/log4j-console.properties" />
|
||||
<sysproperty key="dspace.log.init.disable" value="true" />
|
||||
<sysproperty key="dspace.configuration" value="${config}" />
|
||||
<arg value="database" />
|
||||
<arg value="test" />
|
||||
</java>
|
||||
</target>
|
||||
<!-- Migrate the database -->
|
||||
<target name="migrate_database">
|
||||
<java classname="org.dspace.app.launcher.ScriptLauncher" classpathref="class.path" fork="yes" failonerror="yes">
|
||||
<sysproperty key="log4j.configuration" value="file:config/log4j-console.properties" />
|
||||
@@ -855,7 +865,7 @@ Common usage:
|
||||
<!-- ============================================================= -->
|
||||
|
||||
<target name="fresh_install"
|
||||
depends="init_installation,init_configs,migrate_database,install_code"
|
||||
depends="init_installation,init_configs,test_database,migrate_database,install_code"
|
||||
description="Do a fresh install of the system, overwriting any data">
|
||||
|
||||
<delete failonerror="no">
|
||||
|
Reference in New Issue
Block a user