Some database changes for dealing with concurrent ID generation problems.

(SF bug #495059)
- SQL file separated into database_schema.sql, for creating the schema,
  clean-database.sql, which removes tables, views etc. from an existing
  DSpace database, and update-sequences.sql which resets the ID generators,
  but is only used after an SQL dump which sets explicit primary keys.
- Sequences for primary key generation added to SQL schema
- SQL function "getnextid" added as an abstraction for access to those sequences
- Database manager now uses getnextid() SQL function to get IDs - this means
  other DB backends can hide ID generation specifics behind this
- Minor tweak to HistoryManager, which was accessing DB manager's in-memory
  ID generator directly - now it doesn't do this.
- Old, now unnecessary "reset ID generator" admin servlet/JSP removed


git-svn-id: http://scm.dspace.org/svn/repo/trunk@362 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robert Tansley
2002-09-09 19:44:33 +00:00
parent 68a1b03ff0
commit 35e9b51a53
10 changed files with 330 additions and 346 deletions

View File

@@ -175,14 +175,14 @@ Common usage:
<!-- ============================================================= -->
<!-- Create the database tables, removing anything already there -->
<!-- Create the database tables -->
<!-- ============================================================= -->
<!-- We execute InitializeDatabase, passing in the simple log4j properties
- file in etc/ and the DSpace configuration file using system
- properties -->
<target name="setup_database"
description="Create database tables, removing existing data">
description="Create database tables">
<java classname="org.dspace.storage.rdbms.InitializeDatabase"
classpathref="build.class.path"
fork="yes"
@@ -194,6 +194,26 @@ Common usage:
</target>
<!-- ============================================================= -->
<!-- Remove the database tables -->
<!-- ============================================================= -->
<!-- We execute InitializeDatabase, passing in the simple log4j properties
- file in etc/ and the DSpace configuration file using system
- properties -->
<target name="clean_database"
description="Removes DSpace database tables, destroying data">
<java classname="org.dspace.storage.rdbms.InitializeDatabase"
classpathref="build.class.path"
fork="yes"
failonerror="yes">
<sysproperty key="log4j.configuration" value="file:${basedir}/etc/log4j.build.properties"/>
<sysproperty key="dspace.configuration" value="${config}"/>
<arg value="${basedir}/etc/clean-database.sql"/>
</java>
</target>
<!-- ============================================================= -->
<!-- Load the initial contents of the registries into the database -->
<!-- ============================================================= -->

View File

@@ -0,0 +1,129 @@
--
-- clean-database.sql
--
-- Version: $Revision$
--
-- Date: $Date$
--
-- Copyright (c) 2001, Hewlett-Packard Company and Massachusetts
-- Institute of Technology. All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- - Neither the name of the Hewlett-Packard Company nor the name of the
-- Massachusetts Institute of Technology nor the names of their
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-- HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
-- USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-- DAMAGE.
--
-- DSpace database cleaner
--
-- This SQL "cleans" a database used by a DSpace installation. It removes
-- all tables etc. so the database is completely empty and ready for a
-- fresh installation. Of course, this means all data is lost.
--
-- Caution: THIS IS POSTGRESQL-SPECIFC
-- * The sequences dropped below are automatically created by PostgreSQL
-- for the SERIAL typed fields.
--
-- This should be kept in sync if database_schema.sql is updated.
-- Drop indices
DROP INDEX dcvalue_dc_type_id_idx;
-- Drop the views
DROP VIEW CommunityItemsByDateAccessioned;
DROP VIEW CollectionItemsByDateAccessioned;
DROP VIEW CommunityItemsByDate;
DROP VIEW CollectionItemsByDate;
DROP VIEW CommunityItemsByTitle;
DROP VIEW CollectionItemsByTitle;
DROP VIEW CommunityItemsByAuthor;
DROP VIEW CollectionItemsByAuthor;
DROP VIEW Community2Item;
-- Then the tables
DROP TABLE ItemsByDateAccessioned;
DROP TABLE ItemsByDate;
DROP TABLE ItemsByTitle;
DROP TABLE ItemsByAuthor;
DROP TABLE HistoryState;
DROP TABLE History;
DROP TABLE RegistrationData;
DROP TABLE TasklistItem;
DROP TABLE WorkflowItem;
DROP TABLE WorkspaceItem;
DROP TABLE Handle;
DROP TABLE EPersonGroup2EPerson;
DROP TABLE ResourcePolicy;
DROP TABLE Collection2Item;
DROP TABLE Community2Collection;
DROP TABLE Collection;
DROP TABLE Community;
DROP TABLE DCValue;
DROP TABLE DCTypeRegistry;
DROP TABLE Bundle2Bitstream;
DROP TABLE Item2Bundle;
DROP TABLE Bundle;
DROP TABLE Item;
DROP TABLE EPersonGroup;
DROP TABLE EPerson;
DROP TABLE Bitstream;
DROP TABLE FileExtension;
DROP TABLE BitstreamFormatRegistry;
-- Now drop the sequences for ID (primary key) creation
DROP SEQUENCE bitstreamformatregistry_seq;
DROP SEQUENCE fileextension_seq;
DROP SEQUENCE bitstream_seq;
DROP SEQUENCE eperson_seq;
DROP SEQUENCE epersongroup_seq;
DROP SEQUENCE item_seq;
DROP SEQUENCE bundle_seq;
DROP SEQUENCE item2bundle_seq;
DROP SEQUENCE bundle2bitstream_seq;
DROP SEQUENCE dctyperegistry_seq;
DROP SEQUENCE dcvalue_seq;
DROP SEQUENCE community_seq;
DROP SEQUENCE collection_seq;
DROP SEQUENCE community2collection_seq;
DROP SEQUENCE collection2item_seq;
DROP SEQUENCE resourcepolicy_seq;
DROP SEQUENCE epersongroup2eperson_seq;
DROP SEQUENCE handle_seq;
DROP SEQUENCE workspaceitem_seq;
DROP SEQUENCE workflowitem_seq;
DROP SEQUENCE tasklistitem_seq;
DROP SEQUENCE registrationdata_seq;
DROP SEQUENCE history_seq;
DROP SEQUENCE historystate_seq;
DROP SEQUENCE itemsbyauthor_seq;
DROP SEQUENCE itemsbytitle_seq;
DROP SEQUENCE itemsbydate_seq;
DROP SEQUENCE itemsbydateaccessioned_seq;
-- Drop the getnextid() function
DROP FUNCTION getnextid(VARCHAR(40));

View File

@@ -40,19 +40,77 @@
--
--
--
-- DSpace SQL table definitions
-- DSpace SQL schema
--
-- Authors: Peter Breton, Robert Tansley, David Stuve, Daniel Chudnov
--
-- This file is used as-is to initialize a database. Therefore,
-- table and view definitions must be ordered correctly.
--
-- Caution: THIS IS POSTGRESQL-SPECIFIC:
--
-- * SEQUENCES are used for automatic ID generation
-- * FUNCTION getnextid used for automatic ID generation
--
--
-- To convert to work with another database, you need to ensure
-- an SQL function 'getnextid', which takes a table name as an
-- argument, will return a safe new ID to use to create a new
-- row in that table.
-------------------------------------------------------
-- Function for obtaining new IDs.
--
-- * The argument is a table name
-- * It returns a new ID safe to use for that table
--
-- The function reads the next value from the sequence
-- 'tablename_seq'
-------------------------------------------------------
CREATE FUNCTION getnextid(VARCHAR(40)) RETURNS INTEGER AS
'SELECT CAST (nextval($1 || ''_seq'') AS INTEGER) AS RESULT;' LANGUAGE SQL;
-------------------------------------------------------
-- Sequences for creating new IDs (primary keys) for
-- tables. Each table must have a corresponding
-- sequence called 'tablename_seq'.
-------------------------------------------------------
CREATE SEQUENCE bitstreamformatregistry_seq;
CREATE SEQUENCE fileextension_seq;
CREATE SEQUENCE bitstream_seq;
CREATE SEQUENCE eperson_seq;
CREATE SEQUENCE epersongroup_seq;
CREATE SEQUENCE item_seq;
CREATE SEQUENCE bundle_seq;
CREATE SEQUENCE item2bundle_seq;
CREATE SEQUENCE bundle2bitstream_seq;
CREATE SEQUENCE dctyperegistry_seq;
CREATE SEQUENCE dcvalue_seq;
CREATE SEQUENCE community_seq;
CREATE SEQUENCE collection_seq;
CREATE SEQUENCE community2collection_seq;
CREATE SEQUENCE collection2item_seq;
CREATE SEQUENCE resourcepolicy_seq;
CREATE SEQUENCE epersongroup2eperson_seq;
CREATE SEQUENCE handle_seq;
CREATE SEQUENCE workspaceitem_seq;
CREATE SEQUENCE workflowitem_seq;
CREATE SEQUENCE tasklistitem_seq;
CREATE SEQUENCE registrationdata_seq;
CREATE SEQUENCE history_seq;
CREATE SEQUENCE historystate_seq;
CREATE SEQUENCE itemsbyauthor_seq;
CREATE SEQUENCE itemsbytitle_seq;
CREATE SEQUENCE itemsbydate_seq;
CREATE SEQUENCE itemsbydateaccessioned_seq;
-------------------------------------------------------
-- BitstreamFormatRegistry table
-------------------------------------------------------
DROP TABLE BitstreamFormatRegistry;
CREATE TABLE BitstreamFormatRegistry
(
bitstream_format_id INTEGER PRIMARY KEY,
@@ -67,8 +125,6 @@ CREATE TABLE BitstreamFormatRegistry
-------------------------------------------------------
-- FileExtension table
-------------------------------------------------------
DROP TABLE FileExtension;
CREATE TABLE FileExtension
(
file_extension_id INTEGER PRIMARY KEY,
@@ -79,8 +135,6 @@ CREATE TABLE FileExtension
-------------------------------------------------------
-- Bitstream table
-------------------------------------------------------
DROP TABLE Bitstream;
CREATE TABLE Bitstream
(
bitstream_id INTEGER PRIMARY KEY,
@@ -99,8 +153,6 @@ CREATE TABLE Bitstream
-------------------------------------------------------
-- EPerson table
-------------------------------------------------------
DROP TABLE EPerson;
CREATE TABLE EPerson
(
eperson_id INTEGER PRIMARY KEY,
@@ -116,8 +168,6 @@ CREATE TABLE EPerson
-------------------------------------------------------
-- EPersonGroup table
-------------------------------------------------------
DROP TABLE EPersonGroup;
CREATE TABLE EPersonGroup
(
eperson_group_id INTEGER PRIMARY KEY,
@@ -127,8 +177,6 @@ CREATE TABLE EPersonGroup
-------------------------------------------------------
-- Item table
-------------------------------------------------------
DROP TABLE Item;
CREATE TABLE Item
(
item_id INTEGER PRIMARY KEY,
@@ -139,8 +187,6 @@ CREATE TABLE Item
-------------------------------------------------------
-- Bundle table
-------------------------------------------------------
DROP TABLE Bundle;
CREATE TABLE Bundle
(
bundle_id INTEGER PRIMARY KEY,
@@ -150,8 +196,6 @@ CREATE TABLE Bundle
-------------------------------------------------------
-- Item2Bundle table
-------------------------------------------------------
DROP TABLE Item2Bundle;
CREATE TABLE Item2Bundle
(
id INTEGER PRIMARY KEY,
@@ -162,8 +206,6 @@ CREATE TABLE Item2Bundle
-------------------------------------------------------
-- Bundle2Bitstream table
-------------------------------------------------------
DROP TABLE Bundle2Bitstream;
CREATE TABLE Bundle2Bitstream
(
id INTEGER PRIMARY KEY,
@@ -174,8 +216,6 @@ CREATE TABLE Bundle2Bitstream
-------------------------------------------------------
-- DCTypeRegistry table
-------------------------------------------------------
DROP TABLE DCTypeRegistry;
CREATE TABLE DCTypeRegistry
(
dc_type_id INTEGER PRIMARY KEY,
@@ -188,8 +228,6 @@ CREATE TABLE DCTypeRegistry
-------------------------------------------------------
-- DCValue table
-------------------------------------------------------
DROP TABLE DCValue;
CREATE TABLE DCValue
(
dc_value_id INTEGER PRIMARY KEY,
@@ -202,14 +240,11 @@ CREATE TABLE DCValue
);
-- An index for dctypes
DROP INDEX dcvalue_dc_type_id_idx;
CREATE INDEX dcvalue_dc_type_id_idx on DCValue(dc_type_id);
-------------------------------------------------------
-- Community table
-------------------------------------------------------
DROP TABLE Community;
CREATE TABLE Community
(
community_id INTEGER PRIMARY KEY,
@@ -224,8 +259,6 @@ CREATE TABLE Community
-------------------------------------------------------
-- Collection table
-------------------------------------------------------
DROP TABLE Collection;
CREATE TABLE Collection
(
collection_id INTEGER PRIMARY KEY,
@@ -246,8 +279,6 @@ CREATE TABLE Collection
-------------------------------------------------------
-- Community2Collection table
-------------------------------------------------------
DROP TABLE Community2Collection;
CREATE TABLE Community2Collection
(
id INTEGER PRIMARY KEY,
@@ -258,8 +289,6 @@ CREATE TABLE Community2Collection
-------------------------------------------------------
-- Collection2Item table
-------------------------------------------------------
DROP TABLE Collection2Item;
CREATE TABLE Collection2Item
(
id INTEGER PRIMARY KEY,
@@ -270,8 +299,6 @@ CREATE TABLE Collection2Item
-------------------------------------------------------
-- ResourcePolicy table
-------------------------------------------------------
DROP TABLE ResourcePolicy;
CREATE TABLE ResourcePolicy
(
policy_id INTEGER PRIMARY KEY,
@@ -288,8 +315,6 @@ CREATE TABLE ResourcePolicy
-------------------------------------------------------
-- EPersonGroup2EPerson table
-------------------------------------------------------
DROP TABLE EPersonGroup2EPerson;
CREATE TABLE EPersonGroup2EPerson
(
id INTEGER PRIMARY KEY,
@@ -300,8 +325,6 @@ CREATE TABLE EPersonGroup2EPerson
-------------------------------------------------------
-- Handle table
-------------------------------------------------------
DROP TABLE Handle;
CREATE TABLE Handle
(
handle_id INTEGER PRIMARY KEY,
@@ -313,8 +336,6 @@ CREATE TABLE Handle
-------------------------------------------------------
-- WorkspaceItem table
-------------------------------------------------------
DROP TABLE WorkspaceItem;
CREATE TABLE WorkspaceItem
(
workspace_item_id INTEGER PRIMARY KEY,
@@ -331,8 +352,6 @@ CREATE TABLE WorkspaceItem
-------------------------------------------------------
-- WorkflowItem table
-------------------------------------------------------
DROP TABLE WorkflowItem;
CREATE TABLE WorkflowItem
(
workflow_id INTEGER PRIMARY KEY,
@@ -353,8 +372,6 @@ CREATE TABLE WorkflowItem
-------------------------------------------------------
-- TasklistItem table
-------------------------------------------------------
DROP TABLE TasklistItem;
CREATE TABLE TasklistItem
(
tasklist_id INTEGER PRIMARY KEY,
@@ -366,8 +383,6 @@ CREATE TABLE TasklistItem
-------------------------------------------------------
-- RegistrationData table
-------------------------------------------------------
DROP TABLE RegistrationData;
CREATE TABLE RegistrationData
(
registrationdata_id INTEGER PRIMARY KEY,
@@ -380,22 +395,18 @@ CREATE TABLE RegistrationData
-------------------------------------------------------
-- History table
-------------------------------------------------------
DROP TABLE History;
CREATE TABLE History
(
history_id INTEGER PRIMARY KEY,
-- When it was stored
creation_date TIMESTAMP,
-- A checksum to keep serializations from being stored more than once
-- A checksum to keep INTEGERizations from being stored more than once
checksum VARCHAR(32) UNIQUE
);
-------------------------------------------------------
-- HistoryState table
-------------------------------------------------------
DROP TABLE HistoryState;
CREATE TABLE HistoryState
(
history_state_id INTEGER PRIMARY KEY,
@@ -403,41 +414,21 @@ CREATE TABLE HistoryState
);
------------------------------------------------------------
-- Convenience views
-- Browse subsystem tables and views
------------------------------------------------------------
-------------------------------------------------------
-- Item2Handle view
-------------------------------------------------------
-- Note: org.dspace.core.Constants.ITEM = 2
DROP VIEW Item2Handle;
CREATE VIEW Item2Handle as
select handle_id, handle, resource_id as item_id
from Handle where resource_type_id = 2
;
-------------------------------------------------------
-- Community2Item view
-------------------------------------------------------
DROP VIEW Community2Item;
CREATE VIEW Community2Item as
SELECT Community2Collection.community_id, Collection2Item.item_id
FROM Community2Collection, Collection2Item
WHERE Collection2Item.collection_id = Community2Collection.collection_id
;
------------------------------------------------------------
-- Browse subsystem views
------------------------------------------------------------
-------------------------------------------------------
-- ItemsByAuthor table
-------------------------------------------------------
DROP TABLE ItemsByAuthor;
CREATE TABLE ItemsByAuthor
(
items_by_author_id INTEGER PRIMARY KEY,
@@ -448,8 +439,6 @@ CREATE TABLE ItemsByAuthor
-------------------------------------------------------
-- CollectionItemsByAuthor view
-------------------------------------------------------
DROP VIEW CollectionItemsByAuthor;
CREATE VIEW CollectionItemsByAuthor as
SELECT Collection2Item.collection_id, ItemsByAuthor.*
FROM ItemsByAuthor, Collection2Item
@@ -459,8 +448,6 @@ WHERE ItemsByAuthor.item_id = Collection2Item.item_id
-------------------------------------------------------
-- CommunityItemsByAuthor view
-------------------------------------------------------
DROP VIEW CommunityItemsByAuthor;
CREATE VIEW CommunityItemsByAuthor as
SELECT Community2Item.community_id, ItemsByAuthor.*
FROM ItemsByAuthor, Community2Item
@@ -470,9 +457,6 @@ WHERE ItemsByAuthor.item_id = Community2Item.item_id
----------------------------------------
-- ItemsByTitle table
----------------------------------------
DROP TABLE ItemsByTitle;
CREATE TABLE ItemsByTitle
(
items_by_title_id INTEGER PRIMARY KEY,
@@ -484,8 +468,6 @@ CREATE TABLE ItemsByTitle
-------------------------------------------------------
-- CollectionItemsByTitle view
-------------------------------------------------------
DROP VIEW CollectionItemsByTitle;
CREATE VIEW CollectionItemsByTitle as
SELECT Collection2Item.collection_id, ItemsByTitle.*
FROM ItemsByTitle, Collection2Item
@@ -495,8 +477,6 @@ WHERE ItemsByTitle.item_id = Collection2Item.item_id
-------------------------------------------------------
-- CommunityItemsByTitle view
-------------------------------------------------------
DROP VIEW CommunityItemsByTitle;
CREATE VIEW CommunityItemsByTitle as
SELECT Community2Item.community_id, ItemsByTitle.*
FROM ItemsByTitle, Community2Item
@@ -506,8 +486,6 @@ WHERE ItemsByTitle.item_id = Community2Item.item_id
-------------------------------------------------------
-- ItemsByDate table
-------------------------------------------------------
DROP TABLE ItemsByDate;
CREATE TABLE ItemsByDate
(
items_by_date_id INTEGER PRIMARY KEY,
@@ -518,8 +496,6 @@ CREATE TABLE ItemsByDate
-------------------------------------------------------
-- CollectionItemsByDate view
-------------------------------------------------------
DROP VIEW CollectionItemsByDate;
CREATE VIEW CollectionItemsByDate as
SELECT Collection2Item.collection_id, ItemsByDate.*
FROM ItemsByDate, Collection2Item
@@ -529,8 +505,6 @@ WHERE ItemsByDate.item_id = Collection2Item.item_id
-------------------------------------------------------
-- CommunityItemsByDate view
-------------------------------------------------------
DROP VIEW CommunityItemsByDate;
CREATE VIEW CommunityItemsByDate as
SELECT Community2Item.community_id, ItemsByDate.*
FROM ItemsByDate, Community2Item
@@ -540,8 +514,6 @@ WHERE ItemsByDate.item_id = Community2Item.item_id
-------------------------------------------------------
-- ItemsByDateAccessioned table
-------------------------------------------------------
DROP TABLE ItemsByDateAccessioned;
CREATE TABLE ItemsByDateAccessioned
(
items_by_date_accessioned_id INTEGER PRIMARY KEY,
@@ -552,8 +524,6 @@ CREATE TABLE ItemsByDateAccessioned
-------------------------------------------------------
-- CollectionItemsByDateAccessioned view
-------------------------------------------------------
DROP VIEW CollectionItemsByDateAccessioned;
CREATE VIEW CollectionItemsByDateAccessioned as
SELECT Collection2Item.collection_id, ItemsByDateAccessioned.*
FROM ItemsByDateAccessioned, Collection2Item
@@ -563,11 +533,10 @@ WHERE ItemsByDateAccessioned.item_id = Collection2Item.item_id
-------------------------------------------------------
-- CommunityItemsByDateAccessioned view
-------------------------------------------------------
DROP VIEW CommunityItemsByDateAccessioned;
CREATE VIEW CommunityItemsByDateAccessioned as
SELECT Community2Item.community_id, ItemsByDateAccessioned.*
FROM ItemsByDateAccessioned, Community2Item
WHERE ItemsByDateAccessioned.item_id = Community2Item.item_id
;

View File

@@ -0,0 +1,85 @@
--
-- update-sequences.sql
--
-- Version: $Revision$
--
-- Date: $Date$
--
-- Copyright (c) 2001, Hewlett-Packard Company and Massachusetts
-- Institute of Technology. All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- - Neither the name of the Hewlett-Packard Company nor the name of the
-- Massachusetts Institute of Technology nor the names of their
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-- HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
-- USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-- DAMAGE.
-- SQL code to update the ID (primary key) generating sequences, if some
-- import operation has set explicit IDs.
--
-- Sequences are used to generate IDs for new rows in the database. If a
-- bulk import operation, such as an SQL dump, specifies primary keys for
-- imported data explicitly, the sequences are out of sync and need updating.
-- This SQL code does just that.
--
-- This should rarely be needed; any bulk import should be performed using the
-- org.dspace.content API which is safe to use concurrently and in multiple
-- JVMs. The SQL code below will typically only be required after a direct
-- SQL data dump from a backup or somesuch.
-- There should be one of these calls for every ID sequence defined in
-- database_schema.sql.
SELECT setval('bitstreamformatregistry_seq', max(bitstream_format_id)) FROM bitstreamformatregistry;
SELECT setval('fileextension_seq', max(file_extension_id)) FROM fileextension;
SELECT setval('bitstream_seq', max(bitstream_id)) FROM bitstream;
SELECT setval('eperson_seq', max(eperson_id)) FROM eperson;
SELECT setval('epersongroup_seq', max(eperson_group_id)) FROM epersongroup;
SELECT setval('item_seq', max(item_id)) FROM item;
SELECT setval('bundle_seq', max(bundle_id)) FROM bundle;
SELECT setval('item2bundle_seq', max(id)) FROM item2bundle;
SELECT setval('bundle2bitstream_seq', max(id)) FROM bundle2bitstream;
SELECT setval('dctyperegistry_seq', max(dc_type_id)) FROM dctyperegistry;
SELECT setval('dcvalue_seq', max(dc_value_id)) FROM dcvalue;
SELECT setval('community_seq', max(community_id)) FROM community;
SELECT setval('collection_seq', max(collection_id)) FROM collection;
SELECT setval('community2collection_seq', max(id)) FROM community2collection;
SELECT setval('collection2item_seq', max(id)) FROM collection2item;
SELECT setval('resourcepolicy_seq', max(policy_id)) FROM resourcepolicy;
SELECT setval('epersongroup2eperson_seq', max(id)) FROM epersongroup2eperson;
SELECT setval('handle_seq', max(handle_id)) FROM handle;
SELECT setval('workspaceitem_seq', max(workspace_item_id)) FROM workspaceitem;
SELECT setval('workflowitem_seq', max(workflow_id)) FROM workflowitem;
SELECT setval('tasklistitem_seq', max(tasklist_id)) FROM tasklistitem;
SELECT setval('registrationdata_seq', max(registrationdata_id)) FROM registrationdata;
SELECT setval('history_seq', max(history_id)) FROM history;
SELECT setval('historystate_seq', max(history_state_id)) FROM historystate;
SELECT setval('itemsbyauthor_seq', max(items_by_author_id)) FROM itemsbyauthor;
SELECT setval('itemsbytitle_seq', max(items_by_title_id)) FROM itemsbytitle;
SELECT setval('itemsbydate_seq', max(items_by_date_id)) FROM itemsbydate;
SELECT setval('itemsbydateaccessioned_seq', max(items_by_date_accessioned_id)) FROM itemsbydateaccessioned;

View File

@@ -274,11 +274,6 @@
</init-param>
</servlet>
<servlet>
<servlet-name>reset-id-generator</servlet-name>
<servlet-class>org.dspace.app.webui.servlet.admin.ResetIDGenServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>retrieve</servlet-name>
<servlet-class>org.dspace.app.webui.servlet.RetrieveServlet</servlet-class>
@@ -417,11 +412,6 @@
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reset-id-generator</servlet-name>
<url-pattern>/admin/reset-id-generator</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>retrieve</servlet-name>
<url-pattern>/retrieve/*</url-pattern>

View File

@@ -1,53 +0,0 @@
<%--
- reset-id-generator.jsp
-
- Version: $Revision$
-
- Date: $Date$
-
- Copyright (c) 2001, Hewlett-Packard Company and Massachusetts
- Institute of Technology. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- - Neither the name of the Hewlett-Packard Company nor the name of the
- Massachusetts Institute of Technology nor the names of their
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- DAMAGE.
--%>
<%--
- DB ID generator reset message
--%>
<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>
<dspace:layout locbar="link" navbar="admin" title="Administer">
<h1>Administration Tools</h1>
<P><Strong>Database ID generator has been reset.</P>
<P>Please select an operation from the navigation bar on the left.</P>
</dspace:layout>

View File

@@ -76,9 +76,6 @@
labels.add("Authorization");
links.add("authorize");
labels.add("Reset ID<br>Generator");
links.add("reset-id-generator");
// Get the current page, minus query string
String currentPage = UIUtil.getOriginalURL(request);
int c = currentPage.indexOf( '?' );

View File

@@ -1,84 +0,0 @@
/*
* ResetIDGenerator.java
*
* Version: $Revision$
*
* Date: $Date$
*
* Copyright (c) 2001, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
package org.dspace.app.webui.servlet.admin;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.dspace.app.webui.servlet.DSpaceServlet;
import org.dspace.app.webui.util.JSPManager;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.storage.rdbms.DatabaseManager;
/**
* Simple servlet for resetting the database manager's ID generator. This is
* to work around a bug where the ID generator doesn't work when more than one
* JVM is accessing DSpace (e.g. the item importer).
*
* @author Robert Tansley
* @version $Revision$
*/
public class ResetIDGenServlet extends DSpaceServlet
{
// FIXME: This is a "tentacle" - app layer shouldn't access storage directly
/** Logger */
private static Logger log = Logger.getLogger(EditCommunitiesServlet.class);
protected void doDSGet(Context context,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException, SQLException, AuthorizeException
{
DatabaseManager.resetIDGenerator();
JSPManager.showJSP(request, response,
"/admin/reset-id-generator.jsp");
}
}

View File

@@ -180,9 +180,15 @@ public class HistoryManager
// Create a model
Model model = new ModelMem();
// An id for the new state
Integer stateId = (flag == REMOVE) ? null :
new Integer(DatabaseManager.getID("HistoryState"));
// A table row and id for the new state
Integer stateId = null;
TableRow row = null;
if (flag != REMOVE)
{
row = DatabaseManager.create(context, "HistoryState");
stateId = new Integer(row.getIntColumn("history_state_id"));
}
// This is the object that we're making statements about....
Resource obj = model.createResource(id);
@@ -251,10 +257,9 @@ public class HistoryManager
if (flag != REMOVE)
{
TableRow row = DatabaseManager.create(context, "HistoryState");
row.setColumn("history_state_id", stateId.intValue());
row.setColumn("object_id", id);
DatabaseManager.update(context, row);
}
StringWriter swdata = new StringWriter();

View File

@@ -75,13 +75,6 @@ public class DatabaseManager
/** True if initialization has been done */
private static boolean initialized = false;
/**
* A map of unique ids.
* The key is the table name; the value is an Integer which is the
* highest value assigned.
*/
private static Map ids = new HashMap();
/**
* A map of database column information.
* The key is the table name, a String; the value is
@@ -263,7 +256,6 @@ public class DatabaseManager
{
TableRow row = new TableRow(canonicalize(table),
getColumnNames(table));
assignId(row);
insert(context, row);
return row;
}
@@ -408,24 +400,36 @@ public class DatabaseManager
{
String table = canonicalize(row.getTable());
// Get an ID (primary key) for this row by using the "getnextid"
// SQL function
Statement statement = context.getDBConnection().createStatement();
ResultSet rs = statement.executeQuery(
"SELECT getnextid('" + table + "') AS result");
rs.next();
int newID = rs.getInt(1);
statement.close();
// Set the ID in the table row object
row.setColumn(getPrimaryKeyColumn(table), newID);
StringBuffer sql = new StringBuffer()
.append("insert into ")
.append("INSERT INTO ")
.append(table)
.append(" ( ");
ColumnInfo[] info = getColumnInfo(table);
for (int i = 0; i < info.length; i++ )
for (int i = 0; i < info.length; i++)
{
sql.append(i == 0 ? "" : ", ").append(info[i].getName());
sql.append(i == 0 ? "" : ",").append(info[i].getName());
}
sql.append(") values ( ");
sql.append(") VALUES ( ");
// Values to insert
for (int i = 0; i < info.length; i++ )
for (int i = 0; i < info.length; i++)
{
sql.append(i == 0 ? "" : ", ").append("?");
sql.append(i == 0 ? "" : ",").append("?");
}
// Watch the syntax
@@ -899,72 +903,6 @@ public class DatabaseManager
return null;
}
/**
* Assign an ID to row.
*
* @param row The row to assign an id to.
* @exception SQLException If a database error occurs
*/
private static synchronized void assignId (TableRow row)
throws SQLException
{
String table = canonicalize(row.getTable());
String pk = getPrimaryKeyColumn(table);
row.setColumn(pk, getID(table));
}
/**
* Return the next id for table.
*
* @param table The RDBMS table to obtain an ID for
* @return The next id
* @exception SQLException If a database error occurs
*/
public static synchronized int getID (String table)
throws SQLException
{
// Assigned ids are simply one plus the maximum value
// of the primary key column, and incremented from there.
String pk = getPrimaryKeyColumn(table);
Integer id = (Integer) ids.get(table);
int current_id = id == null ? -1 : id.intValue();
if (id == null)
{
String sql = MessageFormat.format
("select max({0}) from {1}",
new Object[] { pk, table} );
Connection connection = null;
Statement statement = null;
try
{
connection = getConnection();
statement = connection.createStatement();
ResultSet results = statement.executeQuery(sql);
current_id = results.next() ? results.getInt(1): -1;
}
finally
{
if (statement != null)
{
try
{
statement.close();
}
catch (SQLException sqle) {}
}
if (connection != null)
connection.close();
}
}
int new_id = current_id + 1;
ids.put(table, new Integer(new_id));
return new_id;
}
/**
* Execute SQL as a PreparedStatement on Connection.
* Bind parameters in columns to the values in the table row before
@@ -1145,18 +1083,6 @@ public class DatabaseManager
DriverManager.registerDriver(new SimplePool());
initialized = true;
}
/**
* Simple workaround method to reset the in-memory ID generator. This
* causes it to re-read the DB to find IDs to allocate to new objects.
* This should be invoked after another JVM has been writing to the DB.
*/
public static void resetIDGenerator()
{
// Remove cached IDs
ids = new HashMap();
}
}
/**