diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index c8b1014713..8e19af941c 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -45,6 +45,9 @@ + + + @@ -110,6 +113,7 @@ + @@ -117,7 +121,6 @@ - diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql index 9d94cff7a3..b282dc6698 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql @@ -153,90 +153,6 @@ CREATE TABLE alf_authority_alias CONSTRAINT fk_alf_autha_ali FOREIGN KEY (alias_id) REFERENCES alf_authority (id) ) ENGINE=InnoDB; -CREATE TABLE alf_audit_config -( - id BIGINT NOT NULL AUTO_INCREMENT, - config_url TEXT NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -CREATE TABLE alf_audit_date -( - id BIGINT NOT NULL AUTO_INCREMENT, - date_only date NOT NULL, - day_of_year INTEGER NOT NULL, - day_of_month INTEGER NOT NULL, - day_of_week INTEGER NOT NULL, - week_of_year INTEGER NOT NULL, - week_of_month INTEGER NOT NULL, - month INTEGER NOT NULL, - quarter INTEGER NOT NULL, - half_year INTEGER NOT NULL, - full_year INTEGER NOT NULL, - PRIMARY KEY (id), - KEY idx_alf_adtd_woy (week_of_year), - KEY idx_alf_adtd_fy (full_year), - KEY idx_alf_adtd_q (quarter), - KEY idx_alf_adtd_wom (week_of_month), - KEY idx_alf_adtd_dom (day_of_month), - KEY idx_alf_adtd_doy (day_of_year), - KEY idx_alf_adtd_dow (day_of_week), - KEY idx_alf_adtd_m (month), - KEY idx_alf_adtd_hy (half_year), - KEY idx_alf_adtd_dat (date_only) -) ENGINE=InnoDB; - -CREATE TABLE alf_audit_source -( - id BIGINT NOT NULL AUTO_INCREMENT, - application VARCHAR(255) NOT NULL, - service VARCHAR(255), - method VARCHAR(255), - PRIMARY KEY (id), - KEY idx_alf_adts_met (method), - KEY idx_alf_adts_ser (service), - KEY idx_alf_adts_app (application) -) ENGINE=InnoDB; - -CREATE TABLE alf_audit_fact -( - id BIGINT NOT NULL AUTO_INCREMENT, - user_id VARCHAR(255) NOT NULL, - timestamp DATETIME NOT NULL, - transaction_id VARCHAR(56) NOT NULL, - session_id VARCHAR(56), - store_protocol VARCHAR(50), - store_id VARCHAR(100), - node_uuid VARCHAR(36), - path TEXT, - filtered BIT NOT NULL, - return_val TEXT, - arg_1 TEXT, - arg_2 TEXT, - arg_3 TEXT, - arg_4 TEXT, - arg_5 TEXT, - fail BIT NOT NULL, - serialized_url TEXT, - exception_message TEXT, - host_address TEXT, - client_address TEXT, - message_text TEXT, - audit_date_id BIGINT NOT NULL, - audit_conf_id BIGINT NOT NULL, - audit_source_id BIGINT NOT NULL, - PRIMARY KEY (id), - KEY idx_alf_adtf_ref (store_protocol, store_id, node_uuid), - KEY idx_alf_adtf_usr (user_id), - KEY fk_alf_adtf_src (audit_source_id), - KEY fk_alf_adtf_date (audit_date_id), - KEY fk_alf_adtf_conf (audit_conf_id), - KEY idx_alf_adtf_pth (path(128)), - CONSTRAINT fk_alf_adtf_conf FOREIGN KEY (audit_conf_id) REFERENCES alf_audit_config (id), - CONSTRAINT fk_alf_adtf_date FOREIGN KEY (audit_date_id) REFERENCES alf_audit_date (id), - CONSTRAINT fk_alf_adtf_src FOREIGN KEY (audit_source_id) REFERENCES alf_audit_source (id) -) ENGINE=InnoDB; - CREATE TABLE alf_server ( id BIGINT NOT NULL AUTO_INCREMENT, diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ActivityTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ActivityTables.sql index 7349b66e7f..989dda1113 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ActivityTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ActivityTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_activity_feed_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_activity_feed ( id INT8 NOT NULL, @@ -27,8 +28,8 @@ CREATE INDEX feed_postuserid_idx ON alf_activity_feed (post_user_id); CREATE INDEX feed_feeduserid_idx ON alf_activity_feed (feed_user_id); CREATE INDEX feed_sitenetwork_idx ON alf_activity_feed (site_network); CREATE INDEX feed_activityformat_idx ON alf_activity_feed (activity_format); -CREATE SEQUENCE alf_activity_feed_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_activity_feed_control_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_activity_feed_control ( id INT8 NOT NULL, @@ -39,8 +40,8 @@ CREATE TABLE alf_activity_feed_control PRIMARY KEY (id) ); CREATE INDEX feedctrl_feeduserid_idx ON alf_activity_feed_control (feed_user_id); -CREATE SEQUENCE alf_activity_feed_control_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_activity_post_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_activity_post ( sequence_id INT8 NOT NULL, @@ -57,7 +58,6 @@ CREATE TABLE alf_activity_post ); CREATE INDEX post_jobtasknode_idx ON alf_activity_post (job_task_node); CREATE INDEX post_status_idx ON alf_activity_post (status); -CREATE SEQUENCE alf_activity_post_seq START WITH 1 INCREMENT BY 1; -- diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AuditTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AuditTables.sql index d59151d75e..d1fccfd477 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AuditTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AuditTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_audit_model_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_audit_model ( id INT8 NOT NULL, @@ -16,9 +17,9 @@ CREATE TABLE alf_audit_model PRIMARY KEY (id) ); CREATE UNIQUE INDEX idx_alf_aud_mod_cr ON alf_audit_model(content_crc); +CREATE INDEX fk_alf_aud_mod_cd ON alf_audit_model(content_data_id); -CREATE SEQUENCE alf_audit_model_seq START WITH 1 INCREMENT BY 1; - +CREATE SEQUENCE alf_audit_app_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_audit_app ( id INT8 NOT NULL, @@ -31,8 +32,10 @@ CREATE TABLE alf_audit_app CONSTRAINT fk_alf_aud_app_dis FOREIGN KEY (disabled_paths_id) REFERENCES alf_prop_root (id), PRIMARY KEY (id) ); -CREATE SEQUENCE alf_audit_app_seq START WITH 1 INCREMENT BY 1; +CREATE INDEX fk_alf_aud_app_mod ON alf_audit_app(audit_model_id); +CREATE INDEX fk_alf_aud_app_dis ON alf_audit_app(disabled_paths_id); +CREATE SEQUENCE alf_audit_entry_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_audit_entry ( id INT8 NOT NULL, @@ -46,8 +49,9 @@ CREATE TABLE alf_audit_entry PRIMARY KEY (id) ); CREATE INDEX idx_alf_aud_ent_tm ON alf_audit_entry(audit_time); - -CREATE SEQUENCE alf_audit_entry_seq START WITH 1 INCREMENT BY 1; +CREATE INDEX fk_alf_aud_ent_app ON alf_audit_entry(audit_app_id); +CREATE INDEX fk_alf_aud_ent_use ON alf_audit_entry(audit_user_id); +CREATE INDEX fk_alf_aud_ent_pro ON alf_audit_entry(audit_values_id); -- -- Record script finish diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AvmTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AvmTables.sql index 8e2cc746b4..b3096998e2 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AvmTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-AvmTables.sql @@ -47,6 +47,7 @@ primary key (node_id, qname_id) ); + create sequence avm_nodes_seq start with 1 increment by 1; create table avm_nodes ( id INT8 not null, class_type varchar(20) not null, @@ -75,8 +76,7 @@ primary key (id) ); - create sequence avm_nodes_seq start with 1 increment by 1; - + create sequence avm_store_properties_seq start with 1 increment by 1; create table avm_store_properties ( id INT8 not null, avm_store_id INT8, @@ -92,9 +92,8 @@ serializable_value BYTEA, primary key (id) ); - - create sequence avm_store_properties_seq start with 1 increment by 1; - + + create sequence avm_stores_seq start with 1 increment by 1; create table avm_stores ( id INT8 not null, vers INT8 not null, @@ -105,8 +104,6 @@ primary key (id) ); - create sequence avm_stores_seq start with 1 increment by 1; - create table avm_version_layered_node_entry ( version_root_id INT8 not null, md5sum varchar(32) not null, @@ -114,6 +111,7 @@ primary key (version_root_id, md5sum) ); + create sequence avm_version_roots_seq start with 1 increment by 1; create table avm_version_roots ( id INT8 not null, version_id INT4 not null, @@ -127,8 +125,6 @@ unique (version_id, avm_store_id) ); - create sequence avm_version_roots_seq start with 1 increment by 1; - alter table avm_aspects add constraint fk_avm_nasp_n foreign key (node_id) diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ContentTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ContentTables.sql index 4ec31c9564..5329e476d6 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ContentTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-ContentTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_mimetype_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_mimetype ( id INT8 NOT NULL, @@ -15,8 +16,8 @@ CREATE TABLE alf_mimetype PRIMARY KEY (id), UNIQUE (mimetype_str) ); -CREATE SEQUENCE alf_mimetype_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_encoding_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_encoding ( id INT8 NOT NULL, @@ -25,11 +26,11 @@ CREATE TABLE alf_encoding PRIMARY KEY (id), UNIQUE (encoding_str) ); -CREATE SEQUENCE alf_encoding_seq START WITH 1 INCREMENT BY 1; -- This table may exist during upgrades, but must be removed. -- The drop statement is therefore optional. DROP TABLE alf_content_url; --(optional) +CREATE SEQUENCE alf_content_url_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_content_url ( id INT8 NOT NULL, @@ -42,8 +43,8 @@ CREATE TABLE alf_content_url ); CREATE UNIQUE INDEX idx_alf_conturl_cr ON alf_content_url (content_url_short, content_url_crc); CREATE INDEX idx_alf_conturl_ot ON alf_content_url (orphan_time); -CREATE SEQUENCE alf_content_url_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_content_data_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_content_data ( id INT8 NOT NULL, @@ -58,7 +59,10 @@ CREATE TABLE alf_content_data CONSTRAINT fk_alf_cont_loc FOREIGN KEY (content_locale_id) REFERENCES alf_locale (id), PRIMARY KEY (id) ); -CREATE SEQUENCE alf_content_data_seq START WITH 1 INCREMENT BY 1; +CREATE INDEX fk_alf_cont_url ON alf_content_data (content_url_id); +CREATE INDEX fk_alf_cont_mim ON alf_content_data (content_mimetype_id); +CREATE INDEX fk_alf_cont_enc ON alf_content_data (content_encoding_id); +CREATE INDEX fk_alf_cont_loc ON alf_content_data (content_locale_id); -- -- Record script finish diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-LockTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-LockTables.sql index d9091725fd..4d8ba8beff 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-LockTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-LockTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_lock_resource_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_lock_resource ( id INT8 NOT NULL, @@ -18,8 +19,7 @@ CREATE TABLE alf_lock_resource ); CREATE UNIQUE INDEX idx_alf_lockr_key ON alf_lock_resource (qname_ns_id, qname_localname); -CREATE SEQUENCE alf_lock_resource_seq START WITH 1 INCREMENT BY 1; - +CREATE SEQUENCE alf_lock_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_lock ( id INT8 NOT NULL, @@ -34,8 +34,8 @@ CREATE TABLE alf_lock PRIMARY KEY (id) ); CREATE UNIQUE INDEX idx_alf_lock_key ON alf_lock (shared_resource_id, excl_resource_id); +CREATE INDEX fk_alf_lock_excl ON alf_lock (excl_resource_id); -CREATE SEQUENCE alf_lock_seq START WITH 1 INCREMENT BY 1; -- -- Record script finish -- diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-PropertyValueTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-PropertyValueTables.sql index 4a5b786aad..6a08bb2eb9 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-PropertyValueTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-PropertyValueTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_prop_class_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_class ( id INT8 NOT NULL, @@ -18,8 +19,6 @@ CREATE TABLE alf_prop_class CREATE UNIQUE INDEX idx_alf_propc_crc ON alf_prop_class(java_class_name_crc, java_class_name_short); CREATE INDEX idx_alf_propc_clas ON alf_prop_class(java_class_name); -CREATE SEQUENCE alf_prop_class_seq START WITH 1 INCREMENT BY 1; - CREATE TABLE alf_prop_date_value ( date_value INT8 NOT NULL, @@ -36,6 +35,7 @@ CREATE TABLE alf_prop_date_value ); CREATE INDEX idx_alf_propdt_dt ON alf_prop_date_value(full_year, month_of_year, day_of_month); +CREATE SEQUENCE alf_prop_double_value_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_double_value ( id INT8 NOT NULL, @@ -44,9 +44,8 @@ CREATE TABLE alf_prop_double_value ); CREATE UNIQUE INDEX idx_alf_propd_val ON alf_prop_double_value(double_value); -CREATE SEQUENCE alf_prop_double_value_seq START WITH 1 INCREMENT BY 1; - -- Stores unique, case-sensitive string values -- +CREATE SEQUENCE alf_prop_string_value_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_string_value ( id INT8 NOT NULL, @@ -58,16 +57,15 @@ CREATE TABLE alf_prop_string_value CREATE INDEX idx_alf_props_str ON alf_prop_string_value(string_value); CREATE UNIQUE INDEX idx_alf_props_crc ON alf_prop_string_value(string_end_lower, string_crc); -CREATE SEQUENCE alf_prop_string_value_seq START WITH 1 INCREMENT BY 1; - +CREATE SEQUENCE alf_prop_serializable_value_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_serializable_value ( id INT8 NOT NULL, serializable_value BYTEA NOT NULL, PRIMARY KEY (id) ); -CREATE SEQUENCE alf_prop_serializable_value_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_prop_value_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_value ( id INT8 NOT NULL, @@ -79,15 +77,13 @@ CREATE TABLE alf_prop_value CREATE INDEX idx_alf_propv_per ON alf_prop_value(persisted_type, long_value); CREATE UNIQUE INDEX idx_alf_propv_act ON alf_prop_value(actual_type_id, long_value); -CREATE SEQUENCE alf_prop_value_seq START WITH 1 INCREMENT BY 1; - +CREATE SEQUENCE alf_prop_root_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_root ( id INT8 NOT NULL, version INT4 NOT NULL, PRIMARY KEY (id) ); -CREATE SEQUENCE alf_prop_root_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_link ( @@ -102,7 +98,10 @@ CREATE TABLE alf_prop_link PRIMARY KEY (root_prop_id, contained_in, prop_index) ); CREATE INDEX idx_alf_propln_for ON alf_prop_link(root_prop_id, key_prop_id, value_prop_id); +CREATE INDEX fk_alf_propln_key ON alf_prop_link(key_prop_id); +CREATE INDEX fk_alf_propln_val ON alf_prop_link(value_prop_id); +CREATE SEQUENCE alf_prop_unique_ctx_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_prop_unique_ctx ( id INT8 NOT NULL, @@ -118,8 +117,9 @@ CREATE TABLE alf_prop_unique_ctx PRIMARY KEY (id) ); CREATE UNIQUE INDEX idx_alf_propuctx ON alf_prop_unique_ctx(value1_prop_id, value2_prop_id, value3_prop_id); - -CREATE SEQUENCE alf_prop_unique_ctx_seq START WITH 1 INCREMENT BY 1; +CREATE INDEX fk_alf_propuctx_v2 ON alf_prop_unique_ctx(value2_prop_id); +CREATE INDEX fk_alf_propuctx_v3 ON alf_prop_unique_ctx(value3_prop_id); +CREATE INDEX fk_alf_propuctx_p1 ON alf_prop_unique_ctx(prop1_id); -- -- Record script finish diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql index baa18b0248..b36241634e 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql @@ -23,6 +23,7 @@ CREATE TABLE alf_applied_patch PRIMARY KEY (id) ); +CREATE SEQUENCE alf_namespace_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_namespace ( id INT8 NOT NULL, @@ -30,10 +31,9 @@ CREATE TABLE alf_namespace uri VARCHAR(100) NOT NULL, PRIMARY KEY (id) ); - CREATE UNIQUE INDEX uri ON alf_namespace (uri); -CREATE SEQUENCE alf_namespace_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_qname_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_qname ( id INT8 NOT NULL, @@ -45,8 +45,8 @@ CREATE TABLE alf_qname ); CREATE UNIQUE INDEX ns_id ON alf_qname (ns_id, local_name); CREATE INDEX fk_alf_qname_ns ON alf_qname (ns_id); -CREATE SEQUENCE alf_qname_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_permission_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_permission ( id INT8 NOT NULL, @@ -58,8 +58,8 @@ CREATE TABLE alf_permission ); CREATE UNIQUE INDEX type_qname_id ON alf_permission (type_qname_id, name); CREATE INDEX fk_alf_perm_tqn ON alf_permission (type_qname_id); -CREATE SEQUENCE alf_permission_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_ace_context_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_ace_context ( id INT8 NOT NULL, @@ -69,8 +69,8 @@ CREATE TABLE alf_ace_context kvp_context VARCHAR(1024), PRIMARY KEY (id) ); -CREATE SEQUENCE alf_ace_context_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_authority_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_authority ( id INT8 NOT NULL, @@ -81,8 +81,8 @@ CREATE TABLE alf_authority ); CREATE UNIQUE INDEX authority ON alf_authority (authority, crc); CREATE INDEX idx_alf_auth_aut ON alf_authority (authority); -CREATE SEQUENCE alf_authority_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_access_control_entry_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_access_control_entry ( id INT8 NOT NULL, @@ -101,16 +101,16 @@ CREATE UNIQUE INDEX permission_id ON alf_access_control_entry (permission_id, au CREATE INDEX fk_alf_ace_ctx ON alf_access_control_entry (context_id); CREATE INDEX fk_alf_ace_perm ON alf_access_control_entry (permission_id); CREATE INDEX fk_alf_ace_auth ON alf_access_control_entry (authority_id); -CREATE SEQUENCE alf_access_control_entry_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_acl_change_set_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_acl_change_set ( id INT8 NOT NULL, version INT8 NOT NULL, PRIMARY KEY (id) ); -CREATE SEQUENCE alf_acl_change_set_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_access_control_list_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_access_control_list ( id INT8 NOT NULL, @@ -131,8 +131,8 @@ CREATE TABLE alf_access_control_list CREATE UNIQUE INDEX acl_id ON alf_access_control_list (acl_id, latest, acl_version); CREATE INDEX idx_alf_acl_inh ON alf_access_control_list (inherits, inherits_from); CREATE INDEX fk_alf_acl_acs ON alf_access_control_list (acl_change_set); -CREATE SEQUENCE alf_access_control_list_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_acl_member_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_acl_member ( id INT8 NOT NULL, @@ -147,8 +147,8 @@ CREATE TABLE alf_acl_member CREATE UNIQUE INDEX aclm_acl_id ON alf_acl_member (acl_id, ace_id, pos); CREATE INDEX fk_alf_aclm_acl ON alf_acl_member (acl_id); CREATE INDEX fk_alf_aclm_ace ON alf_acl_member (ace_id); -CREATE SEQUENCE alf_acl_member_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_authority_alias_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_authority_alias ( id INT8 NOT NULL, @@ -162,96 +162,8 @@ CREATE TABLE alf_authority_alias CREATE UNIQUE INDEX auth_id ON alf_authority_alias (auth_id, alias_id); CREATE INDEX fk_alf_autha_ali ON alf_authority_alias (alias_id); CREATE INDEX fk_alf_autha_aut ON alf_authority_alias (auth_id); -CREATE SEQUENCE alf_authority_alias_seq START WITH 1 INCREMENT BY 1; - -CREATE TABLE alf_audit_config -( - id INT8 NOT NULL, - config_url VARCHAR(1024) NOT NULL, - PRIMARY KEY (id) -); -CREATE SEQUENCE alf_audit_config_seq START WITH 1 INCREMENT BY 1; - -CREATE TABLE alf_audit_date -( - id INT8 NOT NULL, - date_only DATE NOT NULL, - day_of_year INT4 NOT NULL, - day_of_month INT4 NOT NULL, - day_of_week INT4 NOT NULL, - week_of_year INT4 NOT NULL, - week_of_month INT4 NOT NULL, - month INT4 NOT NULL, - quarter INT4 NOT NULL, - half_year INT4 NOT NULL, - full_year INT4 NOT NULL, - PRIMARY KEY (id) -); -CREATE INDEX idx_alf_adtd_woy ON alf_audit_date (week_of_year); -CREATE INDEX idx_alf_adtd_fy ON alf_audit_date (full_year); -CREATE INDEX idx_alf_adtd_q ON alf_audit_date (quarter); -CREATE INDEX idx_alf_adtd_wom ON alf_audit_date (week_of_month); -CREATE INDEX idx_alf_adtd_dom ON alf_audit_date (day_of_month); -CREATE INDEX idx_alf_adtd_doy ON alf_audit_date (day_of_year); -CREATE INDEX idx_alf_adtd_dow ON alf_audit_date (day_of_week); -CREATE INDEX idx_alf_adtd_m ON alf_audit_date (month); -CREATE INDEX idx_alf_adtd_hy ON alf_audit_date (half_year); -CREATE INDEX idx_alf_adtd_dat ON alf_audit_date (date_only); -CREATE SEQUENCE alf_audit_date_seq START WITH 1 INCREMENT BY 1; - -CREATE TABLE alf_audit_source -( - id INT8 NOT NULL, - application VARCHAR(255) NOT NULL, - service VARCHAR(255), - method VARCHAR(255), - PRIMARY KEY (id) -); -CREATE INDEX idx_alf_adts_met ON alf_audit_source (method); -CREATE INDEX idx_alf_adts_ser ON alf_audit_source (service); -CREATE INDEX idx_alf_adts_app ON alf_audit_source (application); -CREATE SEQUENCE alf_audit_source_seq START WITH 1 INCREMENT BY 1; - -CREATE TABLE alf_audit_fact -( - id INT8 NOT NULL, - user_id VARCHAR(255) NOT NULL, - timestamp TIMESTAMP NOT NULL, - transaction_id VARCHAR(56) NOT NULL, - session_id VARCHAR(56), - store_protocol VARCHAR(50), - store_id VARCHAR(100), - node_uuid VARCHAR(36), - path VARCHAR(1024), - filtered BOOL NOT NULL, - return_val VARCHAR(1024), - arg_1 VARCHAR(1024), - arg_2 VARCHAR(1024), - arg_3 VARCHAR(1024), - arg_4 VARCHAR(1024), - arg_5 VARCHAR(1024), - fail BOOL NOT NULL, - serialized_url VARCHAR(1024), - exception_message VARCHAR(1024), - host_address VARCHAR(1024), - client_address VARCHAR(1024), - message_text VARCHAR(1024), - audit_date_id INT8 NOT NULL, - audit_conf_id INT8 NOT NULL, - audit_source_id INT8 NOT NULL, - PRIMARY KEY (id), - CONSTRAINT fk_alf_adtf_conf FOREIGN KEY (audit_conf_id) REFERENCES alf_audit_config (id), - CONSTRAINT fk_alf_adtf_date FOREIGN KEY (audit_date_id) REFERENCES alf_audit_date (id), - CONSTRAINT fk_alf_adtf_src FOREIGN KEY (audit_source_id) REFERENCES alf_audit_source (id) -); -CREATE INDEX idx_alf_adtf_ref ON alf_audit_fact (store_protocol, store_id, node_uuid); -CREATE INDEX idx_alf_adtf_usr ON alf_audit_fact (user_id); -CREATE INDEX fk_alf_adtf_src ON alf_audit_fact (audit_source_id); -CREATE INDEX fk_alf_adtf_date ON alf_audit_fact (audit_date_id); -CREATE INDEX fk_alf_adtf_conf ON alf_audit_fact (audit_conf_id); -CREATE INDEX idx_alf_adtf_pth ON alf_audit_fact (path); -CREATE SEQUENCE alf_audit_fact_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_server_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_server ( id INT8 NOT NULL, @@ -260,8 +172,8 @@ CREATE TABLE alf_server PRIMARY KEY (id) ); CREATE UNIQUE INDEX ip_address ON alf_server (ip_address); -CREATE SEQUENCE alf_server_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_transaction_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_transaction ( id INT8 NOT NULL, @@ -274,8 +186,8 @@ CREATE TABLE alf_transaction ); CREATE INDEX idx_alf_txn_ctms ON alf_transaction (commit_time_ms); CREATE INDEX fk_alf_txn_svr ON alf_transaction (server_id); -CREATE SEQUENCE alf_transaction_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_store_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_store ( id INT8 NOT NULL, @@ -286,8 +198,8 @@ CREATE TABLE alf_store PRIMARY KEY (id) ); CREATE UNIQUE INDEX protocol ON alf_store (protocol, identifier); -CREATE SEQUENCE alf_store_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_node_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_node ( id INT8 NOT NULL, @@ -315,11 +227,11 @@ CREATE INDEX fk_alf_node_acl ON alf_node (acl_id); CREATE INDEX fk_alf_node_txn ON alf_node (transaction_id); CREATE INDEX fk_alf_node_store ON alf_node (store_id); CREATE INDEX fk_alf_node_tqn ON alf_node (type_qname_id); -CREATE SEQUENCE alf_node_seq START WITH 1 INCREMENT BY 1; CREATE INDEX fk_alf_store_root ON alf_store (root_node_id); ALTER TABLE alf_store ADD CONSTRAINT fk_alf_store_root FOREIGN KEY (root_node_id) REFERENCES alf_node (id); +CREATE SEQUENCE alf_child_assoc_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_child_assoc ( id INT8 NOT NULL, @@ -347,8 +259,8 @@ CREATE INDEX fk_alf_cass_tqn ON alf_child_assoc (type_qname_id); CREATE INDEX fk_alf_cass_qnns ON alf_child_assoc (qname_ns_id); CREATE INDEX idx_alf_cass_qncrc ON alf_child_assoc (qname_crc, type_qname_id, parent_node_id); CREATE INDEX idx_alf_cass_pri ON alf_child_assoc (parent_node_id, is_primary, child_node_id); -CREATE SEQUENCE alf_child_assoc_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_locale_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_locale ( id INT8 NOT NULL, @@ -357,8 +269,8 @@ CREATE TABLE alf_locale PRIMARY KEY (id) ); CREATE UNIQUE INDEX locale_str ON alf_locale (locale_str); -CREATE SEQUENCE alf_locale_seq START WITH 1 INCREMENT BY 1; +CREATE SEQUENCE alf_attributes_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_attributes ( id INT8 NOT NULL, @@ -378,7 +290,6 @@ CREATE TABLE alf_attributes CONSTRAINT fk_alf_attr_acl FOREIGN KEY (acl_id) REFERENCES alf_access_control_list (id) ); CREATE INDEX fk_alf_attr_acl ON alf_attributes (acl_id); -CREATE SEQUENCE alf_attributes_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_global_attributes ( @@ -425,6 +336,7 @@ CREATE TABLE alf_node_aspects CREATE INDEX fk_alf_nasp_n ON alf_node_aspects (node_id); CREATE INDEX fk_alf_nasp_qn ON alf_node_aspects (qname_id); +CREATE SEQUENCE alf_node_assoc_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_node_assoc ( id INT8 NOT NULL, @@ -441,7 +353,6 @@ CREATE UNIQUE INDEX source_node_id ON alf_node_assoc (source_node_id, target_nod CREATE INDEX fk_alf_nass_snode ON alf_node_assoc (source_node_id); CREATE INDEX fk_alf_nass_tnode ON alf_node_assoc (target_node_id); CREATE INDEX fk_alf_nass_tqn ON alf_node_assoc (type_qname_id); -CREATE SEQUENCE alf_node_assoc_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_node_properties ( diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-UsageTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-UsageTables.sql index 607e81cb29..0d7952b8bb 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-UsageTables.sql +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-UsageTables.sql @@ -7,6 +7,7 @@ -- Please contact support@alfresco.com if you need assistance with the upgrade. -- +CREATE SEQUENCE alf_usage_delta_seq START WITH 1 INCREMENT BY 1; -- (optional) CREATE TABLE alf_usage_delta ( id INT8 NOT NULL, @@ -17,7 +18,6 @@ CREATE TABLE alf_usage_delta CONSTRAINT fk_alf_usaged_n FOREIGN KEY (node_id) REFERENCES alf_node (id) ); -- (optional) CREATE INDEX fk_alf_usaged_n ON alf_usage_delta (node_id); -- (optional) -CREATE SEQUENCE alf_usage_delta_seq START WITH 1 INCREMENT BY 1; -- (optional) -- -- Record script finish diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AddFKIndexes.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AddFKIndexes.sql index 45b30fd23e..1b9a99cc79 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AddFKIndexes.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AddFKIndexes.sql @@ -23,10 +23,6 @@ CREATE INDEX fk_alf_aclm_ace ON alf_acl_member (ace_id); CREATE INDEX fk_alf_attr_acl ON alf_attributes (acl_id); -CREATE INDEX fk_alf_adtf_src ON alf_audit_fact (audit_source_id); -CREATE INDEX fk_alf_adtf_date ON alf_audit_fact (audit_date_id); -CREATE INDEX fk_alf_adtf_conf ON alf_audit_fact (audit_conf_id); - CREATE INDEX fk_alf_autha_ali ON alf_authority_alias (alias_id); CREATE INDEX fk_alf_autha_aut ON alf_authority_alias (auth_id); diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql deleted file mode 100644 index d260e34b37..0000000000 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql +++ /dev/null @@ -1,23 +0,0 @@ --- --- Title: Ensure the audit table path column is indexed --- Database: Generic --- Since: V2.1 Schema 82 --- Author: Andy Hind --- --- Please contact support@alfresco.com if you need assistance with the upgrade. --- --- Path was previously unused and unindex - new we use it the index is required. - -CREATE INDEX idx_alf_adtf_pth ON alf_audit_fact (path); - --- --- Record script finish --- -DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.1-AuditPathIndex'; -INSERT INTO alf_applied_patch - (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) - VALUES - ( - 'patch.db-V2.1-AuditPathIndex', 'Manually executed script upgrade V2.1: Ensure existence of audit path index', - 0, 81, -1, 82, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed' - ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql deleted file mode 100644 index b02dfc3019..0000000000 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql +++ /dev/null @@ -1,23 +0,0 @@ --- --- Title: Ensure the audit table path column is indexed --- Database: Generic --- Since: V2.1 Schema 82 --- Author: Andy Hind --- --- Please contact support@alfresco.com if you need assistance with the upgrade. --- --- Path was previously unused and unindex - new we use it the index is required. - -CREATE INDEX idx_alf_adtf_pth ON alf_audit_fact (path(128)); - --- --- Record script finish --- -DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.1-AuditPathIndex'; -INSERT INTO alf_applied_patch - (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) - VALUES - ( - 'patch.db-V2.1-AuditPathIndex', 'Manually executed script upgrade V2.1: Ensure existence of audit path index', - 0, 81, -1, 82, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed' - ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-0-create-missing-tables.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-0-create-missing-tables.sql index a912a34e73..8b22cd627a 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-0-create-missing-tables.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-0-create-missing-tables.sql @@ -10,11 +10,6 @@ -- to simplify subsequent upgrade scripts. -- --- Fix alf_audit_date column names - -ALTER TABLE alf_audit_date CHANGE COLUMN halfYear half_year INTEGER NOT NULL; -ALTER TABLE alf_audit_date CHANGE COLUMN year full_year INTEGER NOT NULL; - -- create other new tables create table avm_aspects ( diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-from-2.1.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-from-2.1.sql index 9f7bc755e3..7ef8ec187f 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-from-2.1.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.MySQLInnoDBDialect/upgrade-from-2.1.sql @@ -966,56 +966,6 @@ ALTER TABLE alf_attributes ADD INDEX fk_alf_attr_acl (acl_id) ; -ALTER TABLE alf_audit_date DROP INDEX adt_woy_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_date_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_y_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_q_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_m_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_dow_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_doy_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_dom_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_hy_idx; -- (optional) -ALTER TABLE alf_audit_date DROP INDEX adt_wom_idx; -- (optional) -ALTER TABLE alf_audit_date - ADD INDEX idx_alf_adtd_woy (week_of_year), - ADD INDEX idx_alf_adtd_q (quarter), - ADD INDEX idx_alf_adtd_wom (week_of_month), - ADD INDEX idx_alf_adtd_dom (day_of_month), - ADD INDEX idx_alf_adtd_doy (day_of_year), - ADD INDEX idx_alf_adtd_dow (day_of_week), - ADD INDEX idx_alf_adtd_m (month), - ADD INDEX idx_alf_adtd_hy (half_year), - ADD INDEX idx_alf_adtd_fy (full_year), - ADD INDEX idx_alf_adtd_dat (date_only) -; - -ALTER TABLE alf_audit_fact DROP INDEX adt_user_idx; -- (optional) -ALTER TABLE alf_audit_fact DROP INDEX adt_store_idx; -- (optional) -ALTER TABLE alf_audit_fact - DROP INDEX FKEAD18174A0F9B8D9, DROP FOREIGN KEY FKEAD18174A0F9B8D9, - DROP INDEX FKEAD1817484342E39, DROP FOREIGN KEY FKEAD1817484342E39, - DROP INDEX FKEAD18174F524CFD7, DROP FOREIGN KEY FKEAD18174F524CFD7 -; -ALTER TABLE alf_audit_fact - ADD INDEX idx_alf_adtf_ref (store_protocol, store_id, node_uuid), - ADD INDEX idx_alf_adtf_usr (user_id), - ADD INDEX fk_alf_adtf_src (audit_source_id), - ADD CONSTRAINT fk_alf_adtf_src FOREIGN KEY (audit_source_id) REFERENCES alf_audit_source (id), - ADD INDEX fk_alf_adtf_date (audit_date_id), - ADD CONSTRAINT fk_alf_adtf_date FOREIGN KEY (audit_date_id) REFERENCES alf_audit_date (id), - ADD INDEX fk_alf_adtf_conf (audit_conf_id), - ADD CONSTRAINT fk_alf_adtf_conf FOREIGN KEY (audit_conf_id) REFERENCES alf_audit_config (id) -; - -ALTER TABLE alf_audit_source DROP INDEX app_source_app_idx; -- (optional) -ALTER TABLE alf_audit_source DROP INDEX app_source_ser_idx; -- (optional) -ALTER TABLE alf_audit_source DROP INDEX app_source_met_idx; -- (optional) -ALTER TABLE alf_audit_source - ADD INDEX idx_alf_adts_met (method), - ADD INDEX idx_alf_adts_ser (service), - ADD INDEX idx_alf_adts_app (application) -; - ALTER TABLE alf_global_attributes DROP FOREIGN KEY FK64D0B9CF69B9F16A; -- (optional) ALTER TABLE alf_global_attributes DROP INDEX FK64D0B9CF69B9F16A; -- (optional) -- alf_global_attributes.attribute is declared unique. Indexes may automatically have been created. diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql deleted file mode 100644 index 6470ddc409..0000000000 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql +++ /dev/null @@ -1,23 +0,0 @@ --- --- Title: Ensure the audit table path column is indexed --- Database: PostgreSQL --- Since: V2.1 Schema 82 --- Author: Andy Hind --- --- Please contact support@alfresco.com if you need assistance with the upgrade. --- --- Path was previously unused and unindex - new we use it the index is required. - -CREATE INDEX idx_alf_adtf_pth ON alf_audit_fact (path); - --- --- Record script finish --- -DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.1-AuditPathIndex'; -INSERT INTO alf_applied_patch - (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) - VALUES - ( - 'patch.db-V2.1-AuditPathIndex', 'Manually executed script upgrade V2.1: Ensure existence of audit path index', - 0, 81, -1, 82, null, 'UNKNOWN', TRUE, TRUE, 'Script completed' - ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-0-create-missing-tables.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-0-create-missing-tables.sql index 56ba34494d..9dfc146700 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-0-create-missing-tables.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-0-create-missing-tables.sql @@ -10,11 +10,6 @@ -- to simplify subsequent upgrade scripts. -- --- Fix alf_audit_date column names - -ALTER TABLE alf_audit_date RENAME halfYear TO half_year; -ALTER TABLE alf_audit_date RENAME year TO full_year; - -- create other new tables create table avm_aspects ( diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-from-2.1.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-from-2.1.sql index f98305af97..d5ecc264b4 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-from-2.1.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.PostgreSQLDialect/upgrade-from-2.1.sql @@ -932,55 +932,6 @@ DROP INDEX fk_attributes_n_acl; -- (optional) DROP INDEX fk_attr_n_acl; -- (optional) CREATE INDEX fk_alf_attr_acl ON alf_attributes (acl_id); -DROP INDEX adt_woy_idx; -- (optional) -DROP INDEX adt_date_idx; -- (optional) -DROP INDEX adt_y_idx; -- (optional) -DROP INDEX adt_q_idx; -- (optional) -DROP INDEX adt_m_idx; -- (optional) -DROP INDEX adt_dow_idx; -- (optional) -DROP INDEX adt_doy_idx; -- (optional) -DROP INDEX adt_dom_idx; -- (optional) -DROP INDEX adt_hy_idx; -- (optional) -DROP INDEX adt_wom_idx; -- (optional) -CREATE INDEX idx_alf_adtd_woy ON alf_audit_date (week_of_year); -CREATE INDEX idx_alf_adtd_q ON alf_audit_date (quarter); -CREATE INDEX idx_alf_adtd_wom ON alf_audit_date (week_of_month); -CREATE INDEX idx_alf_adtd_dom ON alf_audit_date (day_of_month); -CREATE INDEX idx_alf_adtd_doy ON alf_audit_date (day_of_year); -CREATE INDEX idx_alf_adtd_dow ON alf_audit_date (day_of_week); -CREATE INDEX idx_alf_adtd_m ON alf_audit_date (month); -CREATE INDEX idx_alf_adtd_hy ON alf_audit_date (half_year); -CREATE INDEX idx_alf_adtd_fy ON alf_audit_date (full_year); -CREATE INDEX idx_alf_adtd_dat ON alf_audit_date (date_only); - -DROP INDEX adt_user_idx; -- (optional) -DROP INDEX adt_store_idx; -- (optional) -ALTER TABLE alf_audit_fact -DROP CONSTRAINT FKEAD18174A0F9B8D9, -DROP CONSTRAINT FKEAD1817484342E39, -DROP CONSTRAINT FKEAD18174F524CFD7 -; -DROP INDEX FKEAD18174A0F9B8D9; -DROP INDEX FKEAD1817484342E39; -DROP INDEX FKEAD18174F524CFD7; -ALTER TABLE alf_audit_fact - ADD CONSTRAINT fk_alf_adtf_src FOREIGN KEY (audit_source_id) REFERENCES alf_audit_source (id), - ADD CONSTRAINT fk_alf_adtf_date FOREIGN KEY (audit_date_id) REFERENCES alf_audit_date (id), - ADD CONSTRAINT fk_alf_adtf_conf FOREIGN KEY (audit_conf_id) REFERENCES alf_audit_config (id) -; -CREATE INDEX idx_alf_adtf_ref ON alf_audit_fact (store_protocol, store_id, node_uuid); -CREATE INDEX idx_alf_adtf_usr ON alf_audit_fact (user_id); -CREATE INDEX fk_alf_adtf_src ON alf_audit_fact (audit_source_id); -CREATE INDEX fk_alf_adtf_date ON alf_audit_fact (audit_date_id); -CREATE INDEX fk_alf_adtf_conf ON alf_audit_fact (audit_conf_id); - -DROP INDEX app_source_app_idx; -- (optional) -DROP INDEX app_source_ser_idx; -- (optional) -DROP INDEX app_source_met_idx; -- (optional) -CREATE INDEX idx_alf_adts_met ON alf_audit_source (method); -CREATE INDEX idx_alf_adts_ser ON alf_audit_source (service); -CREATE INDEX idx_alf_adts_app ON alf_audit_source (application); - ALTER TABLE alf_global_attributes DROP CONSTRAINT FK64D0B9CF69B9F16A; -- (optional) DROP INDEX FK64D0B9CF69B9F16A; -- (optional) -- alf_global_attributes.attribute is declared unique. Indexes may automatically have been created. diff --git a/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql b/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql new file mode 100644 index 0000000000..6f68424ad9 --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql @@ -0,0 +1,63 @@ +-- +-- Title: Upgrade to V3.2 - Add extra FK indexes +-- Database: Generic +-- Since: V3.2 schema 3503 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- +-- ALF-5396: Missing FK indexes on non-MySQL databases +-- All statements are made optional to cater for varying introductions of tables +-- using create scripts that have been fixed up. + +-- ========== +-- V3.2 diffs +-- ========== + +-- alf_audit_* tables +CREATE INDEX fk_alf_aud_mod_cd ON alf_audit_model(content_data_id); -- (optional) +CREATE INDEX fk_alf_aud_app_mod ON alf_audit_app(audit_model_id); -- (optional) +CREATE INDEX fk_alf_aud_app_dis ON alf_audit_app(disabled_paths_id); -- (optional) +CREATE INDEX fk_alf_aud_ent_app ON alf_audit_entry(audit_app_id); -- (optional) +CREATE INDEX fk_alf_aud_ent_use ON alf_audit_entry(audit_user_id); -- (optional) +CREATE INDEX fk_alf_aud_ent_pro ON alf_audit_entry(audit_values_id); -- (optional) + +-- Only missing on Oracle +ALTER TABLE avm_stores + ADD CONSTRAINT fk_avm_s_acl + FOREIGN KEY (acl_id) + REFERENCES alf_access_control_list (id); -- (optional) +CREATE INDEX fk_avm_s_acl ON avm_stores (acl_id); -- (optional) + +-- alf_content_* tables +CREATE INDEX fk_alf_cont_url ON alf_content_data (content_url_id); -- (optional) +CREATE INDEX fk_alf_cont_mim ON alf_content_data (content_mimetype_id); -- (optional) +CREATE INDEX fk_alf_cont_enc ON alf_content_data (content_encoding_id); -- (optional) +CREATE INDEX fk_alf_cont_loc ON alf_content_data (content_locale_id); -- (optional) + +-- alf_lock_* tables +CREATE INDEX fk_alf_lock_excl ON alf_lock (excl_resource_id); -- (optional) + +-- alf_prop_* tables +CREATE INDEX fk_alf_propln_key ON alf_prop_link(key_prop_id); -- (optional) +CREATE INDEX fk_alf_propln_val ON alf_prop_link(value_prop_id); -- (optional) +CREATE INDEX fk_alf_propuctx_v2 ON alf_prop_unique_ctx(value2_prop_id); -- (optional) +CREATE INDEX fk_alf_propuctx_v3 ON alf_prop_unique_ctx(value3_prop_id); -- (optional) + +-- ========== +-- V3.4 diffs +-- ========== + +CREATE INDEX fk_alf_propuctx_p1 ON alf_prop_unique_ctx(prop1_id); -- (optional) + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-AddFKIndexes-2'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V3.2-AddFKIndexes-2', 'Script fix for ALF-5396: Missing FK indexes on non-MySQL databases', + 0, 4111, -1, 4112, null, 'UNKOWN', ${TRUE}, ${TRUE}, 'Script completed' + ); diff --git a/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql b/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql new file mode 100644 index 0000000000..dd839db860 --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql @@ -0,0 +1,23 @@ +-- +-- Title: Upgrade to V3.2 - Add extra FK indexes +-- Database: MySQL +-- Since: V3.2 schema 3503 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- +-- ALF-5396: Missing FK indexes on non-MySQL databases +-- Not relevant to MySQL + + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-AddFKIndexes-2'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V3.2-AddFKIndexes-2', 'Script fix for ALF-5396: Missing FK indexes on non-MySQL databases', + 0, 4111, -1, 4112, null, 'UNKOWN', ${TRUE}, ${TRUE}, 'Script completed' + ); diff --git a/config/alfresco/dbscripts/upgrade/3.3/org.hibernate.dialect.PostgreSQLDialect/fix-Repo-seqs.sql b/config/alfresco/dbscripts/upgrade/3.3/org.hibernate.dialect.PostgreSQLDialect/fix-Repo-seqs.sql index 2e98cf198a..b7b345a8b8 100755 --- a/config/alfresco/dbscripts/upgrade/3.3/org.hibernate.dialect.PostgreSQLDialect/fix-Repo-seqs.sql +++ b/config/alfresco/dbscripts/upgrade/3.3/org.hibernate.dialect.PostgreSQLDialect/fix-Repo-seqs.sql @@ -32,14 +32,6 @@ CREATE SEQUENCE alf_acl_member_seq START WITH ${hibernate_seq_next_value} INCREM CREATE SEQUENCE alf_authority_alias_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; -CREATE SEQUENCE alf_audit_config_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; - -CREATE SEQUENCE alf_audit_date_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; - -CREATE SEQUENCE alf_audit_source_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; - -CREATE SEQUENCE alf_audit_fact_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; - CREATE SEQUENCE alf_server_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; CREATE SEQUENCE alf_transaction_seq START WITH ${hibernate_seq_next_value} INCREMENT BY 1; diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml index 5084416677..cded15631a 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml @@ -125,8 +125,8 @@ disabled_paths_id = #disabledPathsId# where id = #id# - - and version = ((#version#-1)) + + and version = (#version#-1) diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml index ccc8d0382b..ac5f4ff089 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml @@ -369,7 +369,7 @@ vers = #vers# where id = #id# - + and vers = (#vers#-1) @@ -600,7 +600,7 @@ vers = #vers# where id = #id# - + and vers = (#vers#-1) @@ -614,7 +614,7 @@ vers = #vers# where id = #id# - + and vers = (#vers#-1) @@ -631,7 +631,7 @@ vers = #vers# where id = #id# - + and vers = (#vers#-1) diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/content-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/content-common-SqlMap.xml index 9333e4dac6..52ddfddf81 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/content-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/content-common-SqlMap.xml @@ -207,7 +207,7 @@ mimetype_str = #mimetype# where id = #id# - + and version = (#version#-1) @@ -277,7 +277,7 @@ content_locale_id = #localeId# where id = #id# - + and version = (#version#-1) diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/locks-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/locks-common-SqlMap.xml index 9df990ae3d..6063c98044 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/locks-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/locks-common-SqlMap.xml @@ -121,8 +121,10 @@ start_time = #startTime#, expiry_time = #expiryTime# where - id = #id# and - version = (#version# -1) + id = #id# + + and version = (#version#-1) + diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml index 359771ef2b..f9cccf1e22 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml @@ -366,7 +366,7 @@ where id = #id# - + and version = (#version#-1) @@ -394,7 +394,8 @@ parent_node_id = #parentNode.id# and type_qname_id = #typeQNameId# and qname_ns_id = #qnameNamespaceId# and - qname_localname = #qnameLocalName# + qname_localname = #qnameLocalName# and + child_node_id = #childNode.id# @@ -770,7 +771,7 @@ parentNode.id = #parentNode.id# and assoc.child_node_id = #childNode.id# - and type_qname_id in #typeQNameIds[]# + and assoc.type_qname_id in #typeQNameIds[]# and assoc.type_qname_id = #typeQNameId# and assoc.qname_crc = #qnameCrc# diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml index 2ffedddb7c..f8bf7b395a 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml @@ -12,6 +12,8 @@ + + @@ -70,6 +72,13 @@ + + + + + + + @@ -103,6 +112,12 @@ + + + + + + @@ -320,6 +335,30 @@ acl_id > ? + + @@ -358,6 +397,16 @@ id = ? + + update + avm_child_entries + set + name = ? + where + child_id = ? + and parent_id = ? + + diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/permissions-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/permissions-common-SqlMap.xml index 9f9632e1ad..7483422c28 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/permissions-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/permissions-common-SqlMap.xml @@ -277,7 +277,7 @@ version = #version# where id = #id# - + and version = (#version#-1) @@ -293,7 +293,7 @@ version = #version# where id = #id# - + and version = (#version#-1) @@ -308,7 +308,7 @@ version = #version# where id = #id# - + and version = (#version#-1) @@ -323,7 +323,7 @@ version = #version# where id = #id# - + and version = (#version#-1) diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml index 928da9eae4..eb4712f70a 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml @@ -435,8 +435,8 @@ version = #version# where id = #id# - - and version = ((#version#-1)) + + and version = (#version#-1) @@ -510,8 +510,8 @@ prop1_id = #propertyId# where id = #id# - - and version = ((#version#-1)) + + and version = (#version#-1) diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 880da3d1d1..4bcc3b0ece 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -349,9 +349,12 @@ patch.fixAuthoritiesCrcValues.fixed=Updated CRC32 values for authority '{0}'. patch.fixAuthoritiesCrcValues.unableToChange=Failed to update the CRC32 value for authority: \n Authority: {0} \n Error: {1} patch.updateMimetypes1.description=Fix mimetypes for Excel and Powerpoint. +patch.updateMimetypes2.description=Fix mimetypes for Excel and Powerpoint. patch.db-V3.2-AddFKIndexes.description=Fixes ALF-3189: Added missing FK indexes. Note: The script is empty for MySQL. +patch.eliminateDuplicates.description=Fixes ALF-4203: Searches for AVM duplicate nodes and changes their name + patch.migrateAttrTenants.description=Migrate old Tenant attributes patch.migrateAttrTenants.result=Processed {0} attributes diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 8935cd1139..4df150244e 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -1259,15 +1259,12 @@ - + patch.db-V2.1-AuditPathIndex patch.schemaUpgradeScript.description 0 132 133 - - classpath:alfresco/dbscripts/upgrade/2.2/${db.script.dialect}/AlfrescoSchemaUpdate-2.1-AuditPathIndex.sql - @@ -2264,6 +2261,7 @@ + @@ -2465,5 +2463,27 @@ true - + + + patch.db-V3.2-AddFKIndexes-2 + patch.schemaUpgradeScript.description + 0 + 4111 + 4112 + + classpath:alfresco/dbscripts/upgrade/3.2/${db.script.dialect}/AlfrescoSchemaUpdate-3.2-AddFKIndexes-2.sql + + + + + + + + + + + + + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 8b3e61bddd..6090d71b50 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=4111 +version.schema=4113 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/DuplicateEntry.java b/source/java/org/alfresco/repo/admin/patch/impl/DuplicateEntry.java new file mode 100644 index 0000000000..56bf1790d6 --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/DuplicateEntry.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +/** + * Wrapper for duplicate entries + * + * @author Dmitry Velichkevich + */ +public class DuplicateEntry +{ + private static final int ODD_MULTIPLICATOR = 37; + + private Long id; + + private Long parentId; + + private String name; + + private Long amount; + + public DuplicateEntry() + { + } + + public DuplicateEntry(Long id, Long parentId, String name, Long amount) + { + this.id = id; + this.parentId = parentId; + this.name = name; + this.amount = amount; + } + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getParentId() + { + return parentId; + } + + public void setParentId(Long parentId) + { + this.parentId = parentId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Long getAmount() + { + return amount; + } + + public void setAmount(Long amount) + { + this.amount = amount; + } + + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof DuplicateEntry)) + { + return false; + } + DuplicateEntry converted = (DuplicateEntry) obj; + return (id == converted.getId()) && (parentId == converted.getParentId()) && ((null == name) ? (null == converted.getName()) : (name.equals(converted.getName()))); + } + + @Override + public int hashCode() + { + int result = (int) id.intValue(); + result = DuplicateEntry.ODD_MULTIPLICATOR * result + (int) parentId.longValue(); + result = DuplicateEntry.ODD_MULTIPLICATOR * result + (int) amount.longValue(); + result = DuplicateEntry.ODD_MULTIPLICATOR * result + ((null != name) ? (name.hashCode()) : (0)); + return result; + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/EliminateDuplicatesPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/EliminateDuplicatesPatch.java new file mode 100644 index 0000000000..19a74ee29b --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/EliminateDuplicatesPatch.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.util.Iterator; +import java.util.List; + +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.AVMNodeType; +import org.alfresco.util.GUID; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * ALF-4203 + * + * This patch searches for AVM Node duplicates resulting from case insensitivity issues on + * earlier versions of the software (see ALF-1940) and eliminates them by changing the name + * of duplicates to make them unique. This is achieved by appending a unique suffix to + * duplicate node names. + * + * @author Dmitry Velichkevich + */ +public class EliminateDuplicatesPatch extends AbstractPatch +{ + private Log LOGGER = LogFactory.getLog(EliminateDuplicatesPatch.class); + + private static final String RENAMED_MARK_KEY = "renamed.duplicate.mark"; + + private static final char EXTENSION_DELIMITER = '.'; + + private static final char TOKENS_DELIMITER = '-'; + + /** + * Internationalized mark to indicate renamed duplicate + */ + private String renamedMark; + + /** + * Temporary extension for renamed duplicates. May be 'not set' + */ + private String temporaryExtension; + + private AvmDuplicatesIBatisDao helper; + + public EliminateDuplicatesPatch() + { + helper = new AvmDuplicatesIBatisDao(); + } + + public String getRenamedMark() + { + if (null == renamedMark) + { + String mark = I18NUtil.getMessage(RENAMED_MARK_KEY); + StringBuilder markBuilder = new StringBuilder().append(TOKENS_DELIMITER); + renamedMark = markBuilder.append(mark).append(TOKENS_DELIMITER).toString(); + } + return renamedMark; + } + + public void setTemporaryExtension(String temporaryExtension) + { + this.temporaryExtension = temporaryExtension; + } + + public void setTemplate(SqlMapClientTemplate template) + { + helper.setTemplate(template); + } + + @Override + protected String applyInternal() throws Exception + { + int totalRenamed = 0; + int duplicateGroupsAmount = 0; + + // Receiving duplicates + List duplicates = helper.getDuplicates(); + Iterator duplicatesIterator = duplicates.iterator(); + DuplicateEntry duplicate = null; + + // duplicates contains all the duplicates found ordered by parent_id, lower(name), child_id. + // Within this ordered list there are groups of duplicates (in which the parent_id and lower(name) + // are the same but the child_id varies). A duplicate group, by definition, must have two or more entries. + while (duplicatesIterator.hasNext() && (null != (duplicate = duplicatesIterator.next()))) + { + // Increasing duplicate groups amount + duplicateGroupsAmount++; + int renamed = 0; + + // First element of the duplicates group will be left with its current name. Marking first element of current group as marked + int processed = 1; + + // amount is the number of duplicates in the current duplicate group + long amount = duplicate.getAmount(); + + // While we have duplicates and we are still within a duplicates group + // amount = the number of duplicates with the same parent and lowercase name + // processed = the number of duplicates in the current duplicates group that have been processed + while (duplicatesIterator.hasNext() && (amount > processed)) + { + // Skipping first element from each group to leave at least one Node with initial name + duplicate = duplicatesIterator.next(); + processed++; + + String newName = generatePatchedName(duplicate); + boolean renamingResult = helper.renameNode(new DuplicateEntry(duplicate.getId(), duplicate.getParentId(), newName, 1L)); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Trying to rename Node with id = '" + duplicate.getId() + "' and parent id = '" + + duplicate.getParentId() + "' from '" + duplicate.getName() + "' to '" + newName + "'. Result: " + + renamingResult); + } + if (renamingResult) + { + renamed++; + totalRenamed++; + } + } + + // Entries finished or another group reached + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Duplicates for '" + duplicate.getName().toLowerCase() + "' name and parentId='" + duplicate.getParentId() + "': " + duplicate.getAmount() + + ". Renamed: " + renamed); + } + } + + StringBuilder result = new StringBuilder(); + result.append(duplicateGroupsAmount).append(" duplicate group(s) were found\n"); + result.append(duplicates.size()).append(" affected node entries\n"); + result.append("----------------\nTotal renamed: ").append(totalRenamed).append('\n'); + return result.toString(); + } + + /** + * With help of {@link GUID} utility class this method generates unique and internationalized name for some Node. Also returned name will be finished with + * {@link EliminateDuplicatesPatch#temporaryExtension} extension if it is not empty or null + * + * @param node - {@link DuplicateEntry} instance which contains required old name and Node id + * @return {@link String} value which represents unique and internationalized name generated from the duplicated one + */ + private String generatePatchedName(DuplicateEntry node) + { + StringBuilder result = new StringBuilder(); + StringBuilder extension = new StringBuilder(); + AVMNode avmNode = AVMDAOs.Instance().fAVMNodeDAO.getByID(node.getId()); + String oldName = node.getName(); + if (((AVMNodeType.LAYERED_FILE == avmNode.getType()) || (AVMNodeType.PLAIN_FILE == avmNode.getType()))) + { + int dotPosition = oldName.indexOf(EXTENSION_DELIMITER); + if (-1 != dotPosition) + { + extension.append(oldName.substring(dotPosition)); + oldName = oldName.substring(0, dotPosition); + } + if ((null != temporaryExtension) && (temporaryExtension.length() > 0)) + { + extension.append(EXTENSION_DELIMITER).append(temporaryExtension); + } + } + result.append(oldName).append(getRenamedMark()).append(GUID.generate()).append(extension.toString()); + return result.toString(); + } + + /** + * iBatis helper which introduces functionality for duplicates of some node receiving and renaming in avm_child_entries table + * + * @author Dmitry Velichkevich + */ + private class AvmDuplicatesIBatisDao + { + private static final String QUERY_SELECT_DUPLICATES_ID = "alfresco.patch.select_AvmNodeDuplicates"; + + private static final String QUERY_RENAME_NODE_ID = "alfresco.patch.update_AvmNodeNameById"; + + private SqlMapClientTemplate template; + + public void setTemplate(SqlMapClientTemplate template) + { + this.template = template; + } + + /** + * Receives all duplicates found in some repository + * + * @return {@link List}<{@link DuplicateEntry}> list which contains all received duplicates wrapped into the {@link DuplicateEntry} + */ + @SuppressWarnings("unchecked") + public List getDuplicates() + { + return template.queryForList(QUERY_SELECT_DUPLICATES_ID); + } + + /** + * Renames some child which is duplicate for some other Node(s) in some Space + * + * @param renamedEntry - {@link DuplicateEntry} instance which specifies Id and new name for Node + * @return {@link Boolean} value which equals to true if renaming update has been finished successfully + */ + public boolean renameNode(DuplicateEntry renamedEntry) + { + return template.update(QUERY_RENAME_NODE_ID, renamedEntry) > 0; + } + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java index 115ab49ef7..dadca1baf9 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java @@ -92,27 +92,30 @@ public class MigrateAttrAVMLocksPatch extends AbstractPatch Map result = (Map)valueObject; String wpStoreId = (String)result.get("wpStoreId"); - String relPath = (String)result.get("relPath"); + String path = (String)result.get("relPath"); String avmStore = (String)result.get("avmStore"); String lockOwner = (String)result.get("owner1"); - relPath = AVMLockingServiceImpl.normalizePath(relPath); + String relPath = AVMLockingServiceImpl.normalizePath(path); HashMap lockData = new HashMap(2); lockData.put(AVMLockingServiceImpl.KEY_LOCK_OWNER, lockOwner); lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, avmStore); - - attributeService.createAttribute( - lockData, - AVMLockingServiceImpl.KEY_AVM_LOCKS, wpStoreId, relPath); - - if (logger.isTraceEnabled()) + + if (!attributeService.exists(AVMLockingServiceImpl.KEY_AVM_LOCKS, wpStoreId, relPath)) { - logger.trace("Set AVM Lock attr [wpStoreId="+wpStoreId+", relPath="+relPath+", lockOwner="+lockOwner+", avmStore="+avmStore+"]"); + attributeService.createAttribute(lockData, AVMLockingServiceImpl.KEY_AVM_LOCKS, wpStoreId, relPath); + if (logger.isTraceEnabled()) + { + logger.trace("Set AVM Lock attr [wpStoreId=" + wpStoreId + ", relPath=" + relPath + ", lockOwner=" + lockOwner + ", avmStore=" + avmStore + "]"); + } + total++; } - - total++; - + else + { + logger.warn("'" + path + "' path has duplicates in normalized form. AVM lock unique attribute creation has been skipped"); + } + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) { logger.debug(" Handled " + total + " AVM Lock attributes"); diff --git a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java index 3adca88875..ab85bc1350 100644 --- a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java +++ b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java @@ -39,6 +39,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import javax.sql.DataSource; + import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.ibatis.SerializableTypeHandlerCallback; import org.alfresco.repo.admin.patch.Patch; @@ -48,11 +50,7 @@ import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.hibernate.dialect.AlfrescoOracle9Dialect; import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSQLServerDialect; import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSybaseAnywhereDialect; -import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.descriptor.Descriptor; -import org.alfresco.service.descriptor.DescriptorService; -import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.LogUtil; import org.alfresco.util.TempFileProvider; import org.alfresco.util.schemadump.Main; @@ -78,7 +76,6 @@ import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.engine.ActionQueue; import org.hibernate.tool.hbm2ddl.DatabaseMetadata; -import org.hibernate.tool.hbm2ddl.SchemaExport; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.core.io.Resource; @@ -194,6 +191,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean private static Log logger = LogFactory.getLog(SchemaBootstrap.class); + private DataSource dataSource; private LocalSessionFactoryBean localSessionFactory; private String schemaOuputFilename; private boolean updateSchema; @@ -222,6 +220,11 @@ public class SchemaBootstrap extends AbstractLifecycleBean globalProperties = new Properties(); } + public void setDataSource(DataSource dataSource) + { + this.dataSource = dataSource; + } + public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory) { this.localSessionFactory = localSessionFactory; @@ -402,25 +405,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean this.globalProperties = globalProperties; } - /** - * Helper method to generate a schema creation SQL script from the given Hibernate - * configuration. - */ - private static void dumpSchemaCreate(Configuration cfg, File schemaOutputFile) - { - // if the file exists, delete it - if (schemaOutputFile.exists()) - { - schemaOutputFile.delete(); - } - SchemaExport schemaExport = new SchemaExport(cfg) - .setFormat(true) - .setHaltOnError(true) - .setOutputFile(schemaOutputFile.getAbsolutePath()) - .setDelimiter(";"); - schemaExport.execute(false, false, false, true); - } - private SessionFactory getSessionFactory() { return (SessionFactory) localSessionFactory.getObject(); @@ -765,9 +749,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean else { // Check for scripts that must have been run - checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); + checkSchemaPatchScripts(cfg, connection, validateUpdateScriptPatches, false); // Execute any pre-auto-update scripts - checkSchemaPatchScripts(cfg, session, connection, preUpdateScriptPatches, true); + checkSchemaPatchScripts(cfg, connection, preUpdateScriptPatches, true); // Build and execute changes generated by Hibernate File tempFile = null; @@ -801,7 +785,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean } // Execute any post-auto-update scripts - checkSchemaPatchScripts(cfg, session, connection, postUpdateScriptPatches, true); + checkSchemaPatchScripts(cfg, connection, postUpdateScriptPatches, true); } return create; @@ -812,7 +796,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean */ private void checkSchemaPatchScripts( Configuration cfg, - Session session, Connection connection, List scriptPatches, boolean apply) throws Exception @@ -952,7 +935,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean { // Dump the normalized, pre-upgrade Alfresco schema. We keep the file for later reporting. xmlPreSchemaOutputFile = dumpSchema( - connection, this.dialect, TempFileProvider.createTempFile( "AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-", @@ -1351,7 +1333,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean try { // make sure that we AUTO-COMMIT - connection = session.connection(); + connection = dataSource.getConnection(); connection.setAutoCommit(true); Configuration cfg = localSessionFactory.getConfiguration(); @@ -1424,9 +1406,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean if (! createdSchema) { // verify that all patches have been applied correctly - checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); // check scripts - checkSchemaPatchScripts(cfg, session, connection, preUpdateScriptPatches, false); // check scripts - checkSchemaPatchScripts(cfg, session, connection, postUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, connection, validateUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, connection, preUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, connection, postUpdateScriptPatches, false); // check scripts } if (executedStatements != null) @@ -1440,7 +1422,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean { // Dump the normalized, post-upgrade Alfresco schema. File xmlPostSchemaOutputFile = dumpSchema( - connection, this.dialect, TempFileProvider.createTempFile( "AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-", @@ -1479,7 +1460,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean // We have been forced to stop, so we do one last dump of the schema and throw an exception to // escape further startup procedures File xmlStopSchemaOutputFile = dumpSchema( - connection, this.dialect, TempFileProvider.createTempFile( "AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-", @@ -1538,12 +1518,12 @@ public class SchemaBootstrap extends AbstractLifecycleBean /** * @return Returns the file that was written to or null if it failed */ - private File dumpSchema(Connection connection, Dialect dialect, String fileName, String err) + private File dumpSchema(Dialect dialect, String fileName, String err) { File xmlSchemaOutputFile = new File(fileName); try { - Main xmlSchemaOutputMain = new Main(connection, dialect); + Main xmlSchemaOutputMain = new Main(dataSource, dialect); xmlSchemaOutputMain.execute(xmlSchemaOutputFile); } catch (Throwable e) @@ -1647,94 +1627,4 @@ public class SchemaBootstrap extends AbstractLifecycleBean return false; } } - - private static final String DIR_SCHEMAS = "schemas"; - /** - * Dump a set of creation files for all known Hibernate dialects. These will be - * dumped into the default temporary location in a subdirectory named schemas. - */ - public static void main(String[] args) - { - int exitCode = 0; - try - { - exitCode = dumpDialects(args); - } - catch (Throwable e) - { - LogUtil.error(logger, e, "SchemaBootstrap script dump failed"); - exitCode = 1; - } - // We can exit - System.exit(exitCode); - } - - private static int dumpDialects(String[] dialectClassNames) - { - if (dialectClassNames.length == 0) - { - System.out.println( - "\n" + - " ERROR: A list of fully qualified class names is required"); - return 1; - } - ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - SchemaBootstrap schemaBootstrap = (SchemaBootstrap) ctx.getBean("schemaBootstrap"); - LocalSessionFactoryBean localSessionFactoryBean = schemaBootstrap.getLocalSessionFactory(); - Configuration configuration = localSessionFactoryBean.getConfiguration(); - - ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - DescriptorService descriptorService = serviceRegistry.getDescriptorService(); - Descriptor descriptor = descriptorService.getServerDescriptor(); - - File tempDir = TempFileProvider.getTempDir(); - File schemasDir = new File(tempDir, DIR_SCHEMAS); - if (!schemasDir.exists()) - { - schemasDir.mkdir(); - } - File dumpDir = new File(schemasDir, descriptor.getVersion()); - if (!dumpDir.exists()) - { - dumpDir.mkdir(); - } - for (String dialectClassName : dialectClassNames) - { - Class dialectClazz = null; - try - { - dialectClazz = Class.forName(dialectClassName); - } - catch (ClassNotFoundException e) - { - System.out.println( - "\n" + - " ERROR: Class not found: " + dialectClassName); - continue; - } - if (!Dialect.class.isAssignableFrom(dialectClazz)) - { - System.out.println( - "\n" + - " ERROR: The class name is not a valid dialect: " + dialectClassName); - continue; - } - dumpDialectScript(configuration, dialectClazz, dumpDir); - } - // Done - return 0; - } - - private static void dumpDialectScript(Configuration configuration, Class dialectClazz, File directory) - { - // Set the dialect - configuration.setProperty("hibernate.dialect", dialectClazz.getName()); - - // First dump the dialect's schema - String filename = "default-schema-create-" + dialectClazz.getName() + ".sql"; - File dumpFile = new File(directory, filename); - - // Write the file - SchemaBootstrap.dumpSchemaCreate(configuration, dumpFile); - } } diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java index 92b5643cc5..ad0b8ee429 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java @@ -138,6 +138,12 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest public static final QName ASSOC_ASPECT_CHILD_ASSOC = QName.createQName(NAMESPACE, "aspect-child-assoc"); public static final QName ASSOC_ASPECT_NORMAL_ASSOC = QName.createQName(NAMESPACE, "aspect-normal-assoc"); + public static final QName ASPECT_WITH_ASSOCIATIONS_EXTRA = QName.createQName(NAMESPACE, "withAssociationsExtra"); + public static final QName ASSOC_ASPECT_CHILD_ASSOC_01 = QName.createQName(NAMESPACE, "aspect-child-assoc-01"); + public static final QName ASSOC_ASPECT_CHILD_ASSOC_02 = QName.createQName(NAMESPACE, "aspect-child-assoc-02"); + public static final QName ASSOC_ASPECT_NORMAL_ASSOC_01 = QName.createQName(NAMESPACE, "aspect-normal-assoc-01"); + public static final QName ASSOC_ASPECT_NORMAL_ASSOC_02 = QName.createQName(NAMESPACE, "aspect-normal-assoc-02"); + public static final QName TYPE_QNAME_TEST_MULTIPLE_TESTER = QName.createQName(NAMESPACE, "multiple-tester"); public static final QName PROP_QNAME_STRING_PROP_SINGLE = QName.createQName(NAMESPACE, "stringprop-single"); public static final QName PROP_QNAME_STRING_PROP_MULTIPLE = QName.createQName(NAMESPACE, "stringprop-multiple"); @@ -790,6 +796,24 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest 0, nodeService.getChildAssocs(sourceNodeRef).size()); assertEquals("Expected exactly zero target", 0, nodeService.getTargetAssocs(sourceNodeRef, RegexQNamePattern.MATCH_ALL).size()); + + // Force different cleanup queries: + // ALF-5308: SQL error when changing name for record / folder with dispostion schedule applied + nodeService.addAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS_EXTRA, null); + // Make the associations + nodeService.addChild( + sourceNodeRef, + targetNodeRef, + ASSOC_ASPECT_CHILD_ASSOC_01, + QName.createQName(NAMESPACE, "aspect-child-01")); + nodeService.addChild( + sourceNodeRef, + targetNodeRef, + ASSOC_ASPECT_CHILD_ASSOC_02, + QName.createQName(NAMESPACE, "aspect-child-02")); + nodeService.createAssociation(sourceNodeRef, targetNodeRef, ASSOC_ASPECT_NORMAL_ASSOC_01); + nodeService.createAssociation(sourceNodeRef, targetNodeRef, ASSOC_ASPECT_NORMAL_ASSOC_02); + nodeService.removeAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS_EXTRA); } /** diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml b/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml index a33fe8f0f1..f3c43de001 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml @@ -380,6 +380,56 @@ + + Aspect with Associations + + + + false + false + + + sys:base + true + true + + + + + false + false + + + sys:base + true + true + + + + + false + false + + + sys:base + true + true + + + + + false + false + + + sys:base + true + true + + + + + Aspect ANO1 diff --git a/source/java/org/alfresco/util/schemadump/Main.java b/source/java/org/alfresco/util/schemadump/Main.java index e083cc54ad..243e0c8278 100644 --- a/source/java/org/alfresco/util/schemadump/Main.java +++ b/source/java/org/alfresco/util/schemadump/Main.java @@ -41,6 +41,7 @@ import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; +import org.alfresco.util.PropertyCheck; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.TypeNames; @@ -67,8 +68,8 @@ public class Main /** Should we scale down string field widths (assuming 4 bytes to one character?). */ private boolean scaleCharacters; - /** The JDBC connection. */ - private Connection con; + /** The JDBC DataSource. */ + private DataSource dataSource; /** * The main method. @@ -92,15 +93,13 @@ public class Main /** * Creates a new instance of this tool by starting up a full context. */ - @SuppressWarnings("unchecked") public Main(final String contextPath) throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "file:" + contextPath }); - final DataSource datasource = (DataSource) context.getBean("dataSource"); - this.con = datasource.getConnection(); + this.dataSource = (DataSource) context.getBean("dataSource"); // Use Java reflection to bypass accessibility rules and get hold of hibernate's type mapping! final Properties hibProps = (Properties) context.getBean("hibernateConfigProperties"); @@ -116,9 +115,9 @@ public class Main * @param connection the database connection to use for metadata queries * @param dialect the Hibernate dialect */ - public Main(final Connection connection, final Dialect dialect) throws Exception + public Main(final DataSource dataSource, final Dialect dialect) throws Exception { - this.con = connection; + this.dataSource = dataSource; // Initialize init(dialect); @@ -163,7 +162,19 @@ public class Main */ public void execute(File outputFile) throws Exception { - final NamedElementCollection result = execute(); + PropertyCheck.mandatory(this, "dataSource", dataSource); + // Get a Connection + Connection connection = dataSource.getConnection(); + NamedElementCollection result = null; + try + { + connection.setAutoCommit(false); + result = execute(connection); + } + finally + { + try { connection.close(); } catch (Throwable e) {} + } // Set up a SAX TransformerHandler for outputting XML final SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance(); @@ -190,11 +201,11 @@ public class Main * * @return Returns the named XML elements */ - public NamedElementCollection execute() throws Exception + private NamedElementCollection execute(Connection con) throws Exception { final NamedElementCollection schemaCol = new NamedElementCollection("schema", "table"); - final DatabaseMetaData dbmd = this.con.getMetaData(); + final DatabaseMetaData dbmd = con.getMetaData(); // Assume that if there are schemas, we want the one named after the connection user or the one called "dbo" (MS // SQL hack) @@ -398,19 +409,6 @@ public class Main this.elementName = elementName; } - /** - * Adds an attribute. - * - * @param name - * the name - * @param value - * the value - */ - public void addAttribute(final String name, final String value) - { - this.attributes.addAttribute("", "", name, "CDATA", value); - } - /** * Adds a named element. *