From: Patrick Schmitz Date: Thu, 16 Jun 2011 20:33:49 +0000 (+0000) Subject: CSPACE-2903, CSPACE-2421. Added support for postgresql, cleaned up configuration... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=b3a5b237e56866ae6c6373ca85363576552b8187;p=tmp%2Fjakarta-migration.git CSPACE-2903, CSPACE-2421. Added support for postgresql, cleaned up configuration and various sql statements and resources that were mysql-specific. Refactored lots of configuration to take DB info from build properties. Note that in this version, mysql is still the configured DB. --- diff --git a/build.properties b/build.properties index 7dd8d18a3..dd351fab5 100644 --- a/build.properties +++ b/build.properties @@ -76,6 +76,8 @@ db.jdbc.driver.class=com.mysql.jdbc.Driver db.dialect=org.hibernate.dialect.MySQLDialect db.typemapping=mySQL db.exceptionsorter=org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter +db.spring.acl.classIdentityQuery=SELECT @@IDENTITY +db.spring.acl.sidIdentityQuery=SELECT @@IDENTITY #For postgresql, uncomment this, and comment out mysql section #db.port=5432 @@ -83,7 +85,11 @@ db.exceptionsorter=org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter #db.jdbc.driver.class=org.postgresql.Driver #db.dialect=org.hibernate.dialect.PostgreSQLDialect #db.typemapping=PostgreSQL 8.0 -#db.exceptionsorter=org.jboss.resource.adapter.jdbc.vendor.PostgreSQLExceptionSorter +# Should be org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter +# but current JBoss does not seem to include it... +#db.exceptionsorter= +#db.spring.acl.classIdentityQuery=select currval(pg_get_serial_sequence('acl_class', 'id')) +#db.spring.acl.sidIdentityQuery=select currval(pg_get_serial_sequence('acl_sid', 'id')) #database common settings diff --git a/build.xml b/build.xml index eb311ae24..e46dc2a38 100644 --- a/build.xml +++ b/build.xml @@ -218,6 +218,7 @@ url="${db.jdbc.baseurl}" userid="${db.user}" password="${db.user.password}" + autocommit="true" src="${db.script.dir}/init_db.sql" > diff --git a/pom.xml b/pom.xml index fc4c1bf10..60aff6b91 100644 --- a/pom.xml +++ b/pom.xml @@ -190,6 +190,14 @@ false + + repo1 + Maven repo1 + http://repo1.maven.org/maven2 + + false + + maven repo maven repo diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch.xml index 383c08d6b..0cc39a587 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch.xml @@ -3,7 +3,6 @@ YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I= - YWRtaW5AY29sbGVjdGlvbnNwYWNlLm9yZzpBZG1pbmlzdHJhdG9y diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 6b09ab5bb..f0ac40123 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -384,6 +384,15 @@ cspace-services package + + ../../build.properties + + + + src/main/resources + true + + org.codehaus.mojo @@ -403,7 +412,20 @@ - + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + process-resources + + resources + + + + + org.codehaus.cargo cargo-maven2-plugin 0.3 diff --git a/services/JaxRsServiceProvider/src/main/resources/META-INF/persistence.xml b/services/JaxRsServiceProvider/src/main/resources/META-INF/persistence.xml index 2ae9d411d..9bed0370d 100644 --- a/services/JaxRsServiceProvider/src/main/resources/META-INF/persistence.xml +++ b/services/JaxRsServiceProvider/src/main/resources/META-INF/persistence.xml @@ -15,7 +15,7 @@ org.collectionspace.services.authorization.Role org.collectionspace.services.authorization.AccountRoleRel - + diff --git a/services/account/client/pom.xml b/services/account/client/pom.xml index 458162e5f..ab3d51b2b 100644 --- a/services/account/client/pom.xml +++ b/services/account/client/pom.xml @@ -54,7 +54,12 @@ mysql-connector-java test - + + postgresql + postgresql + + org.collectionspace.services org.collectionspace.services.account.jaxb @@ -74,6 +78,24 @@ ddl + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + ${basedir}/../../../build.properties + + + + + org.codehaus.mojo hibernate3-maven-plugin @@ -107,8 +129,13 @@ mysql mysql-connector-java - 5.1.5 + 5.1.5 + + postgresql + postgresql + 8.4-702.jdbc4 + @@ -118,7 +145,7 @@ process-test-resources - + diff --git a/services/account/pstore/src/main/resources/db/mysql/account_index.sql b/services/account/pstore/src/main/resources/db/mysql/account_index.sql index 0b9a66ec4..0eace4edc 100644 --- a/services/account/pstore/src/main/resources/db/mysql/account_index.sql +++ b/services/account/pstore/src/main/resources/db/mysql/account_index.sql @@ -3,7 +3,7 @@ -- Licensed under the Educational Community License (ECL), Version 2.0. -- You may not use this file except in compliance with this License. -- -use cspace; +-- use cspace; CREATE INDEX index_userid ON accounts_common (userid); CREATE INDEX index_screen_name ON accounts_common (screen_name); CREATE INDEX index_email ON accounts_common (email); diff --git a/services/account/pstore/src/main/resources/db/postgresql/README.txt b/services/account/pstore/src/main/resources/db/postgresql/README.txt new file mode 100644 index 000000000..b591433f8 --- /dev/null +++ b/services/account/pstore/src/main/resources/db/postgresql/README.txt @@ -0,0 +1,32 @@ +The file account.sql is basically generated by the gen_ddl ant target. +However, you must modify the result of that to make the + + DROP TABLE + +statements be + + DROP TABLE IF EXISTS table CASCADE + +This ensures that first time setup does not fail, and that later invocations +can deal with dependencies. + +You must also make the + + DROP SEQUENCE + +statements be + + DROP SEQUENCE IF EXISTS + +for similar reasons. + +You must also remove (comment out) the statement (which is superfluous with the CASCADE above): + + alter table permissions_actions drop constraint FKFDA649B05A9CEEB5; + +When using the account_tenants table on insert, you have to specify "nextval('hibernate_sequence')" +as the value for the HJID column. + +Note that because of the way gen_ddl does its work per-sub-project, there is a single shared +sequence for both this and the authorization.sql script. This should be okay, even if it does +create gaps in what would be a nice sequence for each table. diff --git a/services/account/pstore/src/main/resources/db/postgresql/account.sql b/services/account/pstore/src/main/resources/db/postgresql/account.sql new file mode 100644 index 000000000..2a7fa297c --- /dev/null +++ b/services/account/pstore/src/main/resources/db/postgresql/account.sql @@ -0,0 +1,10 @@ +-- alter table accounts_tenants drop constraint FKFDA649B05A9CEEB5; +DROP TABLE IF EXISTS accounts_common CASCADE; +DROP TABLE IF EXISTS accounts_tenants CASCADE; +DROP TABLE IF EXISTS tenants CASCADE; +DROP SEQUENCE IF EXISTS hibernate_sequence; +create table accounts_common (csid varchar(128) not null, created_at timestamp not null, email varchar(255) not null, mobile varchar(255), person_ref_name varchar(255), phone varchar(255), screen_name varchar(128) not null, status varchar(15) not null, updated_at timestamp, userid varchar(128) not null, primary key (csid)); +create table accounts_tenants (HJID int8 not null, tenant_id varchar(128) not null, TENANTS_ACCOUNTSCOMMON_CSID varchar(128), primary key (HJID)); +create table tenants (id varchar(128) not null, created_at timestamp not null, name varchar(255) not null, updated_at timestamp, primary key (id)); +alter table accounts_tenants add constraint FKFDA649B05A9CEEB5 foreign key (TENANTS_ACCOUNTSCOMMON_CSID) references accounts_common; +create sequence hibernate_sequence; diff --git a/services/account/pstore/src/main/resources/db/postgresql/account_index.sql b/services/account/pstore/src/main/resources/db/postgresql/account_index.sql new file mode 100644 index 000000000..0eace4edc --- /dev/null +++ b/services/account/pstore/src/main/resources/db/postgresql/account_index.sql @@ -0,0 +1,12 @@ +-- +-- Copyright 20010 University of California at Berkeley +-- Licensed under the Educational Community License (ECL), Version 2.0. +-- You may not use this file except in compliance with this License. +-- +-- use cspace; +CREATE INDEX index_userid ON accounts_common (userid); +CREATE INDEX index_screen_name ON accounts_common (screen_name); +CREATE INDEX index_email ON accounts_common (email); +CREATE INDEX index_person_ref_name ON accounts_common (person_ref_name); +CREATE INDEX index_update_at ON accounts_common (updated_at); +CREATE INDEX index_status ON accounts_common (status); diff --git a/services/authentication/pstore/build.xml b/services/authentication/pstore/build.xml index dda450f83..267d70d46 100644 --- a/services/authentication/pstore/build.xml +++ b/services/authentication/pstore/build.xml @@ -162,6 +162,7 @@ + @@ -73,7 +77,25 @@ ddl - + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + ${basedir}/../../../build.properties + + + + + + org.codehaus.mojo hibernate3-maven-plugin 2.2 @@ -106,9 +128,14 @@ mysql mysql-connector-java - 5.1.5 + - + + postgresql + postgresql + + + maven-antrun-plugin @@ -117,7 +144,7 @@ process-test-resources - + diff --git a/services/authentication/pstore/src/main/resources/db/postgresql/README.txt b/services/authentication/pstore/src/main/resources/db/postgresql/README.txt new file mode 100644 index 000000000..4967d1a78 --- /dev/null +++ b/services/authentication/pstore/src/main/resources/db/postgresql/README.txt @@ -0,0 +1,11 @@ +The file authentication.sql is basically generated by the gen_ddl ant target. + +However, you must modify the result of that to make the + + DROP TABLE + +statements be + + DROP TABLE IF EXISTS table + +This ensures that first time setup does not fail. diff --git a/services/authentication/pstore/src/main/resources/db/postgresql/authentication.sql b/services/authentication/pstore/src/main/resources/db/postgresql/authentication.sql new file mode 100644 index 000000000..7aff0f078 --- /dev/null +++ b/services/authentication/pstore/src/main/resources/db/postgresql/authentication.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS users; +create table users (username varchar(128) not null, created_at timestamp not null, passwd varchar(128) not null, updated_at timestamp, primary key (username)); diff --git a/services/authority/pom.xml b/services/authority/pom.xml index e50ee41ef..07e93d7dd 100644 --- a/services/authority/pom.xml +++ b/services/authority/pom.xml @@ -133,7 +133,11 @@ mysql mysql-connector-java - + + postgresql + postgresql + + javax.persistence persistence-api diff --git a/services/authorization-mgt/client/pom.xml b/services/authorization-mgt/client/pom.xml index a7ea28dae..b3ca631af 100644 --- a/services/authorization-mgt/client/pom.xml +++ b/services/authorization-mgt/client/pom.xml @@ -153,6 +153,11 @@ mysql-connector-java test + + postgresql + postgresql + test + diff --git a/services/authorization-mgt/import/build.xml b/services/authorization-mgt/import/build.xml index f328d3d41..03eb51d47 100644 --- a/services/authorization-mgt/import/build.xml +++ b/services/authorization-mgt/import/build.xml @@ -146,6 +146,8 @@ + + diff --git a/services/authorization-mgt/import/pom.xml b/services/authorization-mgt/import/pom.xml index ccbc9679c..f6206d5f2 100644 --- a/services/authorization-mgt/import/pom.xml +++ b/services/authorization-mgt/import/pom.xml @@ -123,6 +123,10 @@ mysql mysql-connector-java + + postgresql + postgresql + ch.elca.el4j.modules module-xml_merge-common @@ -133,7 +137,29 @@ cspace-services-authorization-mgt-import + + ../../../build.properties + + + + src/main/resources + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + process-resources + + resources + + + + org.codehaus.mojo exec-maven-plugin @@ -154,6 +180,9 @@ -p does_not_matter -b + ${basedir}/../../common/src/main -edir ${basedir}/target @@ -165,8 +194,13 @@ mysql mysql-connector-java - 5.1.5 + 5.1.5 + + postgresql + postgresql + 8.4-702.jdbc4 + diff --git a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java index c203f80df..aa974c52c 100644 --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java @@ -366,8 +366,8 @@ public class AuthorizationGen { rv.setRoleId(role.getCsid()); roleValues.add(rv); } else { - if (logger.isDebugEnabled() == true) { - logger.debug("Role and Permission tenant ID did not match."); //FIXME: REM - Remove this debug statement. + if (logger.isTraceEnabled() == true) { + logger.trace("Role and Permission tenant ID did not match."); //FIXME: REM - Remove this debug statement. } } } diff --git a/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml b/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml index f394cefdc..7818a1810 100644 --- a/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml +++ b/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml @@ -31,9 +31,9 @@ - - - + + + diff --git a/services/authorization/pstore/pom.xml b/services/authorization/pstore/pom.xml index d63b73452..31fa27fb4 100644 --- a/services/authorization/pstore/pom.xml +++ b/services/authorization/pstore/pom.xml @@ -13,7 +13,7 @@ services.authorization.pstore authorization.sql - ${basedir}/src/main/resources/db/mysql + ${basedir}/src/main/resources/db @@ -36,6 +36,10 @@ mysql mysql-connector-java + + + postgresql + postgresql @@ -68,7 +72,25 @@ ddl - + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + ${basedir}/../../../build.properties + + + + + + org.codehaus.mojo hibernate3-maven-plugin 2.2 @@ -101,9 +123,14 @@ mysql mysql-connector-java - 5.1.5 + - + + postgresql + postgresql + + + maven-antrun-plugin @@ -112,7 +139,7 @@ process-test-resources - + diff --git a/services/authorization/pstore/src/main/resources/db/mysql/acl.sql b/services/authorization/pstore/src/main/resources/db/mysql/acl.sql index a3a07cd16..c84810e79 100644 --- a/services/authorization/pstore/src/main/resources/db/mysql/acl.sql +++ b/services/authorization/pstore/src/main/resources/db/mysql/acl.sql @@ -4,7 +4,7 @@ -- You may not use this file except in compliance with this License. -- -use cspace; +-- use cspace; drop table if exists `acl_entry`; drop table if exists `acl_object_identity`; drop table if exists `acl_sid`; @@ -14,7 +14,7 @@ drop table if exists `acl_class`; -- Table structure for table `acl_class` -- -CREATE TABLE IF NOT EXISTS `acl_class` ( +CREATE TABLE `acl_class` ( `id` bigint(20) NOT NULL auto_increment, `class` varchar(100) NOT NULL, PRIMARY KEY (`id`), @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS `acl_class` ( -- Table structure for table `acl_sid` -- -CREATE TABLE IF NOT EXISTS `acl_sid` ( +CREATE TABLE `acl_sid` ( `id` bigint(20) NOT NULL auto_increment, `principal` tinyint(1) NOT NULL, `sid` varchar(100) NOT NULL, @@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS `acl_sid` ( -- Table structure for table `acl_entry` -- -CREATE TABLE IF NOT EXISTS `acl_entry` ( +CREATE TABLE `acl_entry` ( `id` bigint(20) NOT NULL auto_increment, `acl_object_identity` bigint(20) NOT NULL, `ace_order` int(11) NOT NULL, @@ -71,7 +71,7 @@ CREATE TABLE IF NOT EXISTS `acl_entry` ( -- Table structure for table `acl_object_identity` -- -CREATE TABLE IF NOT EXISTS `acl_object_identity` ( +CREATE TABLE `acl_object_identity` ( `id` bigint(20) NOT NULL auto_increment, `object_id_class` bigint(20) NOT NULL, `object_id_identity` bigint(20) NOT NULL, diff --git a/services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql b/services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql index 7f5fdd70e..3c05b7dec 100644 --- a/services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql +++ b/services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql @@ -3,7 +3,7 @@ -- Licensed under the Educational Community License (ECL), Version 2.0. -- You may not use this file except in compliance with this License. -- -use cspace; +-- use cspace; CREATE INDEX index_rolename ON roles (rolename); CREATE INDEX index_rolegroup ON roles (rolegroup); CREATE INDEX index_tenant_id ON roles (tenant_id); diff --git a/services/authorization/pstore/src/main/resources/db/postgresql/README.txt b/services/authorization/pstore/src/main/resources/db/postgresql/README.txt new file mode 100644 index 000000000..b9cf6f804 --- /dev/null +++ b/services/authorization/pstore/src/main/resources/db/postgresql/README.txt @@ -0,0 +1,32 @@ +The file authorization.sql is basically generated by the gen_ddl ant target. +However, you must modify the result of that to make the + + DROP TABLE + +statements be + + DROP TABLE IF EXISTS table CASCADE + +This ensures that first time setup does not fail, and that later invocations +can deal with dependencies. + +You must also make the + + DROP SEQUENCE + +statements be + + DROP SEQUENCE IF EXISTS + +for similar reasons. + +You must also remove (comment out) the statement (which is superfluous with the CASCADE above): + + alter table permissions_actions drop constraint FK85F82042E2DC84FD; + +When using the account_tenants table on insert, you have to specify "nextval('hibernate_sequence')" +as the value for the HJID column. + +Note that because of the way gen_ddl does its work per-sub-project, there is a single shared +sequence for both this and the authorization.sql script. This should be okay, even if it does +create gaps in what would be a nice sequence for each table. diff --git a/services/authorization/pstore/src/main/resources/db/postgresql/acl.sql b/services/authorization/pstore/src/main/resources/db/postgresql/acl.sql new file mode 100644 index 000000000..41f9276eb --- /dev/null +++ b/services/authorization/pstore/src/main/resources/db/postgresql/acl.sql @@ -0,0 +1,66 @@ +-- +-- Copyright 2010 University of California at Berkeley +-- Licensed under the Educational Community License (ECL), Version 2.0. +-- You may not use this file except in compliance with this License. +-- + +-- use cspace; +DROP TABLE IF EXISTS acl_entry; +DROP TABLE IF EXISTS acl_object_identity; +DROP TABLE IF EXISTS acl_sid; +DROP TABLE IF EXISTS acl_class; + +-- +-- Table structure for table acl_class +-- +CREATE TABLE acl_class( + id bigserial not null primary key, + class varchar(100) not null, + constraint unique_uk_2 unique(class) +); + + +-- +-- Table structure for table acl_sid +-- +CREATE TABLE acl_sid( + id bigserial not null primary key, + principal boolean not null, + sid varchar(100) not null, + constraint unique_uk_1 unique(sid,principal) +); + +-- +-- Table structure for table acl_object_identity +-- +CREATE TABLE acl_object_identity( + id bigserial primary key, + object_id_class bigint not null, + object_id_identity bigint not null, + parent_object bigint, + owner_sid bigint, + entries_inheriting boolean not null, + constraint unique_uk_3 unique(object_id_class,object_id_identity), + constraint acl_obj_id_ibfk_1 foreign key(parent_object) references acl_object_identity(id), + constraint acl_obj_id_ibfk_2 foreign key(object_id_class) references acl_class(id), + constraint acl_obj_id_ibfk_3 foreign key(owner_sid) references acl_sid(id) +); + +-- +-- Table structure for table acl_entry +-- +CREATE TABLE acl_entry( + id bigserial primary key, + acl_object_identity bigint not null, + ace_order int not null, + sid bigint not null, + mask integer not null, + granting boolean not null, + audit_success boolean not null, + audit_failure boolean not null, + constraint unique_uk_4 unique(acl_object_identity,ace_order), + constraint acl_entry_ibfk_1 foreign key(acl_object_identity) + references acl_object_identity(id), + constraint acl_entry_ibfk_2 foreign key(sid) references acl_sid(id) +); + diff --git a/services/authorization/pstore/src/main/resources/db/postgresql/authorization.sql b/services/authorization/pstore/src/main/resources/db/postgresql/authorization.sql new file mode 100644 index 000000000..cdde3c99c --- /dev/null +++ b/services/authorization/pstore/src/main/resources/db/postgresql/authorization.sql @@ -0,0 +1,14 @@ +-- alter table permissions_actions drop constraint FK85F82042E2DC84FD; +DROP TABLE IF EXISTS accounts_roles CASCADE; +DROP TABLE IF EXISTS permissions CASCADE; +DROP TABLE IF EXISTS permissions_actions CASCADE; +DROP TABLE IF EXISTS permissions_roles CASCADE; +DROP TABLE IF EXISTS roles CASCADE; +DROP SEQUENCE IF EXISTS hibernate_sequence; +create table accounts_roles (HJID int8 not null, account_id varchar(128) not null, created_at timestamp not null, role_id varchar(128) not null, role_name varchar(255), screen_name varchar(255), user_id varchar(128) not null, primary key (HJID), unique (account_id, role_id)); +create table permissions (csid varchar(128) not null, action_group varchar(128), attribute_name varchar(128), created_at timestamp not null, description varchar(255), effect varchar(32) not null, resource_name varchar(128) not null, tenant_id varchar(128) not null, updated_at timestamp, primary key (csid)); +create table permissions_actions (HJID int8 not null, name varchar(128) not null, objectIdentity varchar(128) not null, objectIdentityResource varchar(128) not null, ACTIONS_PERMISSION_CSID varchar(128), primary key (HJID)); +create table permissions_roles (HJID int8 not null, actionGroup varchar(255), created_at timestamp not null, permission_id varchar(128) not null, permission_resource varchar(255), role_id varchar(128) not null, role_name varchar(255), primary key (HJID), unique (permission_id, role_id)); +create table roles (csid varchar(128) not null, created_at timestamp not null, description varchar(255), displayname varchar(200) not null, rolegroup varchar(255), rolename varchar(200) not null, tenant_id varchar(128) not null, updated_at timestamp, primary key (csid), unique (rolename, tenant_id), unique (displayname, tenant_id)); +alter table permissions_actions add constraint FK85F82042E2DC84FD foreign key (ACTIONS_PERMISSION_CSID) references permissions; +create sequence hibernate_sequence; diff --git a/services/authorization/pstore/src/main/resources/db/postgresql/authorization_index.sql b/services/authorization/pstore/src/main/resources/db/postgresql/authorization_index.sql new file mode 100644 index 000000000..63b46ef90 --- /dev/null +++ b/services/authorization/pstore/src/main/resources/db/postgresql/authorization_index.sql @@ -0,0 +1,17 @@ +-- +-- Copyright 2010 University of California at Berkeley +-- Licensed under the Educational Community License (ECL), Version 2.0. +-- You may not use this file except in compliance with this License. +-- +-- use cspace; +CREATE INDEX index_rolename ON roles (rolename); +CREATE INDEX index_rolegroup ON roles (rolegroup); +CREATE INDEX index_tenant_id ON roles (tenant_id); + +CREATE INDEX index_user_id ON accounts_roles (user_id); +CREATE INDEX index_account_id ON accounts_roles (account_id); +CREATE INDEX index_acct_role_id ON accounts_roles (role_id); + +CREATE INDEX index_permission_id ON permissions_roles (permission_id); +CREATE INDEX index_perm_role_id ON permissions_roles (role_id); + diff --git a/services/authorization/service/pom.xml b/services/authorization/service/pom.xml index 0d51c7db4..4e9b9b116 100644 --- a/services/authorization/service/pom.xml +++ b/services/authorization/service/pom.xml @@ -148,6 +148,11 @@ mysql-connector-java test + + postgresql + postgresql + test + org.collectionspace.services @@ -166,8 +171,29 @@ cspace-services-authz - - - + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + process-resources + + resources + + + + + + + ../../../build.properties + + + + src/main/resources + true + + diff --git a/services/authorization/service/src/main/resources/applicationContext-authorization.xml b/services/authorization/service/src/main/resources/applicationContext-authorization.xml index ad3c750c2..49d568ceb 100644 --- a/services/authorization/service/src/main/resources/applicationContext-authorization.xml +++ b/services/authorization/service/src/main/resources/applicationContext-authorization.xml @@ -30,8 +30,9 @@ - - + + + diff --git a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java index ee8b42708..7775b8363 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java @@ -32,12 +32,12 @@ public interface IQueryManager { final static String SEARCH_GROUP_CLOSE = ")"; final static String SEARCH_TERM_SEPARATOR = " "; final static String SEARCH_LIKE = " LIKE "; + final static String SEARCH_ILIKE = " ILIKE "; final static String SEARCH_TYPE_KEYWORDS = "keywords"; final static String SEARCH_TYPE_KEYWORDS_KW = "kw"; final static String SEARCH_TYPE_PARTIALTERM = "pt"; final static String SEARCH_TYPE_DOCTYPE = "doctype"; final static String SEARCH_TYPE_INVOCATION = "inv"; - final static String ECM_FULLTEXT_LIKE = "ecm:fulltext" + SEARCH_TERM_SEPARATOR + SEARCH_LIKE; final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR; final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR; diff --git a/services/common/pom.xml b/services/common/pom.xml index 34a1d5bcf..be731bd35 100644 --- a/services/common/pom.xml +++ b/services/common/pom.xml @@ -125,7 +125,11 @@ mysql mysql-connector-java - + + postgresql + postgresql + + javax.persistence persistence-api diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 2ed6c5170..035f41361 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -56,31 +56,31 @@ org.collectionspace.services.common.init.ModifyFieldDatatypes - nuxeo.collectionobjects_common_briefdescriptions + collectionobjects_common_briefdescriptions item LARGETEXT - nuxeo.collectionobjects_common_comments + collectionobjects_common_comments item LARGETEXT - nuxeo.collectionobjects_common_objectproductionreasons + collectionobjects_common_objectproductionreasons item LARGETEXT - nuxeo.collectionobjects_common_ownersreferences + collectionobjects_common_ownersreferences item LARGETEXT - nuxeo.collectionobjects_common_viewersreferences + collectionobjects_common_viewersreferences item LARGETEXT diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index c0dd989d4..a4a5902c8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -21,6 +21,7 @@ import org.collectionspace.services.common.init.IInitHandler; import org.collectionspace.services.common.security.SecurityUtils; import org.collectionspace.services.common.service.*; import org.collectionspace.services.common.storage.JDBCTools; +import org.collectionspace.services.common.storage.DatabaseProductType; import org.collectionspace.services.common.tenant.TenantBindingType; import org.collectionspace.services.common.types.PropertyItemType; import org.collectionspace.services.common.types.PropertyType; @@ -56,10 +57,6 @@ public class ServiceMain { private static final String DEFAULT_ADMIN_PASSWORD = "Administrator"; private static final String DEFAULT_READER_PASSWORD = "reader"; - public static final String NUXEO_REPOSITORY_NAME = "NuxeoDS"; - public static final String CSPACE_REPOSITORY_NAME = "CspaceDS"; - public static final String DEFAULT_REPOSITORY_NAME = CSPACE_REPOSITORY_NAME; - private ServiceMain() { //empty } @@ -176,7 +173,7 @@ public class ServiceMain { conn = getConnection(); // First find or create the tenants String queryTenantSQL = - "SELECT `id`,`name` FROM `tenants`"; + "SELECT id,name FROM tenants"; stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(queryTenantSQL); ArrayList existingTenants = new ArrayList(); @@ -195,7 +192,7 @@ public class ServiceMain { rs.close(); String insertTenantSQL = - "INSERT INTO `tenants` (`id`,`name`,`created_at`) VALUES (?,?, now())"; + "INSERT INTO tenants (id,name,created_at) VALUES (?,?, now())"; pstmt = conn.prepareStatement(insertTenantSQL); // create a statement for(String tId : tenantInfo.keySet()) { if(existingTenants.contains(tId)) { @@ -215,8 +212,8 @@ public class ServiceMain { pstmt.close(); // Second find or create the users String queryUserSQL = - "SELECT `username` FROM `users` WHERE `username` LIKE '" - +TENANT_ADMIN_ACCT_PREFIX+"%' OR `username` LIKE '" + "SELECT username FROM users WHERE username LIKE '" + +TENANT_ADMIN_ACCT_PREFIX+"%' OR username LIKE '" +TENANT_READER_ACCT_PREFIX+"%'"; rs = stmt.executeQuery(queryUserSQL); ArrayList usersInRepo = new ArrayList(); @@ -226,7 +223,7 @@ public class ServiceMain { } rs.close(); String insertUserSQL = - "INSERT INTO `users` (`username`,`passwd`, `created_at`)" + "INSERT INTO users (username,passwd, created_at)" +" VALUES (?,?, now())"; pstmt = conn.prepareStatement(insertUserSQL); // create a statement for(String tName : tenantInfo.values()) { @@ -267,8 +264,8 @@ public class ServiceMain { // Third, create the accounts. Assume that if the users were already there, // then the accounts were as well String insertAccountSQL = - "INSERT INTO `accounts_common` " - + "(`csid`, `email`, `userid`, `status`, `screen_name`, `created_at`) " + "INSERT INTO accounts_common " + + "(csid, email, userid, status, screen_name, created_at) " + "VALUES (?,?,?,'ACTIVE',?, now())"; Hashtable tenantAdminAcctCSIDs = new Hashtable(); Hashtable tenantReaderAcctCSIDs = new Hashtable(); @@ -314,9 +311,19 @@ public class ServiceMain { pstmt.close(); // Fourth, bind accounts to tenants. Assume that if the users were already there, // then the accounts were bound to tenants correctly - String insertAccountTenantSQL = - "INSERT INTO `accounts_tenants` (`TENANTS_ACCOUNTSCOMMON_CSID`,`tenant_id`) " - + "VALUES (?, ?)"; + String insertAccountTenantSQL; + DatabaseProductType databaseProductType = JDBCTools.getDatabaseProductType(); + if (databaseProductType == DatabaseProductType.MYSQL) { + insertAccountTenantSQL = + "INSERT INTO accounts_tenants (TENANTS_ACCOUNTSCOMMON_CSID,tenant_id) " + + " VALUES(?, ?)"; + } else if (databaseProductType == DatabaseProductType.POSTGRESQL) { + insertAccountTenantSQL = + "INSERT INTO accounts_tenants (HJID, TENANTS_ACCOUNTSCOMMON_CSID,tenant_id) " + + " VALUES(nextval('hibernate_sequence'), ?, ?)"; + } else { + throw new Exception("Unrecognized database system."); + } pstmt = conn.prepareStatement(insertAccountTenantSQL); // create a statement for(String tId : tenantInfo.keySet()) { String tName = tenantInfo.get(tId); @@ -345,7 +352,7 @@ public class ServiceMain { // Fifth, fetch and save the default roles String springAdminRoleCSID = null; String querySpringRole = - "SELECT `csid` from `roles` WHERE `rolename`='"+SPRING_ADMIN_ROLE+"'"; + "SELECT csid from roles WHERE rolename='"+SPRING_ADMIN_ROLE+"'"; rs = stmt.executeQuery(querySpringRole); if(rs.next()) { springAdminRoleCSID = rs.getString(1); @@ -355,7 +362,7 @@ public class ServiceMain { } } else { String insertSpringAdminRoleSQL = - "INSERT INTO `roles` (`csid`, `rolename`, `displayName`, `rolegroup`, `created_at`, `tenant_id`) " + "INSERT INTO roles (csid, rolename, displayName, rolegroup, created_at, tenant_id) " + "VALUES ('-1', 'ROLE_SPRING_ADMIN', 'SPRING_ADMIN', 'Spring Security Administrator', now(), '0')"; stmt.executeUpdate(insertSpringAdminRoleSQL); springAdminRoleCSID = "-1"; @@ -366,7 +373,7 @@ public class ServiceMain { } rs.close(); String getRoleCSIDSql = - "SELECT `csid` from `roles` WHERE `tenant_id`=? and `rolename`=?"; + "SELECT csid from roles WHERE tenant_id=? and rolename=?"; pstmt = conn.prepareStatement(getRoleCSIDSql); // create a statement rs = null; Hashtable tenantAdminRoleCSIDs = new Hashtable(); @@ -408,9 +415,18 @@ public class ServiceMain { pstmt.close(); // Sixth, bind the accounts to roles. If the users already existed, // we'll assume they were set up correctly. - String insertAccountRoleSQL = - "INSERT INTO `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`)" - + " VALUES(?, ?, ?, ?, now())"; + String insertAccountRoleSQL; + if (databaseProductType == DatabaseProductType.MYSQL) { + insertAccountRoleSQL = + "INSERT INTO accounts_roles(account_id, user_id, role_id, role_name, created_at)" + +" VALUES(?, ?, ?, ?, now())"; + } else if (databaseProductType == DatabaseProductType.POSTGRESQL) { + insertAccountRoleSQL = + "INSERT INTO accounts_roles(HJID, account_id, user_id, role_id, role_name, created_at)" + +" VALUES(nextval('hibernate_sequence'), ?, ?, ?, ?, now())"; + } else { + throw new Exception("Unrecognized database system."); + } if (logger.isDebugEnabled()) { logger.debug("createDefaultAccounts binding accounts to roles with SQL:\n" +insertAccountRoleSQL); @@ -563,7 +579,7 @@ public class ServiceMain { } private Connection getConnection() throws LoginException, SQLException { - return JDBCTools.getConnection(DEFAULT_REPOSITORY_NAME); + return JDBCTools.getConnection(JDBCTools.CSPACE_REPOSITORY_NAME); } void retrieveAllWorkspaceIds() throws Exception { diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java b/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java index 529bc5f89..59a78daf8 100755 --- a/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java @@ -140,7 +140,7 @@ public class AddIndices extends InitHandler implements IInitHandler { // // If this assumption is no longer valid, we might instead // identify the relevant repository from the table name here. - rows = JDBCTools.executeUpdate(sql, JDBCTools.getNuxeoRepositoryName()); + rows = JDBCTools.executeUpdate(JDBCTools.NUXEO_REPOSITORY_NAME, sql); logger.trace("Index added to column ("+columnName+") on table ("+tableName+")"); } return rows; @@ -184,7 +184,7 @@ public class AddIndices extends InitHandler implements IInitHandler { } try { - // Assumes indicies will only be created at post-init time + // Assumes indices will only be created at post-init time // for the Nuxeo repository. // // To date, for the CSpace repository, indices have typically been @@ -193,7 +193,7 @@ public class AddIndices extends InitHandler implements IInitHandler { // // If this assumption is no longer valid, we might instead // identify the relevant repository from the table name here. - conn = JDBCTools.getConnection(JDBCTools.getNuxeoRepositoryName()); + conn = JDBCTools.getConnection(JDBCTools.NUXEO_REPOSITORY_NAME); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); if (rs.last()) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/ModifyFieldDatatypes.java b/services/common/src/main/java/org/collectionspace/services/common/init/ModifyFieldDatatypes.java index d2638f0df..701cacd97 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/init/ModifyFieldDatatypes.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/ModifyFieldDatatypes.java @@ -74,11 +74,13 @@ public class ModifyFieldDatatypes extends InitHandler implements IInitHandler { if (databaseProductType == DatabaseProductType.MYSQL) { logger.info("Modifying field " + field.getTable() + "." + field.getCol() + " to datatype " + datatype); - sql = "ALTER TABLE " + field.getTable() + " MODIFY COLUMN " + field.getCol() + " " + datatype; + sql = "ALTER TABLE " + field.getTable() + " MODIFY COLUMN " + + field.getCol() + " " + datatype; } else if (databaseProductType == DatabaseProductType.POSTGRESQL) { logger.info("Modifying field " + field.getTable() + "." + field.getCol() + " to datatype " + datatype); - sql = "ALTER TABLE " + field.getTable() + " ALTER COLUMN " + field.getCol() + " " + datatype; + sql = "ALTER TABLE " + field.getTable() + " ALTER COLUMN " + + field.getCol() + " TYPE " + datatype; } else { throw new Exception("Unrecognized database system."); } @@ -91,7 +93,7 @@ public class ModifyFieldDatatypes extends InitHandler implements IInitHandler { // // If this assumption is no longer valid, we might instead // identify the relevant repository from the table name here. - rows = JDBCTools.executeUpdate(sql, JDBCTools.getNuxeoRepositoryName()); + rows = JDBCTools.executeUpdate(JDBCTools.NUXEO_REPOSITORY_NAME, sql); } } catch (Exception e) { throw e; @@ -147,7 +149,7 @@ public class ModifyFieldDatatypes extends InitHandler implements IInitHandler { } try { - conn = JDBCTools.getConnection(JDBCTools.getNuxeoRepositoryName()); + conn = JDBCTools.getConnection(JDBCTools.NUXEO_REPOSITORY_NAME); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java index dec09948a..9d268b0f3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java @@ -39,9 +39,15 @@ import org.nuxeo.ecm.core.client.NuxeoClient; import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.client.IQueryManager; +import org.collectionspace.services.common.storage.DatabaseProductType; +import org.collectionspace.services.common.storage.JDBCTools; public class QueryManagerNuxeoImpl implements IQueryManager { + private static String ECM_FULLTEXT_LIKE = + "ecm:fulltext" + SEARCH_TERM_SEPARATOR + IQueryManager.SEARCH_LIKE; + private static String SEARCH_LIKE_FORM = null; + private final Logger logger = LoggerFactory .getLogger(QueryManagerNuxeoImpl.class); @@ -49,6 +55,22 @@ public class QueryManagerNuxeoImpl implements IQueryManager { private static Pattern nonWordChars = Pattern.compile("[^\\p{L}\\p{M}\\p{N}_']"); private static Pattern unescapedDblQuotes = Pattern.compile("(? params = new HashMap(); + if (csid.equals(CS_CURRENT_USER) == true) { + whereClause = "where userId = :userId"; + params.put("userId", AuthN.get().getUserId()); + } else { + whereClause = "where csid = :csid"; + params.put("csid", csid); + } + + Object account = JpaStorageUtils.getEntity( + "org.collectionspace.services.account.AccountsCommon", whereClause, params); + if (account == null) { + String msg = "User's account not found, csid=" + csid; + throw new DocumentNotFoundException(msg); + } + AccountValue av = new AccountValue(); + av.setAccountId((String)JaxbUtils.getValue(account, "getCsid")); + av.setScreenName((String)JaxbUtils.getValue(account, "getScreenName")); + av.setUserId((String)JaxbUtils.getValue(account, "getUserId")); + // Add the currentTenantId to the payload so the client knows the current tenancy. + av.setTenantId(AuthN.get().getCurrentTenantId()); + + return av; + } catch (Exception e) { + String msg = "User's account is in invalid state, csid=" + csid; + throw new DocumentNotFoundException(msg); + } + } + //FIXME: REM - This method should probably be moved to the AccountPermissionDocumemntHandler /* * This is a prototype for the /accounts/{csid}/permissions GET service call. @@ -186,7 +223,8 @@ public class JpaStorageUtils { // permission -that is, the csid's userId match the currently logged in userId or // that they have read access to the "accounts" resource. // - String userId = getUserId(csid); + AccountValue account = getAccountValue(csid); + String userId = account.getUserId(); String currentUserId = AuthN.get().getUserId(); if (currentUserId.equalsIgnoreCase(userId) == false) { CSpaceResource res = new URIResourceImpl("accounts", "GET"); @@ -203,49 +241,36 @@ public class JpaStorageUtils { AccountPermission result = new AccountPermission(); EntityManagerFactory emf = null; EntityManager em = null; - Iterator tuples = null; + Iterator resultList = null; try { - StringBuilder queryStrBldr = new StringBuilder("SELECT ar, pr FROM " + AccountRoleRel.class.getName() + - " ar, " + PermissionRoleRel.class.getName() + " pr" + - " WHERE ar.roleId = pr.roleId and ar.userId=" + "'" + userId + "'"); + List accountValues = new ArrayList(); + accountValues.add(account); + result.setAccounts(accountValues); + + emf = getEntityManagerFactory(); + em = emf.createEntityManager(); + + StringBuilder permQueryStrBldr = new StringBuilder( + "SELECT DISTINCT pr FROM " + AccountRoleRel.class.getName() + " ar, " + + PermissionRoleRel.class.getName() + " pr" + + " WHERE ar.roleId = pr.roleId and ar.userId=" + "'" + userId + "'"); // // Filter by the permissionResource param if it is set to something // if (permissionResource != null && currentResource != null) { - queryStrBldr.append(" and (pr.permissionResource = " + "'" + currentResource + "'" + + permQueryStrBldr.append(" and (pr.permissionResource = " + "'" + currentResource + "'" + " or pr.permissionResource = " + "'" + permissionResource + "'" + ")"); } - // - // Add group by clause - // - queryStrBldr.append(" group by pr.permissionId"); - - emf = getEntityManagerFactory(); - em = emf.createEntityManager(); - String queryStr = queryStrBldr.toString(); //for debugging + String queryStr = permQueryStrBldr.toString(); //for debugging Query q = em.createQuery(queryStr); - tuples = q.getResultList().iterator(); - if (tuples.hasNext()) { - // - // get the first tuple, extract the AccountRoleRel and set the Account value for the result list - // - Object[] tuple = tuples.next(); - List accountValues = new ArrayList(); - accountValues.add(AuthorizationRoleRel.buildAccountValue((AccountRoleRel)tuple[0])); - // - // Since we extracted the first tuple, we need to store the first perm value as well - // before iterating over the rest of the tuples. - // + resultList = q.getResultList().iterator(); + + if (resultList.hasNext()) { List permissionValues = new ArrayList(); - permissionValues.add(AuthorizationRoleRel.buildPermissionValue((PermissionRoleRel)tuple[1])); - // - // Now finish add the permission values. - // - while (tuples.hasNext()) { - tuple = tuples.next(); - permissionValues.add(AuthorizationRoleRel.buildPermissionValue((PermissionRoleRel)tuple[1])); + while (resultList.hasNext()) { + PermissionRoleRel permRolRel = (PermissionRoleRel)resultList.next(); + permissionValues.add(AuthorizationRoleRel.buildPermissionValue(permRolRel)); } - result.setAccounts(accountValues); result.setPermissions(permissionValues); } } catch (NoResultException nre) { @@ -268,12 +293,6 @@ public class JpaStorageUtils { releaseEntityManagerFactory(emf); } } - /* - * Add the currentTenantId to the payload so the client knows the current - * tenancy. - */ - AccountValue av = result.getAccounts().get(0); - av.setTenantId(AuthN.get().getCurrentTenantId()); return result; } diff --git a/services/id/service/build.xml b/services/id/service/build.xml index 5c024266f..3004393bb 100644 --- a/services/id/service/build.xml +++ b/services/id/service/build.xml @@ -110,18 +110,18 @@ diff --git a/services/id/service/src/main/java/org/collectionspace/services/id/IDServiceJdbcImpl.java b/services/id/service/src/main/java/org/collectionspace/services/id/IDServiceJdbcImpl.java index c6ec9a25a..99a8d1b5e 100644 --- a/services/id/service/src/main/java/org/collectionspace/services/id/IDServiceJdbcImpl.java +++ b/services/id/service/src/main/java/org/collectionspace/services/id/IDServiceJdbcImpl.java @@ -939,13 +939,9 @@ public class IDServiceJdbcImpl implements IDService { logger.debug("> in getJdbcConnection"); - // Providing an empty repository name to getConnection() will cause the - // default repository name to be used. - final String EMPTY_REPOSITORY_NAME = ""; - Connection conn = null; try { - conn = JDBCTools.getConnection(EMPTY_REPOSITORY_NAME); + conn = JDBCTools.getConnection(JDBCTools.NUXEO_REPOSITORY_NAME); } catch (LoginException e) { throw e; } catch (SQLException e) { diff --git a/services/id/service/src/main/resources/db/mysql/create_id_generators_table.sql b/services/id/service/src/main/resources/db/mysql/create_id_generators_table.sql index 5657fbd70..57b950e4a 100644 --- a/services/id/service/src/main/resources/db/mysql/create_id_generators_table.sql +++ b/services/id/service/src/main/resources/db/mysql/create_id_generators_table.sql @@ -25,9 +25,6 @@ * $LastChangedDate$ */ -CREATE DATABASE IF NOT EXISTS `cspace`; -USE `cspace`; - DROP TABLE IF EXISTS `id_generators`; CREATE TABLE `id_generators` ( `csid` varchar(80) PRIMARY KEY, diff --git a/services/id/service/src/main/resources/db/mysql/load_id_generators.sql b/services/id/service/src/main/resources/db/mysql/load_id_generators.sql index 1de199f1e..6b114a881 100644 --- a/services/id/service/src/main/resources/db/mysql/load_id_generators.sql +++ b/services/id/service/src/main/resources/db/mysql/load_id_generators.sql @@ -40,8 +40,6 @@ * initial value is '1'). */ -USE `cspace`; - -- ACCESSION_LOT_NUMBER INSERT INTO `id_generators` diff --git a/services/id/service/src/main/resources/db/postgresql/create_id_generators_table.sql b/services/id/service/src/main/resources/db/postgresql/create_id_generators_table.sql index 47adebafd..23f58c0a2 100644 --- a/services/id/service/src/main/resources/db/postgresql/create_id_generators_table.sql +++ b/services/id/service/src/main/resources/db/postgresql/create_id_generators_table.sql @@ -25,14 +25,6 @@ * $LastChangedDate$ */ --- Will return non-fatal failure result code and error message --- if this database already exists. -CREATE DATABASE cspace WITH ENCODING = 'UTF8'; - --- Explicitly use this database before creating a table within it --- (only works with scripts executed by the 'psql' client). -\c cspace; - DROP TABLE IF EXISTS id_generators; CREATE TABLE id_generators ( @@ -49,10 +41,10 @@ CREATE TABLE id_generators ); -- CREATE UNIQUE INDEX csid_idx ON id_generators USING btree (csid); +CREATE OR REPLACE FUNCTION update_modified_column() +RETURNS TRIGGER AS 'BEGIN NEW.modified = now(); RETURN NEW; END;' language 'plpgsql'; --- Update the timestamp in the 'modified' field when the record is updated. -CREATE OR REPLACE RULE update_idgenerators_timestamp AS - ON UPDATE TO id_generators - DO INSERT INTO id_generators (modified) - VALUES (now()); +CREATE TRIGGER update_customer_modtime BEFORE UPDATE + ON id_generators FOR EACH ROW EXECUTE PROCEDURE + update_modified_column(); diff --git a/services/id/service/src/main/resources/db/postgresql/load_id_generators.sql b/services/id/service/src/main/resources/db/postgresql/load_id_generators.sql index 1f554e4df..217609ff4 100644 --- a/services/id/service/src/main/resources/db/postgresql/load_id_generators.sql +++ b/services/id/service/src/main/resources/db/postgresql/load_id_generators.sql @@ -40,9 +40,6 @@ * initial value is '1'). */ --- (Only works with scripts executed by the 'psql' client.) -\c cspace; - -- ACCESSION_LOT_NUMBER INSERT INTO id_generators diff --git a/services/pom.xml b/services/pom.xml index 1ebd6ad32..b31c630aa 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -97,6 +97,12 @@ + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + org.apache.maven.plugins maven-site-plugin @@ -342,6 +348,11 @@ mysql-connector-java 5.1.5 + + postgresql + postgresql + 8.4-702.jdbc4 + diff --git a/src/main/resources/db/postgresql/init_db.sql b/src/main/resources/db/postgresql/init_db.sql index 25aece532..8df78c4fe 100644 --- a/src/main/resources/db/postgresql/init_db.sql +++ b/src/main/resources/db/postgresql/init_db.sql @@ -6,6 +6,7 @@ DROP database IF EXISTS nuxeo; DROP USER IF EXISTS nuxeo; DROP USER IF EXISTS cspace; DROP USER IF EXISTS jboss; +DROP USER IF EXISTS reader; CREATE ROLE @DB_NUXEO_USER@ WITH PASSWORD '@DB_NUXEO_PASSWORD@' LOGIN; CREATE ROLE @DB_CSPACE_USER@ WITH PASSWORD '@DB_CSPACE_PASSWORD@' LOGIN;