From 0883d138a4a526069566eaba0d5a64a3393c5f53 Mon Sep 17 00:00:00 2001 From: KevinVdV Date: Fri, 21 Aug 2015 15:32:05 +0200 Subject: [PATCH] [DS-2712] Fix DatabaseUtils class, migration issues and altered the ant update fresh_install scripts to migrate database --- build.properties | 2 +- .../org/dspace/authorize/ResourcePolicy.java | 2 + .../main/java/org/dspace/core/Context.java | 7 ++ .../java/org/dspace/core/DBConnection.java | 7 ++ .../dspace/core/HibernateDBConnection.java | 24 +++++ .../storage/rdbms/DatabaseConfigVO.java | 73 +++++++++++++++ .../dspace/storage/rdbms/DatabaseUtils.java | 89 +++---------------- ...ct.java => DSpacePostgreSQL82Dialect.java} | 9 +- ...tial_DSpace_1.2_Oracle_database_schema.sql | 28 +++--- .../h2/V1.4__Upgrade_to_DSpace_1.4_schema.sql | 8 +- .../h2/V1.5__Upgrade_to_DSpace_1.5_schema.sql | 4 +- .../h2/V3.0__Upgrade_to_DSpace_3.x_schema.sql | 2 +- .../h2/V4.0__Upgrade_to_DSpace_4.x_schema.sql | 6 +- .../V6.0_2015.03.07__hibernate_migration.sql | 16 ++++ .../V6.0_2015.03.07__hibernate_migration.sql | 16 +++- .../src/test/resources/hibernate.cfg.xml | 5 -- dspace-services/pom.xml | 2 +- .../aspect/administrative/ControlPanel.java | 19 ++-- dspace/config/hibernate.cfg.xml | 2 +- dspace/src/main/config/build.xml | 13 +-- pom.xml | 26 +++--- 21 files changed, 216 insertions(+), 144 deletions(-) create mode 100644 dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseConfigVO.java rename dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/{DSpacePostgreSQL9Dialect.java => DSpacePostgreSQL82Dialect.java} (82%) diff --git a/build.properties b/build.properties index b48840a6e0..856a2a5fc4 100644 --- a/build.properties +++ b/build.properties @@ -56,7 +56,7 @@ default.language = en_US # Uncomment the appropriate block below for your database. # postgres db.driver=org.postgresql.Driver -db.dialect=org.dspace.storage.rdbms.hibernate.postgres.DSpacePostgreSQL9Dialect +db.dialect=org.dspace.storage.rdbms.hibernate.postgres.DSpacePostgreSQL82Dialect db.url=jdbc:postgresql://localhost:5432/dspace db.username=dspace db.password=dspace diff --git a/dspace-api/src/main/java/org/dspace/authorize/ResourcePolicy.java b/dspace-api/src/main/java/org/dspace/authorize/ResourcePolicy.java index e65510e1c2..45b0578660 100644 --- a/dspace-api/src/main/java/org/dspace/authorize/ResourcePolicy.java +++ b/dspace-api/src/main/java/org/dspace/authorize/ResourcePolicy.java @@ -55,9 +55,11 @@ public class ResourcePolicy{ private Group epersonGroup; @Column(name="start_date") + @Temporal(TemporalType.DATE) private Date startDate; @Column(name="end_date") + @Temporal(TemporalType.DATE) private Date endDate; @Column(name="rpname", length = 30) diff --git a/dspace-api/src/main/java/org/dspace/core/Context.java b/dspace-api/src/main/java/org/dspace/core/Context.java index f6c2be73be..d228c5f34a 100644 --- a/dspace-api/src/main/java/org/dspace/core/Context.java +++ b/dspace-api/src/main/java/org/dspace/core/Context.java @@ -18,6 +18,7 @@ import org.dspace.event.Dispatcher; import org.dspace.event.Event; import org.dspace.event.factory.EventServiceFactory; import org.dspace.event.service.EventService; +import org.dspace.storage.rdbms.DatabaseConfigVO; import org.dspace.utils.DSpace; import org.springframework.util.CollectionUtils; @@ -153,6 +154,12 @@ public class Context return dbConnection; } + + public DatabaseConfigVO getDBConfig() throws SQLException + { + return dbConnection.getDatabaseConfig(); + } + public String getDbType(){ return dbConnection.getType(); } diff --git a/dspace-api/src/main/java/org/dspace/core/DBConnection.java b/dspace-api/src/main/java/org/dspace/core/DBConnection.java index fbb04cd8fd..163fa9ab02 100644 --- a/dspace-api/src/main/java/org/dspace/core/DBConnection.java +++ b/dspace-api/src/main/java/org/dspace/core/DBConnection.java @@ -7,6 +7,9 @@ */ package org.dspace.core; +import org.dspace.storage.rdbms.DatabaseConfigVO; + +import javax.sql.DataSource; import java.sql.SQLException; /** @@ -31,4 +34,8 @@ public interface DBConnection { public void shutdown(); public String getType(); + + public DataSource getDataSource(); + + public DatabaseConfigVO getDatabaseConfig() throws SQLException; } \ No newline at end of file diff --git a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java index 18174d8ed8..d6e226dac8 100644 --- a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java +++ b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java @@ -7,13 +7,18 @@ */ package org.dspace.core; +import org.dspace.storage.rdbms.DatabaseConfigVO; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.orm.hibernate4.SessionFactoryUtils; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.DatabaseMetaData; import java.sql.SQLException; /** @@ -83,4 +88,23 @@ public class HibernateDBConnection implements DBConnection { return ((SessionFactoryImplementor) sessionFactory).getDialect().toString(); } + @Override + public DataSource getDataSource() { + return SessionFactoryUtils.getDataSource(sessionFactory); + } + + @Override + public DatabaseConfigVO getDatabaseConfig() throws SQLException { + DatabaseConfigVO databaseConfigVO = new DatabaseConfigVO(); + + try (Connection connection = getDataSource().getConnection()) { + DatabaseMetaData metaData = connection.getMetaData(); + databaseConfigVO.setDatabaseDriver(metaData.getDriverName()); + databaseConfigVO.setDatabaseUrl(metaData.getURL()); + databaseConfigVO.setSchema(metaData.getSchemaTerm()); + databaseConfigVO.setMaxConnections(metaData.getMaxConnections()); + databaseConfigVO.setUserName(metaData.getUserName()); + } + return databaseConfigVO; + } } \ No newline at end of file diff --git a/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseConfigVO.java b/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseConfigVO.java new file mode 100644 index 0000000000..89177b99d2 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseConfigVO.java @@ -0,0 +1,73 @@ +/** + * 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.storage.rdbms; + +/** + * Value object for the Database configuration, can be used to get the database configuration parameters. + * The config parameters are retrieved by the implementation of the org.dspace.core.DBConnection object. + * This class should never be used to store configuration, it is just used to export & can be used for display purposes + * + * @author kevinvandevelde at atmire.com + */ +public class DatabaseConfigVO { + + private String databaseUrl; + + private String databaseDriver; + + private String userName; + + private String schema; + + private int maxConnections; + + public DatabaseConfigVO() + { + + } + + public String getDatabaseUrl() { + return databaseUrl; + } + + public void setDatabaseUrl(String databaseUrl) { + this.databaseUrl = databaseUrl; + } + + public String getDatabaseDriver() { + return databaseDriver; + } + + public void setDatabaseDriver(String databaseDriver) { + this.databaseDriver = databaseDriver; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public int getMaxConnections() { + return maxConnections; + } + + public void setMaxConnections(int maxConnections) { + this.maxConnections = maxConnections; + } +} diff --git a/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseUtils.java b/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseUtils.java index 6f490e871d..ec03b82250 100644 --- a/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseUtils.java +++ b/dspace-api/src/main/java/org/dspace/storage/rdbms/DatabaseUtils.java @@ -87,46 +87,24 @@ 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 - //TODO: HIBERNATE FIX FLYWAY - DataSource dataSource = null; //DatabaseManager.initDataSource(); + DBConnection dbConnection = new DSpace().getSingletonService(DBConnection.class); + DataSource dataSource = dbConnection.getDataSource(); + DatabaseConfigVO databaseConfig = dbConnection.getDatabaseConfig(); // Get configured DB URL for reporting below - String url = ConfigurationManager.getProperty("db.url"); + String url = databaseConfig.getDatabaseUrl(); + + // Point Flyway API to our database Flyway flyway = setupFlyway(dataSource); - // "test" = Test Database Connection - if(argv[0].equalsIgnoreCase("test")) + if(argv[0].equalsIgnoreCase("migrate")) { - // Try to connect to the database - System.out.println("\nAttempting to connect to database using these configurations: "); - System.out.println(" - URL: " + url); - System.out.println(" - Driver: " + ConfigurationManager.getProperty("db.driver")); - System.out.println(" - Username: " + ConfigurationManager.getProperty("db.username")); - System.out.println(" - Password: [hidden]"); - System.out.println(" - Schema: " + ConfigurationManager.getProperty("db.schema")); - System.out.println("\nTesting connection..."); - try - { - // Just do a high level test by getting our configured DataSource and attempting to connect to it - // NOTE: We specifically do NOT call DatabaseManager.getConnection() because that will attempt - // a full initialization of DatabaseManager & also cause database migrations/upgrades to occur - Connection connection = dataSource.getConnection(); - connection.close(); + try (Connection connection = dataSource.getConnection()) { } - 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); - } - - System.out.println("Connected successfully!\n"); - } - // "info" = Basic Database Information - else if(argv[0].equalsIgnoreCase("info")) + }else + if(argv[0].equalsIgnoreCase("info")) { // Get basic Database info Connection connection = dataSource.getConnection(); @@ -156,51 +134,6 @@ public class DatabaseUtils } connection.close(); } - // "migrate" = Manually run any outstanding Database migrations (if any) - else if(argv[0].equalsIgnoreCase("migrate")) - { - System.out.println("\nDatabase URL: " + url); - - // "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)"); - // NOTE: This looks odd, but all we really need to do is ensure the - // DatabaseManager auto-initializes. It'll take care of the migration itself. - // Asking for our DB Name will ensure DatabaseManager.initialize() is called. - //TODO: HIBERNATE FIX FLYWAY -// DatabaseManager.getDbName(); - } - System.out.println("Done."); - } // "repair" = Run Flyway repair script else if(argv[0].equalsIgnoreCase("repair")) { @@ -232,10 +165,8 @@ public class DatabaseUtils { System.out.println("\nUsage: database [action]"); System.out.println("Valid actions: 'test', 'info', 'migrate', 'repair' or 'clean'"); - System.out.println(" - test = Test database connection is OK"); System.out.println(" - info = Describe basic info about database, including migrations run"); System.out.println(" - migrate = Migrate the Database to the latest version"); - System.out.println(" Optionally, specify \"ignored\" to also run \"Ignored\" migrations"); System.out.println(" - repair = Attempt to repair any previously failed database migrations"); System.out.println(" - clean = DESTROY all data and tables in Database (WARNING there is no going back!)"); System.out.println(""); diff --git a/dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL9Dialect.java b/dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL82Dialect.java similarity index 82% rename from dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL9Dialect.java rename to dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL82Dialect.java index 766955628d..7c93b535f2 100644 --- a/dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL9Dialect.java +++ b/dspace-api/src/main/java/org/dspace/storage/rdbms/hibernate/postgres/DSpacePostgreSQL82Dialect.java @@ -7,7 +7,7 @@ */ package org.dspace.storage.rdbms.hibernate.postgres; -import org.hibernate.dialect.PostgreSQL9Dialect; +import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.metamodel.spi.TypeContributions; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.PostgresUUIDType; @@ -18,7 +18,7 @@ import org.hibernate.type.PostgresUUIDType; * * @author kevinvandevelde at atmire.com */ -public class DSpacePostgreSQL9Dialect extends PostgreSQL9Dialect +public class DSpacePostgreSQL82Dialect extends PostgreSQL82Dialect { @Override public void contributeTypes(final TypeContributions typeContributions, final ServiceRegistry serviceRegistry) { @@ -26,6 +26,11 @@ public class DSpacePostgreSQL9Dialect extends PostgreSQL9Dialect typeContributions.contributeType(new InternalPostgresUUIDType()); } + @Override + protected void registerHibernateType(int code, String name) { + super.registerHibernateType(code, name); + } + protected static class InternalPostgresUUIDType extends PostgresUUIDType { @Override diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.2__Initial_DSpace_1.2_Oracle_database_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.2__Initial_DSpace_1.2_Oracle_database_schema.sql index 957a6e8092..d573b3d47b 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.2__Initial_DSpace_1.2_Oracle_database_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.2__Initial_DSpace_1.2_Oracle_database_schema.sql @@ -59,7 +59,7 @@ CREATE TABLE BitstreamFormatRegistry description VARCHAR2(2000), support_level INTEGER, -- Identifies internal types - internal NUMBER(1) + internal BOOLEAN ); ------------------------------------------------------- @@ -80,14 +80,14 @@ CREATE TABLE Bitstream bitstream_id INTEGER PRIMARY KEY, bitstream_format_id INTEGER REFERENCES BitstreamFormatRegistry(bitstream_format_id), name VARCHAR2(256), - size_bytes INTEGER, + size_bytes BIGINT, checksum VARCHAR2(64), checksum_algorithm VARCHAR2(32), description VARCHAR2(2000), user_format_description VARCHAR2(2000), source VARCHAR2(256), internal_id VARCHAR2(256), - deleted NUMBER(1), + deleted BOOLEAN, store_number INTEGER, sequence_id INTEGER ); @@ -102,9 +102,9 @@ CREATE TABLE EPerson password VARCHAR2(64), firstname VARCHAR2(64), lastname VARCHAR2(64), - can_log_in NUMBER(1), - require_certificate NUMBER(1), - self_registered NUMBER(1), + can_log_in BOOLEAN, + require_certificate BOOLEAN, + self_registered BOOLEAN, last_active TIMESTAMP, sub_frequency INTEGER, phone VARCHAR2(32) @@ -129,8 +129,8 @@ CREATE TABLE Item ( item_id INTEGER PRIMARY KEY, submitter_id INTEGER REFERENCES EPerson(eperson_id), - in_archive NUMBER(1), - withdrawn NUMBER(1), + in_archive BOOLEAN, + withdrawn BOOLEAN, last_modified TIMESTAMP, owning_collection INTEGER ); @@ -326,9 +326,9 @@ CREATE TABLE WorkspaceItem item_id INTEGER REFERENCES Item(item_id), collection_id INTEGER REFERENCES Collection(collection_id), -- Answers to questions on first page of submit UI - multiple_titles NUMBER(1), -- boolean - published_before NUMBER(1), - multiple_files NUMBER(1), + multiple_titles BOOLEAN, -- boolean + published_before BOOLEAN, + multiple_files BOOLEAN, -- How for the user has got in the submit process stage_reached INTEGER ); @@ -345,9 +345,9 @@ CREATE TABLE WorkflowItem owner INTEGER REFERENCES EPerson(eperson_id), -- Answers to questions on first page of submit UI - multiple_titles NUMBER(1), - published_before NUMBER(1), - multiple_files NUMBER(1) + multiple_titles BOOLEAN, + published_before BOOLEAN, + multiple_files BOOLEAN -- Note: stage reached not applicable here - people involved in workflow -- can always jump around submission UI diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.4__Upgrade_to_DSpace_1.4_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.4__Upgrade_to_DSpace_1.4_schema.sql index 15847b7a18..e00a651626 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.4__Upgrade_to_DSpace_1.4_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.4__Upgrade_to_DSpace_1.4_schema.sql @@ -136,13 +136,13 @@ CREATE TABLE checksum_results CREATE TABLE most_recent_checksum ( bitstream_id INTEGER PRIMARY KEY, - to_be_processed NUMBER(1) NOT NULL, + to_be_processed BOOLEAN NOT NULL, expected_checksum VARCHAR(64) NOT NULL, current_checksum VARCHAR(64) NOT NULL, last_process_start_date TIMESTAMP NOT NULL, last_process_end_date TIMESTAMP NOT NULL, checksum_algorithm VARCHAR(64) NOT NULL, - matched_prev_checksum NUMBER(1) NOT NULL, + matched_prev_checksum BOOLEAN NOT NULL, result VARCHAR(64) REFERENCES checksum_results(result_code) ); @@ -150,11 +150,11 @@ CREATE TABLE most_recent_checksum -- A row will be inserted into this table every -- time a checksum is re-calculated. -CREATE SEQUENCE checksum_history_seq; +CREATE SEQUENCE checksum_history_check_id_seq; CREATE TABLE checksum_history ( - check_id INTEGER PRIMARY KEY, + check_id BIGINT PRIMARY KEY, bitstream_id INTEGER, process_start_date TIMESTAMP, process_end_date TIMESTAMP, diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.5__Upgrade_to_DSpace_1.5_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.5__Upgrade_to_DSpace_1.5_schema.sql index 8b874d2aac..7f5a5ccf0a 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.5__Upgrade_to_DSpace_1.5_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V1.5__Upgrade_to_DSpace_1.5_schema.sql @@ -15,8 +15,8 @@ -- =============================================================== -- Remove NOT NULL restrictions from the checksum columns of most_recent_checksum -ALTER TABLE most_recent_checksum MODIFY expected_checksum null; -ALTER TABLE most_recent_checksum MODIFY current_checksum null; +ALTER TABLE most_recent_checksum ALTER COLUMN expected_checksum SET NOT NULL; +ALTER TABLE most_recent_checksum ALTER COLUMN current_checksum SET NOT NULL; ------------------------------------------------------ -- New Column language language in EPerson diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V3.0__Upgrade_to_DSpace_3.x_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V3.0__Upgrade_to_DSpace_3.x_schema.sql index 51ed63639c..29d6a4ffa7 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V3.0__Upgrade_to_DSpace_3.x_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V3.0__Upgrade_to_DSpace_3.x_schema.sql @@ -19,7 +19,7 @@ ALTER TABLE resourcepolicy ADD COLUMN rptype VARCHAR2(30); ALTER TABLE resourcepolicy ADD COLUMN rpdescription VARCHAR2(100); -ALTER TABLE item ADD COLUMN discoverable NUMBER(1); +ALTER TABLE item ADD COLUMN discoverable BOOLEAN; CREATE TABLE versionhistory ( diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V4.0__Upgrade_to_DSpace_4.x_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V4.0__Upgrade_to_DSpace_4.x_schema.sql index 8102376906..de425741f9 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V4.0__Upgrade_to_DSpace_4.x_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V4.0__Upgrade_to_DSpace_4.x_schema.sql @@ -47,7 +47,7 @@ CREATE TABLE Webapp AppName VARCHAR2(32), URL VARCHAR2(1000), Started TIMESTAMP, - isUI NUMBER(1) + isUI INTEGER ); CREATE SEQUENCE webapp_seq; @@ -62,11 +62,11 @@ CREATE TABLE requestitem token varchar(48), item_id INTEGER, bitstream_id INTEGER, - allfiles NUMBER(1), + allfiles BOOLEAN, request_email VARCHAR2(64), request_name VARCHAR2(64), request_date TIMESTAMP, - accept_request NUMBER(1), + accept_request BOOLEAN, decision_date TIMESTAMP, expires TIMESTAMP, CONSTRAINT requestitem_pkey PRIMARY KEY (requestitem_id), diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__hibernate_migration.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__hibernate_migration.sql index 03f8939a18..91af0a1a6b 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__hibernate_migration.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__hibernate_migration.sql @@ -384,3 +384,19 @@ ALTER TABLE most_recent_checksum ADD COLUMN bitstream_id UUID; ALTER TABLE most_recent_checksum ADD CONSTRAINT most_recent_checksum_bitstream_id_fk FOREIGN KEY (bitstream_id) REFERENCES Bitstream; UPDATE most_recent_checksum SET bitstream_id = (SELECT Bitstream.uuid FROM Bitstream WHERE most_recent_checksum.bitstream_legacy_id = Bitstream.bitstream_id); ALTER TABLE most_recent_checksum DROP COLUMN bitstream_legacy_id; + +ALTER TABLE checksum_history ALTER COLUMN bitstream_id rename to bitstream_legacy_id; +ALTER TABLE checksum_history ADD COLUMN bitstream_id UUID; +ALTER TABLE checksum_history ADD CONSTRAINT checksum_history_id_fk FOREIGN KEY (bitstream_id) REFERENCES Bitstream; +UPDATE checksum_history SET bitstream_id = (SELECT Bitstream.uuid FROM Bitstream WHERE checksum_history.bitstream_legacy_id = Bitstream.bitstream_id); +ALTER TABLE checksum_history DROP COLUMN bitstream_legacy_id; + +--Alter table doi +ALTER TABLE doi ADD COLUMN dspace_object UUID; +ALTER TABLE doi ADD CONSTRAINT doi_dspace_object_fk FOREIGN KEY (dspace_object) REFERENCES dspaceobject; +UPDATE doi SET dspace_object = (SELECT community.uuid FROM community WHERE doi.resource_id = community.community_id AND doi.resource_type_id = 4) WHERE doi.resource_type_id = 4; +UPDATE doi SET dspace_object = (SELECT collection.uuid FROM collection WHERE doi.resource_id = collection.collection_id AND doi.resource_type_id = 3) WHERE doi.resource_type_id = 3; +UPDATE doi SET dspace_object = (SELECT item.uuid FROM item WHERE doi.resource_id = item.item_id AND doi.resource_type_id = 2) WHERE doi.resource_type_id = 2; +UPDATE doi SET dspace_object = (SELECT bundle.uuid FROM bundle WHERE doi.resource_id = bundle.bundle_id AND doi.resource_type_id = 1) WHERE doi.resource_type_id = 1; +UPDATE doi SET dspace_object = (SELECT bitstream.uuid FROM bitstream WHERE doi.resource_id = bitstream.bitstream_id AND doi.resource_type_id = 0) WHERE doi.resource_type_id = 0; + diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__hibernate_migration.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__hibernate_migration.sql index f7c439d4cf..cb90a88e44 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__hibernate_migration.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__hibernate_migration.sql @@ -361,4 +361,18 @@ ALTER TABLE epersongroup2workspaceitem add primary key (workspace_item_id,eperso ALTER TABLE most_recent_checksum RENAME COLUMN bitstream_id to bitstream_legacy_id; ALTER TABLE most_recent_checksum ADD COLUMN bitstream_id UUID REFERENCES Bitstream(uuid); UPDATE most_recent_checksum SET bitstream_id = (SELECT Bitstream.uuid FROM Bitstream WHERE most_recent_checksum.bitstream_legacy_id = Bitstream.bitstream_id); -ALTER TABLE most_recent_checksum DROP COLUMN bitstream_legacy_id; \ No newline at end of file +ALTER TABLE most_recent_checksum DROP COLUMN bitstream_legacy_id; + +ALTER TABLE checksum_history RENAME COLUMN bitstream_id to bitstream_legacy_id; +ALTER TABLE checksum_history ADD COLUMN bitstream_id UUID REFERENCES Bitstream(uuid); +UPDATE checksum_history SET bitstream_id = (SELECT Bitstream.uuid FROM Bitstream WHERE checksum_history.bitstream_legacy_id = Bitstream.bitstream_id); +ALTER TABLE checksum_history DROP COLUMN bitstream_legacy_id; + +--Alter table doi +ALTER TABLE doi ADD COLUMN dspace_object UUID REFERENCES dspaceobject(uuid); +UPDATE doi SET dspace_object = (SELECT community.uuid FROM community WHERE doi.resource_id = community.community_id AND doi.resource_type_id = 4) WHERE doi.resource_type_id = 4; +UPDATE doi SET dspace_object = (SELECT collection.uuid FROM collection WHERE doi.resource_id = collection.collection_id AND doi.resource_type_id = 3) WHERE doi.resource_type_id = 3; +UPDATE doi SET dspace_object = (SELECT item.uuid FROM item WHERE doi.resource_id = item.item_id AND doi.resource_type_id = 2) WHERE doi.resource_type_id = 2; +UPDATE doi SET dspace_object = (SELECT bundle.uuid FROM bundle WHERE doi.resource_id = bundle.bundle_id AND doi.resource_type_id = 1) WHERE doi.resource_type_id = 1; +UPDATE doi SET dspace_object = (SELECT bitstream.uuid FROM bitstream WHERE doi.resource_id = bitstream.bitstream_id AND doi.resource_type_id = 0) WHERE doi.resource_type_id = 0; + diff --git a/dspace-api/src/test/resources/hibernate.cfg.xml b/dspace-api/src/test/resources/hibernate.cfg.xml index 35eaf14f4e..735940f0ba 100644 --- a/dspace-api/src/test/resources/hibernate.cfg.xml +++ b/dspace-api/src/test/resources/hibernate.cfg.xml @@ -3,11 +3,6 @@ "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> - - - - - org.h2.Driver diff --git a/dspace-services/pom.xml b/dspace-services/pom.xml index 1970122ace..8f63f62b8b 100644 --- a/dspace-services/pom.xml +++ b/dspace-services/pom.xml @@ -27,7 +27,7 @@ org.springframework spring-context-support - 3.2.0.RELEASE + ${spring.version} compile diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/ControlPanel.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/ControlPanel.java index 10da5a9197..557838d5e0 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/ControlPanel.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/ControlPanel.java @@ -50,6 +50,7 @@ import org.dspace.harvest.HarvestScheduler; import org.dspace.harvest.factory.HarvestServiceFactory; import org.dspace.harvest.service.HarvestSchedulingService; import org.dspace.harvest.service.HarvestedCollectionService; +import org.dspace.storage.rdbms.DatabaseConfigVO; import org.xml.sax.SAXException; /** @@ -102,8 +103,6 @@ public class ControlPanel extends AbstractDSpaceTransformer implements Serviceab private static final Message T_DB_URL = message("xmlui.administrative.ControlPanel.db_url"); private static final Message T_DB_DRIVER = message("xmlui.administrative.ControlPanel.db_driver"); private static final Message T_DB_MAX_CONN = message("xmlui.administrative.ControlPanel.db_maxconnections"); - private static final Message T_DB_MAX_WAIT = message("xmlui.administrative.ControlPanel.db_maxwait"); - private static final Message T_DB_MAX_IDLE = message("xmlui.administrative.ControlPanel.db_maxidle"); private static final Message T_MAIL_SERVER = message("xmlui.administrative.ControlPanel.mail_server"); private static final Message T_MAIL_FROM_ADDRESS = message("xmlui.administrative.ControlPanel.mail_from_address"); private static final Message T_FEEDBACK_RECIPIENT = message("xmlui.administrative.ControlPanel.mail_feedback_recipient"); @@ -496,8 +495,7 @@ public class ControlPanel extends AbstractDSpaceTransformer implements Serviceab /** * List important DSpace configuration parameters. */ - private void addDSpaceConfiguration(Division div) throws WingException - { + private void addDSpaceConfiguration(Division div) throws WingException, SQLException { // LIST: DSpace List dspace = div.addList("dspace"); @@ -521,20 +519,15 @@ public class ControlPanel extends AbstractDSpaceTransformer implements Serviceab dspace.addLabel(T_DB_NAME); dspace.addItem(notempty(context.getDbType())); + DatabaseConfigVO dbConfig = context.getDBConfig(); dspace.addLabel(T_DB_URL); - dspace.addItem(notempty(ConfigurationManager.getProperty("db.url"))); + dspace.addItem(notempty(dbConfig.getDatabaseUrl())); dspace.addLabel(T_DB_DRIVER); - dspace.addItem(notempty(ConfigurationManager.getProperty("db.driver"))); + dspace.addItem(notempty(dbConfig.getDatabaseDriver())); dspace.addLabel(T_DB_MAX_CONN); - dspace.addItem(notempty(ConfigurationManager.getProperty("db.maxconnections"))); - - dspace.addLabel(T_DB_MAX_WAIT); - dspace.addItem(notempty(ConfigurationManager.getProperty("db.maxwait"))); - - dspace.addLabel(T_DB_MAX_IDLE); - dspace.addItem(notempty(ConfigurationManager.getProperty("db.maxidle"))); + dspace.addItem(notempty(String.valueOf(dbConfig.getMaxConnections()))); dspace.addLabel(T_MAIL_SERVER); dspace.addItem(notempty(ConfigurationManager.getProperty("mail.server"))); diff --git a/dspace/config/hibernate.cfg.xml b/dspace/config/hibernate.cfg.xml index 18843b9fe5..2620f0662a 100644 --- a/dspace/config/hibernate.cfg.xml +++ b/dspace/config/hibernate.cfg.xml @@ -18,7 +18,7 @@ ${db.schema} ${db.username} ${db.password} - update + validate org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor false org.hibernate.context.internal.ThreadLocalSessionContext diff --git a/dspace/src/main/config/build.xml b/dspace/src/main/config/build.xml index 1c515c3f8b..01048269a7 100644 --- a/dspace/src/main/config/build.xml +++ b/dspace/src/main/config/build.xml @@ -145,7 +145,7 @@ Common usage: - + @@ -186,7 +186,7 @@ Common usage: - + @@ -789,12 +789,13 @@ Common usage: - - + + - + + @@ -854,7 +855,7 @@ Common usage: diff --git a/pom.xml b/pom.xml index 39dd454128..3253fc1a99 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,12 @@ 4.10.2 2.12.0 1.6.1 - 4.3.10.Final + + 4.2.19.Final + 3.2.14.RELEASE ${basedir} @@ -848,8 +853,7 @@ org.springframework spring-orm - - 3.2.0.RELEASE + ${spring.version} org.swordapp @@ -860,49 +864,49 @@ spring-core org.springframework - 3.2.0.RELEASE + ${spring.version} spring-beans org.springframework - 3.2.0.RELEASE + ${spring.version} spring-aop org.springframework - 3.2.0.RELEASE + ${spring.version} spring-context org.springframework - 3.2.0.RELEASE + ${spring.version} spring-tx org.springframework - 3.2.0.RELEASE + ${spring.version} spring-jdbc org.springframework - 3.2.0.RELEASE + ${spring.version} spring-web org.springframework - 3.2.0.RELEASE + ${spring.version} spring-webmvc org.springframework - 3.2.0.RELEASE + ${spring.version}