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
This commit is contained in:
Derek Hulley 2007-02-16 16:10:44 +00:00
parent f484e98638
commit b4e48157f5
15 changed files with 294 additions and 105 deletions

View File

@ -35,19 +35,25 @@
</property>
<property name="postCreateScriptUrls">
<list>
<value>classpath:alfresco/dbscripts/create/1.4/${db.script.dialect}/post-create-indexes.sql</value>
<value>classpath:alfresco/dbscripts/create/2.0/${db.script.dialect}/AlfrescoPostCreate-2.0-FKIndexes.sql</value>
</list>
</property>
<property name="validateUpdateScriptPatches">
<list>
</list>
</property>
<property name="applyUpdateScriptPatches">
<property name="preUpdateScriptPatches">
<list>
<ref bean="patch.schemaUpdateScript-V1.4-1" />
<ref bean="patch.schemaUpdateScript-V1.4-2" />
</list>
</property>
<property name="postUpdateScriptPatches">
<list>
<ref bean="patch.db-V2.0-ExplicitIndexes" />
<ref bean="patch.db-V2.0-AVMFKIndexes" />
</list>
</property>
</bean>
<!-- Bootstrap the AVM -->

View File

@ -1,3 +0,0 @@
--
-- Add post-creation indexes. (Generic Schema 1.4)
--

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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'
);

View File

@ -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'
);

View File

@ -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'
);

View File

@ -622,4 +622,26 @@
</property>
</bean>
<bean id="patch.db-V2.0-ExplicitIndexes" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
<property name="id"><value>patch.db-V2.0-ExplicitIndexes</value></property>
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>37</value></property>
<property name="targetSchema"><value>38</value></property>
<property name="scriptUrl">
<value>classpath:alfresco/dbscripts/upgrade/2.0/${db.script.dialect}/AlfrescoSchemaUpdate-2.0-ExplicitIndexes.sql</value>
</property>
</bean>
<bean id="patch.db-V2.0-AVMFKIndexes" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
<property name="id"><value>patch.db-V2.0-AVMFKIndexes</value></property>
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>37</value></property>
<property name="targetSchema"><value>38</value></property>
<property name="scriptUrl">
<value>classpath:alfresco/dbscripts/upgrade/2.0/${db.script.dialect}/AlfrescoSchemaUpdate-2.0-AVMFKIndexes.sql</value>
</property>
</bean>
</beans>

View File

@ -19,4 +19,4 @@ version.build=@build-number@
# Schema number
version.schema=37
version.schema=38

View File

@ -72,11 +72,12 @@ public interface PatchDaoService
public List<AppliedPatch> 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<AppliedPatch> getAppliedPatches(Date from, Date to);
}

View File

@ -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<String, Patch> allPatchesById = new HashMap<String, Patch>(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<String, AppliedPatch> appliedPatchesById = new HashMap<String, AppliedPatch>(23);
List<AppliedPatch> 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<Patch> sortedPatches = new ArrayList<Patch>(patches);
Comparator<Patch> comparator = new PatchTargetSchemaComparator();
Collections.sort(sortedPatches, comparator);
// construct a list of executed patches by ID (also check the date)
Map<String, AppliedPatch> appliedPatchesById = new HashMap<String, AppliedPatch>(23);
List<AppliedPatch> 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<PatchInfo>) appliedPatches;
}
/**
* Compares patch target schemas.
*
* @see Patch#getTargetSchema()
* @author Derek Hulley
*/
private static class PatchTargetSchemaComparator implements Comparator<Patch>
{
public int compare(Patch p1, Patch p2)
{
Integer i1 = new Integer(p1.getTargetSchema());
Integer i2 = new Integer(p2.getTargetSchema());
return i1.compareTo(i2);
}
}
}

View File

@ -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();

View File

