From b4e48157f50158f1f98cee3aece20abe678144cc Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Fri, 16 Feb 2007 16:10:44 +0000 Subject: [PATCH] Merged V2.0 to HEAD svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5154 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5155 . - Installer script cleanup svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5156 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5157 . svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5162 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5163 . svn rm --force root\projects\repository\config\alfresco\dbscripts\create\1.4\org.hibernate.dialect.Dialect\post-create-indexes.sql svn rm --force root\projects\repository\config\alfresco\dbscripts\create\1.4\org.hibernate.dialect.MySQLInnoDBDialect\post-create-indexes.sql - Fix AR-1225: Upgrade and install indexes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5171 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bootstrap-context.xml | 10 ++- .../post-create-indexes.sql | 3 - .../post-create-indexes.sql | 30 ------- .../AlfrescoPostCreate-2.0-FKIndexes.sql} | 27 +++++- .../AlfrescoPostCreate-2.0-FKIndexes.sql | 10 +++ .../AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql | 35 ++++++++ ...frescoSchemaUpdate-2.0-ExplicitIndexes.sql | 60 +++++++++++++ .../AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql | 22 +++++ .../alfresco/patch/patch-services-context.xml | 22 +++++ config/alfresco/version.properties | 2 +- .../repo/admin/patch/PatchDaoService.java | 5 +- .../repo/admin/patch/PatchServiceImpl.java | 87 ++++++++++++------- .../HibernatePatchDaoServiceImpl.java | 2 +- .../alfresco/repo/avm/hibernate/AVM.hbm.xml | 35 ++++---- .../repo/domain/schema/SchemaBootstrap.java | 49 +++++++---- 15 files changed, 294 insertions(+), 105 deletions(-) delete mode 100644 config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Dialect/post-create-indexes.sql delete mode 100644 config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.SQLServerDialect/post-create-indexes.sql rename config/alfresco/dbscripts/create/{1.4/org.hibernate.dialect.Oracle9Dialect/post-create-indexes.sql => 2.0/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.0-FKIndexes.sql} (53%) create mode 100644 config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-2.0-FKIndexes.sql create mode 100644 config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql create mode 100644 config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql create mode 100644 config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index a360122959..0b1d162efa 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -35,19 +35,25 @@ - classpath:alfresco/dbscripts/create/1.4/${db.script.dialect}/post-create-indexes.sql + classpath:alfresco/dbscripts/create/2.0/${db.script.dialect}/AlfrescoPostCreate-2.0-FKIndexes.sql - + + + + + + + diff --git a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Dialect/post-create-indexes.sql b/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Dialect/post-create-indexes.sql deleted file mode 100644 index d2bc282c82..0000000000 --- a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Dialect/post-create-indexes.sql +++ /dev/null @@ -1,3 +0,0 @@ --- --- Add post-creation indexes. (Generic Schema 1.4) --- diff --git a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.SQLServerDialect/post-create-indexes.sql b/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.SQLServerDialect/post-create-indexes.sql deleted file mode 100644 index 1a385c5260..0000000000 --- a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.SQLServerDialect/post-create-indexes.sql +++ /dev/null @@ -1,30 +0,0 @@ --- --- Add post-creation indexes. (SQL Server Schema 1.4) --- -CREATE INDEX FKFFF41F9960601995 ON alf_access_control_entry (permission_id); -CREATE INDEX FKFFF41F99B25A50BF ON alf_access_control_entry (authority_id); -CREATE INDEX FKFFF41F99B9553F6C ON alf_access_control_entry (acl_id); -CREATE INDEX FK8A749A657B7FDE43 ON alf_auth_ext_keys (id); -CREATE INDEX FKFFC5468E74173FF4 ON alf_child_assoc (child_node_id); -CREATE INDEX FKFFC5468E8E50E582 ON alf_child_assoc (parent_node_id); -CREATE INDEX FK60EFB626B9553F6C ON alf_node (acl_id); -CREATE INDEX FK60EFB626D24ADD25 ON alf_node (protocol, identifier); -CREATE INDEX FK7D4CF8EC7F2C8017 ON alf_node_properties (node_id); -CREATE INDEX FKD654E027F2C8017 ON alf_node_aspects (node_id); -CREATE INDEX FKE1A550BCB69C43F3 ON alf_node_assoc (source_node_id); -CREATE INDEX FKE1A550BCA8FC7769 ON alf_node_assoc (target_node_id); -CREATE INDEX FK71C2002B7F2C8017 ON alf_node_status (node_id); -CREATE INDEX FKBD4FF53D22DBA5BA ON alf_store (root_node_id); - --- --- Transaction tables --- -CREATE INDEX FK71C2002B9E57C13D ON alf_node_status (transaction_id); -CREATE INDEX FKB8761A3A9AE340B7 ON alf_transaction (server_id); - --- --- New audit tables --- -CREATE INDEX FKEAD1817484342E39 ON alf_audit_fact (audit_date_id); -CREATE INDEX FKEAD18174A0F9B8D9 ON alf_audit_fact (audit_source_id); -CREATE INDEX FKEAD18174F524CFD7 ON alf_audit_fact (audit_conf_id); diff --git a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Oracle9Dialect/post-create-indexes.sql b/config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.0-FKIndexes.sql similarity index 53% rename from config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Oracle9Dialect/post-create-indexes.sql rename to config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.0-FKIndexes.sql index 373194f988..c52d7b15eb 100644 --- a/config/alfresco/dbscripts/create/1.4/org.hibernate.dialect.Oracle9Dialect/post-create-indexes.sql +++ b/config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.0-FKIndexes.sql @@ -1,6 +1,13 @@ -- --- Add post-creation indexes. (Oracle Schema 1.4) +-- Title: Post-Create Foreign Key indexes +-- Database: Generic +-- Since: V2.0 Schema 38 +-- Author: Derek Hulley -- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +-- Repository CREATE INDEX FKFFF41F9960601995 ON alf_access_control_entry (permission_id); CREATE INDEX FKFFF41F99B25A50BF ON alf_access_control_entry (authority_id); CREATE INDEX FKFFF41F99B9553F6C ON alf_access_control_entry (acl_id); @@ -23,8 +30,24 @@ CREATE INDEX FK71C2002B9E57C13D ON alf_node_status (transaction_id); CREATE INDEX FKB8761A3A9AE340B7 ON alf_transaction (server_id); -- --- New audit tables +-- Audit tables -- CREATE INDEX FKEAD1817484342E39 ON alf_audit_fact (audit_date_id); CREATE INDEX FKEAD18174A0F9B8D9 ON alf_audit_fact (audit_source_id); CREATE INDEX FKEAD18174F524CFD7 ON alf_audit_fact (audit_conf_id); + +-- AVM +CREATE INDEX fk_avm_asp_node ON avm_aspects (node_id); +CREATE INDEX fk_avm_ce_child ON avm_child_entries (child_id); +CREATE INDEX fk_avm_ce_parent ON avm_child_entries (parent_id); +CREATE INDEX fk_avm_hl_desc ON avm_history_links (descendent); +CREATE INDEX fk_avm_hl_ancestor ON avm_history_links (ancestor); +CREATE INDEX fk_avm_ml_from ON avm_merge_links (mfrom); +CREATE INDEX fk_avm_ml_to ON avm_merge_links (mto); +CREATE INDEX fk_avm_np_node ON avm_node_properties (node_id); +CREATE INDEX fk_avm_n_acl ON avm_nodes (acl_id); +CREATE INDEX fk_avm_n_store ON avm_nodes (store_new_id); +CREATE INDEX fk_avm_sp_store ON avm_store_properties (avm_store_id); +CREATE INDEX fk_avm_s_root ON avm_stores (current_root_id); +CREATE INDEX fk_avm_vr_store ON avm_version_roots (avm_store_id); +CREATE INDEX fk_avm_vr_root ON avm_version_roots (root_id); diff --git a/config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-2.0-FKIndexes.sql b/config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-2.0-FKIndexes.sql new file mode 100644 index 0000000000..674078042b --- /dev/null +++ b/config/alfresco/dbscripts/create/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-2.0-FKIndexes.sql @@ -0,0 +1,10 @@ +-- +-- Title: Post-Create AVM Foreign Key indexes +-- Database: MySQL +-- Since: V2.0 Schema 38 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +-- The MySQL dialects apply the FK indexes by default diff --git a/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql new file mode 100644 index 0000000000..b6a5946b5b --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql @@ -0,0 +1,35 @@ +-- +-- Title: AVM Foreign Key indexes +-- Database: Generic +-- Since: V2.0 Schema 38 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +CREATE INDEX fk_avm_asp_node ON avm_aspects (node_id); +CREATE INDEX fk_avm_ce_child ON avm_child_entries (child_id); +CREATE INDEX fk_avm_ce_parent ON avm_child_entries (parent_id); +CREATE INDEX fk_avm_hl_desc ON avm_history_links (descendent); +CREATE INDEX fk_avm_hl_ancestor ON avm_history_links (ancestor); +CREATE INDEX fk_avm_ml_from ON avm_merge_links (mfrom); +CREATE INDEX fk_avm_ml_to ON avm_merge_links (mto); +CREATE INDEX fk_avm_np_node ON avm_node_properties (node_id); +CREATE INDEX fk_avm_n_acl ON avm_nodes (acl_id); +CREATE INDEX fk_avm_n_store ON avm_nodes (store_new_id); +CREATE INDEX fk_avm_sp_store ON avm_store_properties (avm_store_id); +CREATE INDEX fk_avm_s_root ON avm_stores (current_root_id); +CREATE INDEX fk_avm_vr_store ON avm_version_roots (avm_store_id); +CREATE INDEX fk_avm_vr_root ON avm_version_roots (root_id); + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.0-AVMFKIndexes'; +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.0-AVMFKIndexes', 'Manually executed script upgrade V2.0: AVM Foreign Key Indexes', + 0, 37, -1, 38, null, 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql new file mode 100644 index 0000000000..9911294d56 --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql @@ -0,0 +1,60 @@ +-- +-- Title: Explicit indexes +-- Database: Generic +-- Since: V2.0 Schema 38 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- +-- None of the Hibernate dialects will generate statements for explicit indexes +-- when creating new tables for an existing database. We need to check that the +-- indexes for the AUDIT, JBPM and AVM tables are present. +-- +-- This script must be executed after Hibernate-generated scripts have been executed. +-- Where the updates are being applied long after the tables may have been created, +-- the index creation statements are optional. The the select statements ensure that +-- the script is only executed once the appropriate tables have been created. +-- + +-- JBPM tables +SELECT COUNT(*) FROM JBPM_POOLEDACTOR; +CREATE INDEX IDX_PLDACTR_ACTID ON JBPM_POOLEDACTOR (ACTORID_);(optional) +SELECT COUNT(*) FROM JBPM_TASKINSTANCE; +CREATE INDEX IDX_TASK_ACTORID ON JBPM_TASKINSTANCE (ACTORID_);(optional) + +-- Audit tables +SELECT COUNT(*) FROM alf_audit_date; +CREATE INDEX adt_q_idx ON alf_audit_date (quarter);(optional) +CREATE INDEX adt_dow_idx ON alf_audit_date (day_of_week);(optional) +CREATE INDEX adt_date_idx ON alf_audit_date (date_only);(optional) +CREATE INDEX adt_y_idx ON alf_audit_date (year);(optional) +CREATE INDEX adt_hy_idx ON alf_audit_date (halfYear);(optional) +CREATE INDEX adt_wom_idx ON alf_audit_date (week_of_month);(optional) +CREATE INDEX adt_dom_idx ON alf_audit_date (day_of_month);(optional) +CREATE INDEX adt_m_idx ON alf_audit_date (month);(optional) +CREATE INDEX adt_doy_idx ON alf_audit_date (day_of_year);(optional) +CREATE INDEX adt_woy_idx ON alf_audit_date (week_of_year);(optional) +SELECT COUNT(*) FROM alf_audit_fact; +CREATE INDEX adt_user_idx ON alf_audit_fact (user_id);(optional) +CREATE INDEX adt_store_idx ON alf_audit_fact (store_protocol, store_id, node_uuid);(optional) +SELECT COUNT(*) FROM alf_audit_source; +CREATE INDEX app_source_met_idx ON alf_audit_source (method);(optional) +CREATE INDEX app_source_app_idx ON alf_audit_source (application);(optional) +CREATE INDEX app_source_ser_idx ON alf_audit_source (service);(optional) + +-- AVM tables: These are new so are not optional +CREATE INDEX idx_avm_np_name ON avm_node_properties (qname); +CREATE INDEX idx_avm_sp_name ON avm_store_properties (qname); +CREATE INDEX idx_avm_vr_version ON avm_version_roots (version_id); + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.0-ExplicitIndexes'; +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.0-ExplicitIndexes', 'Manually executed script upgrade V2.0: Explicit Indexes', + 0, 37, -1, 38, null, 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql new file mode 100644 index 0000000000..6a6246717f --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/2.0/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql @@ -0,0 +1,22 @@ +-- +-- Title: AVM Foreign Key indexes +-- Database: MySQL +-- Since: V2.0 Schema 38 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +-- The MySQL dialects apply the FK indexes by default + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.0-AVMFKIndexes'; +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.0-AVMFKIndexes', 'Manually executed script upgrade V2.0: AVM Foreign Key Indexes', + 0, 37, -1, 38, now(), 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 069c0b622e..eaa70cbd3a 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -622,4 +622,26 @@ + + patch.db-V2.0-ExplicitIndexes + patch.schemaUpgradeScript.description + 0 + 37 + 38 + + classpath:alfresco/dbscripts/upgrade/2.0/${db.script.dialect}/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql + + + + + patch.db-V2.0-AVMFKIndexes + patch.schemaUpgradeScript.description + 0 + 37 + 38 + + classpath:alfresco/dbscripts/upgrade/2.0/${db.script.dialect}/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql + + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index f65ccf1cba..93c632e0b7 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=37 +version.schema=38 diff --git a/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java b/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java index eaea2db603..0a9c8a5259 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java @@ -72,11 +72,12 @@ public interface PatchDaoService public List getAppliedPatches(); /** - * Get a list of all patches applied between the given dates + * Get a list of all patches applied between the given dates. * * @param from the lower date limit or null to ignore * @param to the upper date limit or null to ignore - * @return Returns all applied patches + * @return Returns applied patches for the date range, but also patches without + * a date */ public List getAppliedPatches(Date from, Date to); } diff --git a/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java b/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java index 1c414c419c..2b513a5f64 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.admin.patch; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -94,40 +96,46 @@ public class PatchServiceImpl implements PatchService try { - // Diable rules whilst processing the patches - this.ruleService.disableRules(); - try - { - // construct a map of all known patches by ID - Map allPatchesById = new HashMap(23); - for (Patch patch : patches) + // Disable rules whilst processing the patches + this.ruleService.disableRules(); + try { - allPatchesById.put(patch.getId(), patch); - } - // construct a list of executed patches by ID - Map appliedPatchesById = new HashMap(23); - List appliedPatches = patchDaoService.getAppliedPatches(); - for (AppliedPatch appliedPatch : appliedPatches) - { - appliedPatchesById.put(appliedPatch.getId(), appliedPatch); - } - - // go through all the patches and apply them where necessary - for (Patch patch : allPatchesById.values()) - { - // apply the patch - success = applyPatchAndDependencies(patch, appliedPatchesById); - if (!success) + // Sort the patches + List sortedPatches = new ArrayList(patches); + Comparator comparator = new PatchTargetSchemaComparator(); + Collections.sort(sortedPatches, comparator); + + // construct a list of executed patches by ID (also check the date) + Map appliedPatchesById = new HashMap(23); + List appliedPatches = patchDaoService.getAppliedPatches(); + for (AppliedPatch appliedPatch : appliedPatches) { - // we failed to apply a patch or one of its dependencies - terminate - break; + appliedPatchesById.put(appliedPatch.getId(), appliedPatch); + // Update the time of execution if it is null. This is to deal with + // patches that get executed prior to server startup and need to have + // an execution time assigned + if (appliedPatch.getAppliedOnDate() == null) + { + appliedPatch.setAppliedOnDate(new Date()); + } } - } - } - finally - { - this.ruleService.enableRules(); - } + + // go through all the patches and apply them where necessary + for (Patch patch : sortedPatches) + { + // apply the patch + success = applyPatchAndDependencies(patch, appliedPatchesById); + if (!success) + { + // we failed to apply a patch or one of its dependencies - terminate + break; + } + } + } + finally + { + this.ruleService.enableRules(); + } } catch (Throwable exception) { @@ -306,4 +314,21 @@ public class PatchServiceImpl implements PatchService // done return (List) appliedPatches; } + + /** + * Compares patch target schemas. + * + * @see Patch#getTargetSchema() + * @author Derek Hulley + */ + private static class PatchTargetSchemaComparator implements Comparator + { + public int compare(Patch p1, Patch p2) + { + Integer i1 = new Integer(p1.getTargetSchema()); + Integer i2 = new Integer(p2.getTargetSchema()); + return i1.compareTo(i2); + } + + } } diff --git a/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java b/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java index 5f8067f3ac..d0ee386169 100644 --- a/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java +++ b/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java @@ -118,7 +118,7 @@ public class HibernatePatchDaoServiceImpl extends HibernateDaoSupport implements { AppliedPatch appliedPatch = iterator.next(); Date appliedOnDate = appliedPatch.getAppliedOnDate(); - if (fromDate.compareTo(appliedOnDate) >= 0 || toDate.compareTo(appliedOnDate) <= 0) + if (appliedOnDate != null && fromDate.compareTo(appliedOnDate) >= 0 || toDate.compareTo(appliedOnDate) <= 0) { // it is out of range iterator.remove(); diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml index cdbfa06359..4f10625a4a 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml +++ b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml @@ -41,9 +41,9 @@ - + - + column="current_root_id" cascade="save-update" foreign-key="fk_avm_s_root"> @@ -123,7 +123,7 @@ + column="version_id" index="idx_avm_vr_version"> @@ -131,10 +131,10 @@ not-null="true"> + class="AVMStoreImpl" not-null="true" foreign-key="fk_avm_vr_store"> + column="root_id" not-null="true" foreign-key="fk_avm_vr_root"> @@ -142,30 +142,29 @@ - + - + - - + + - - + + - - + + @@ -182,8 +181,8 @@ - - + + @@ -201,7 +200,7 @@ - + diff --git a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java index e54fb3d5e4..b2d4f81699 100644 --- a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java +++ b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java @@ -95,13 +95,15 @@ public class SchemaBootstrap extends AbstractLifecycleBean private boolean updateSchema; private List postCreateScriptUrls; private List validateUpdateScriptPatches; - private List applyUpdateScriptPatches; + private List preUpdateScriptPatches; + private List postUpdateScriptPatches; public SchemaBootstrap() { postCreateScriptUrls = new ArrayList(1); validateUpdateScriptPatches = new ArrayList(4); - applyUpdateScriptPatches = new ArrayList(4); + preUpdateScriptPatches = new ArrayList(4); + postUpdateScriptPatches = new ArrayList(4); } public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory) @@ -154,7 +156,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean * For example, at version 3.0, the upgrade scripts for version 1.4 may be considered * unsupported - this doesn't prevent the manual application of the scripts, though. * - * @param applyUpdateScriptPatches a list of schema patches to check + * @param scriptPatches a list of schema patches to check */ public void setValidateUpdateScriptPatches(List scriptPatches) { @@ -162,13 +164,23 @@ public class SchemaBootstrap extends AbstractLifecycleBean } /** - * Set the schema script patches that may be executed during an update. + * Set the schema script patches that may be applied prior to the auto-update process. * - * @param applyUpdateScriptPatches a list of schema patches to check + * @param scriptPatches a list of schema patches to check */ - public void setApplyUpdateScriptPatches(List scriptPatches) + public void setPreUpdateScriptPatches(List scriptPatches) { - this.applyUpdateScriptPatches = scriptPatches; + this.preUpdateScriptPatches = scriptPatches; + } + + /** + * Set the schema script patches that may be applied after the auto-update process. + * + * @param postUpdateScriptPatches a list of schema patches to check + */ + public void setPostUpdateScriptPatches(List scriptPatches) + { + this.postUpdateScriptPatches = scriptPatches; } /** @@ -350,10 +362,12 @@ public class SchemaBootstrap extends AbstractLifecycleBean } else { - // we have a database, so just run the update scripts - checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); // check for scripts that must have been run - checkSchemaPatchScripts(cfg, session, connection, applyUpdateScriptPatches, true); // execute scripts as required - // let Hibernate do any required updates + // Check for scripts that must have been run + checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); + // Execute any pre-auto-update scripts + checkSchemaPatchScripts(cfg, session, connection, preUpdateScriptPatches, true); + + // Build and execute changes generated by Hibernate File tempFile = null; Writer writer = null; try @@ -383,6 +397,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean { executeScriptFile(cfg, connection, tempFile, tempFile.getPath()); } + + // Execute any post-auto-update scripts + checkSchemaPatchScripts(cfg, session, connection, postUpdateScriptPatches, true); } } @@ -414,7 +431,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean boolean wasSuccessfullyApplied = didPatchSucceed(connection, patchId); if (wasSuccessfullyApplied) { - // nothing to do - it has been done before + // Either the patch was executed before or the system was bootstrapped + // with the patch bean present. continue; } else if (!apply) @@ -574,7 +592,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean { if (logger.isDebugEnabled()) { - logger.debug("Executing statment: " + sql); + logger.debug("Executing statement: " + sql); } stmt.execute(sql); } @@ -626,8 +644,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean } // verify that all patches have been applied correctly - checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); // check scripts - checkSchemaPatchScripts(cfg, session, connection, applyUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, session, connection, validateUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, session, connection, preUpdateScriptPatches, false); // check scripts + checkSchemaPatchScripts(cfg, session, connection, postUpdateScriptPatches, false); // check scripts // all done successfully transaction.commit();