Fixed ALF-4190: fixNameCrcValues-2 fails on 3.4

- Finished implementation: Missing bean injection, update parameters wrong way around, etc
 - Improved performance (negative name crc values can be left as is)
 - Tested 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21814 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-08-16 18:28:34 +00:00
parent 103c17d160
commit b55d27f553
4 changed files with 43 additions and 18 deletions

View File

@@ -302,8 +302,8 @@
update
alf_child_assoc
set
qname_crc = ?,
child_node_name_crc = ?
child_node_name_crc = ?,
qname_crc = ?
where
id = ?
</update>

View File

@@ -304,6 +304,8 @@ patch.fixNameCrcValues.description=Fixes name and qname CRC32 values to match UT
patch.fixNameCrcValues.result=Fixed CRC32 values for UTF-8 encoding for {0} node child associations. See file {1} for details.
patch.fixNameCrcValues.fixed=Updated CRC32 values for association ID {0}, name ''{1}'': {2} -> {3}, qname ''{4}'': {5} -> {6}.
patch.fixNameCrcValues.unableToChange=Failed to update the CRC32 value for association ID {0}: \n Node name: {1} \n name CRC old: {2} \n name CRC new: {3} \n qname: {4} \n qname CRC old: {5} \n qname CRC new: {6} \n Error: {7}
patch.fixNameCrcValues.associationTypeNotDefined=Association type ''{0}'' has not been defined.
patch.fixNameCrcValues.associationTypeNotChild=Association type ''{0}'' does not represent a child association but is used as one.
patch.personUsagePatch.description=Add person 'cm:sizeCurrent' property (if missing).
patch.personUsagePatch.result1=Added 'cm:sizeCurrent' property to {0} people that were missing this property.

View File

@@ -1965,6 +1965,9 @@
<property name="controlDAO">
<ref bean="controlDAO" />
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
</bean>
<bean id="patch.redeployNominatedInvitationProcessWithPropsForShare" class="org.alfresco.repo.admin.patch.impl.GenericWorkflowPatch" parent="basePatch" >

View File

@@ -29,6 +29,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.alfresco.error.StackTraceUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.admin.patch.PatchExecuter;
import org.alfresco.repo.batch.BatchProcessWorkProvider;
@@ -39,6 +40,7 @@ import org.alfresco.repo.domain.node.ChildAssocEntity;
import org.alfresco.repo.domain.patch.PatchDAO;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
@@ -59,6 +61,8 @@ public class FixNameCrcValuesPatch extends AbstractPatch
private static final String MSG_SUCCESS = "patch.fixNameCrcValues.result";
private static final String MSG_REWRITTEN = "patch.fixNameCrcValues.fixed";
private static final String MSG_UNABLE_TO_CHANGE = "patch.fixNameCrcValues.unableToChange";
private static final String ERR_ASSOCIATION_TYPE_NOT_DEFINED = "patch.fixNameCrcValues.associationTypeNotDefined";
private static final String ERR_ASSOCIATION_TYPE_NOT_CHILD = "patch.fixNameCrcValues.associationTypeNotChild";
private PatchDAO patchDAO;
private QNameDAO qnameDAO;
@@ -107,6 +111,8 @@ public class FixNameCrcValuesPatch extends AbstractPatch
super.checkProperties();
checkPropertyNotNull(patchDAO, "patchDAO");
checkPropertyNotNull(qnameDAO, "qnameDAO");
checkPropertyNotNull(controlDAO, "controlDAO");
checkPropertyNotNull(dictionaryService, "dictionaryService");
checkPropertyNotNull(applicationEventPublisher, "applicationEventPublisher");
}
@@ -236,11 +242,29 @@ public class FixNameCrcValuesPatch extends AbstractPatch
ChildAssocEntity entity = new ChildAssocEntity();
entity.setChildNodeNameAll(dictionaryService, typeQName, childNodeName);
entity.setQNameAll(qnameDAO, qname, false);
// Check the CRC values for cm:name
if (entity.getChildNodeNameCrc().equals(childNodeNameCrc))
Long childNodeNameCrcNew = entity.getChildNodeNameCrc();
Long qnameCrcNew = entity.getQnameCrc();
entity = null; // Just checking that we don't misuse it
AssociationDefinition assocDef = dictionaryService.getAssociation(typeQName);
if (assocDef == null)
{
throw new DictionaryException(ERR_ASSOCIATION_TYPE_NOT_DEFINED, typeQName, assocId);
}
else if (!assocDef.isChild())
{
throw new DictionaryException(ERR_ASSOCIATION_TYPE_NOT_CHILD, typeQName, assocId);
}
ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
boolean requiresNameConstraint = !childAssocDef.getDuplicateChildNamesAllowed();
// Check the CRC for the QName
if (entity.getQnameCrc().equals(qnameCrc))
if (qnameCrcNew.equals(qnameCrc))
{
// Check the CRC values for cm:name
// - value might have stayed the same
// - Any existing name crc negative value is fine if the name constraint need not be enforced
if (childNodeNameCrcNew.equals(childNodeNameCrc) || (childNodeNameCrc < 0 && !requiresNameConstraint))
{
// This child assoc is good
return;
@@ -250,22 +274,16 @@ public class FixNameCrcValuesPatch extends AbstractPatch
Savepoint savepoint = null;
try
{
AssociationDefinition assocDef = dictionaryService.getAssociation(typeQName);
if (assocDef == null)
{
throw new DictionaryException("Association type not defined: " + typeQName);
}
// Being here indicates that the association needs to be updated
savepoint = controlDAO.createSavepoint("FixNameCrcValuesPatch");
patchDAO.updateChildAssocCrc(assocId, childNodeNameCrc, qnameCrc);
patchDAO.updateChildAssocCrc(assocId, childNodeNameCrcNew, qnameCrcNew);
controlDAO.releaseSavepoint(savepoint);
String msg = I18NUtil.getMessage(
MSG_REWRITTEN,
assocId,
childNodeName, childNodeNameCrc, entity.getChildNodeNameCrc(),
qname, qnameCrc, entity.getQnameCrc());
childNodeName, childNodeNameCrc, childNodeNameCrcNew,
qname, qnameCrc, qnameCrcNew);
writeLine(msg);
}
catch (Throwable e)
@@ -277,8 +295,8 @@ public class FixNameCrcValuesPatch extends AbstractPatch
String msg = I18NUtil.getMessage(
MSG_UNABLE_TO_CHANGE,
assocId,
childNodeName, childNodeNameCrc, entity.getChildNodeNameCrc(),
qname, qnameCrc, entity.getQnameCrc(),
childNodeName, childNodeNameCrc, childNodeNameCrcNew,
qname, qnameCrc, qnameCrcNew,
e.getMessage());
// We just log this and add details to the message file
if (logger.isDebugEnabled())
@@ -289,7 +307,9 @@ public class FixNameCrcValuesPatch extends AbstractPatch
{
logger.warn(msg);
}
writeLine(msg);
StringBuilder sb = new StringBuilder(1024);
StackTraceUtil.buildStackTrace(msg, e.getStackTrace(), sb, 0);
writeLine(sb.toString());
}
}