@ -41,9 +41,9 @@
<property name="accessDate" type="long" not-null="true"/>
</component>
<property name="isRoot" column="is_root" type="boolean"/>
<many-to-one name="storeNew" class="AVMStoreImpl" column="store_new_id"/>
<many-to-one name="storeNew" class="AVMStoreImpl" column="store_new_id" foreign-key="fk_avm_n_store"/>
<!-- ACL -->
<many-to-one name="acl" column="acl_id"
<many-to-one name="acl" column="acl_id" foreign-key="fk_avm_n_acl"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"/>
<!-- Deleted nodes -->
<subclass name="DeletedNodeImpl"
@ -114,7 +114,7 @@
column="next_version_id" not-null="true"/>
<!-- Every AVMStore has a root directory that is the current root directory. -->
<many-to-one name="root" class="DirectoryNodeImpl"
column="current_root_id" cascade="save-update">
column="current_root_id" cascade="save-update" foreign-key="fk_avm_s_root">
</many-to-one>
</class>
<class name="VersionRootImpl" proxy="VersionRoot" table="avm_version_roots">
@ -123,7 +123,7 @@
<generator class="native"></generator>
</id>
<property name="versionID" type="int" not-null="true"
column="version_id" index="version_roots_version_id_index">
column="version_id" index="idx_avm_vr_version">
</property>
<property name="createDate" type="long" not-null="true" column="create_date">
</property>
@ -131,10 +131,10 @@
not-null="true">
</property>
<many-to-one name="avmStore" column="avm_store_id"
class="AVMStoreImpl" not-null="true">
class="AVMStoreImpl" not-null="true" foreign-key="fk_avm_vr_store">
</many-to-one>
<many-to-one name="root" class="DirectoryNodeImpl"
column="root_id" not-null="true">
column="root_id" not-null="true" foreign-key="fk_avm_vr_root">
</many-to-one>
<property name="tag" type="string" length="255" column="tag"/>
<property name="description" type="string" length="4000" column="description"/>
@ -142,30 +142,29 @@
<class name="ChildEntryImpl" proxy="ChildEntry" table="avm_child_entries">
<cache usage="read-write"/>
<composite-id name="key" class="ChildKey">
<key-many-to-one name="parent" column="parent_id" class="DirectoryNodeImpl"/>
<key-many-to-one name="parent" column="parent_id" class="DirectoryNodeImpl" foreign-key="fk_avm_ce_parent"/>
<key-property name="name" column="name" type="string" length="160"/>
</composite-id>
<many-to-one name="child" column="child_id" class="AVMNodeImpl"
not-null="true"/>
<many-to-one name="child" column="child_id" class="AVMNodeImpl" not-null="true" foreign-key="fk_avm_ce_child"/>
</class>
<class name="HistoryLinkImpl" proxy="HistoryLink" table="avm_history_links">
<composite-id>
<key-many-to-one name="ancestor" class="AVMNodeImpl" column="ancestor"/>
<key-many-to-one name="descendent" class="AVMNodeImpl" column="descendent"/>
<key-many-to-one name="ancestor" class="AVMNodeImpl" column="ancestor" foreign-key="fk_avm_hl_ancestor"/>
<key-many-to-one name="descendent" class="AVMNodeImpl" column="descendent" foreign-key="fk_avm_hl_desc"/>
</composite-id>
</class>
<class name="MergeLinkImpl" proxy="MergeLink" table="avm_merge_links">
<composite-id>
<key-many-to-one name="mfrom" class="AVMNodeImpl" column="mfrom"/>
<key-many-to-one name="mto" class="AVMNodeImpl" column="mto"/>
<key-many-to-one name="mfrom" class="AVMNodeImpl" column="mfrom" foreign-key="fk_avm_ml_from"/>
<key-many-to-one name="mto" class="AVMNodeImpl" column="mto" foreign-key="fk_avm_ml_to"/>
</composite-id>
</class>
<class name="AVMNodePropertyImpl" proxy="AVMNodeProperty" table="avm_node_properties">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="node" class="AVMNodeImpl" column="node_id"/>
<property name="name" column="qname" type="QName" length="200" index="node_property_name_index"/>
<many-to-one name="node" class="AVMNodeImpl" column="node_id" foreign-key="fk_avm_np_node"/>
<property name="name" column="qname" type="QName" length="200" index="idx_avm_np_name"/>
<component class="org.alfresco.repo.domain.PropertyValue" name="value">
<property name="actualType" column="actual_type" type="string" length="15" not-null="true" />
<property name="multiValued" column="multi_valued" type="boolean" not-null="true" />
@ -182,8 +181,8 @@
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="store" class="AVMStoreImpl" column="avm_store_id"/>
<property name="name" column="qname" type="QName" length="200" index="store_property_name_index"/>
<many-to-one name="store" class="AVMStoreImpl" column="avm_store_id" foreign-key="fk_avm_sp_store"/>
<property name="name" column="qname" type="QName" length="200" index="idx_avm_sp_name"/>
<component class="org.alfresco.repo.domain.PropertyValue" name="value">
<property name="actualType" column="actual_type" type="string" length="15" not-null="true" />
<property name="multiValued" column="multi_valued" type="boolean" not-null="true" />
@ -201,7 +200,7 @@
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="node" class="AVMNodeImpl" column="node_id"/>
<many-to-one name="node" class="AVMNodeImpl" column="node_id" foreign-key="fk_avm_asp_node"/>
<property name="name" column="qname" type="QName" length="200"/>
</class>
<query name="ChildEntry.DeleteByParent">

View File

@ -95,13 +95,15 @@ public class SchemaBootstrap extends AbstractLifecycleBean
private boolean updateSchema;
private List<String> postCreateScriptUrls;
private List<SchemaUpgradeScriptPatch> validateUpdateScriptPatches;
private List<SchemaUpgradeScriptPatch> applyUpdateScriptPatches;
private List<SchemaUpgradeScriptPatch> preUpdateScriptPatches;
private List<SchemaUpgradeScriptPatch> postUpdateScriptPatches;
public SchemaBootstrap()
{
postCreateScriptUrls = new ArrayList<String>(1);
validateUpdateScriptPatches = new ArrayList<SchemaUpgradeScriptPatch>(4);
applyUpdateScriptPatches = new ArrayList<SchemaUpgradeScriptPatch>(4);
preUpdateScriptPatches = new ArrayList<SchemaUpgradeScriptPatch>(4);
postUpdateScriptPatches = new ArrayList<SchemaUpgradeScriptPatch>(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<SchemaUpgradeScriptPatch> 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<SchemaUpgradeScriptPatch> scriptPatches)
public void setPreUpdateScriptPatches(List<SchemaUpgradeScriptPatch> 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<SchemaUpgradeScriptPatch> 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();