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

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