ALF-3266 - further perf improvements (createVersion / getCurrentVersion)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22926 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-10-06 16:36:43 +00:00
parent 7f720478fd
commit fd425423a0

View File

@@ -51,7 +51,7 @@ import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.VersionNumber;
import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
@@ -260,6 +260,8 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
}
Version currentVersion = null;
if (versionHistoryRef == null)
{
// Create the version history
@@ -273,21 +275,38 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
// Since we have an existing version history we should be able to lookup
// the current version
currentVersionRef = getCurrentVersionNodeRef(versionHistoryRef, nodeRef);
Pair<Boolean, Version> result = getCurrentVersionImpl(versionHistoryRef, nodeRef);
boolean headVersion = false;
if (currentVersionRef == null)
if (result != null)
{
currentVersion = result.getSecond();
headVersion = result.getFirst();
}
if (currentVersion == null)
{
throw new VersionServiceException(MSGID_ERR_NOT_FOUND);
}
// Need to check that we are not about to create branch since this is not currently supported
if (! headVersion)
{
// belt-and-braces - remove extra check at some point
// although child assocs should be in ascending time (hence version creation) order
VersionHistory versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
Version currentVersion = getVersion(currentVersionRef);
if (versionHistory.getSuccessors(currentVersion).size() != 0)
if (versionHistory.getSuccessors(currentVersion).size() == 0)
{
if (logger.isDebugEnabled())
{
logger.debug("Belt-and-braces: current version does seem to be head version ["+versionHistoryRef+", "+nodeRef+"]");
}
}
else
{
throw new VersionServiceException(MSGID_ERR_NO_BRANCHES);
}
}
}
// Create the node details
@@ -298,8 +317,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
invokeOnCreateVersion(nodeRef, versionProperties, nodeDetails);
// Calculate the version label
Version preceedingVersion = getVersion(currentVersionRef);
String versionLabel = invokeCalculateVersionLabel(classRef, preceedingVersion, versionNumber, versionProperties);
String versionLabel = invokeCalculateVersionLabel(classRef, currentVersion, versionNumber, versionProperties);
// Extract Type Definition
QName sourceTypeRef = nodeService.getType(nodeRef);
@@ -430,11 +448,14 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
// get the current version, if the 'live' (versioned) node has the "versionable" aspect
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
VersionHistory versionHistory = getVersionHistory(nodeRef);
if (versionHistory != null)
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
if (versionHistoryRef != null)
{
String versionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
version = versionHistory.getVersion(versionLabel);
Pair<Boolean, Version> result = getCurrentVersionImpl(versionHistoryRef, nodeRef);
if (result != null)
{
version = result.getSecond();
}
}
}
@@ -698,22 +719,24 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
*/
protected List<Version> getAllVersions(NodeRef versionHistoryRef)
{
List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, RegexQNamePattern.MATCH_ALL);
List<ChildAssociationRef> versionAssocs = getVersionAssocs(versionHistoryRef, true);
List<Version> versions = new ArrayList<Version>(versionsAssoc.size());
List<Version> versions = new ArrayList<Version>(versionAssocs.size());
for (ChildAssociationRef versionAssoc : versionsAssoc)
{
String localName = versionAssoc.getQName().getLocalName();
if (localName.indexOf(Version2Model.CHILD_VERSIONS+"-") != -1) // TODO - could remove this belts-and-braces, should match correctly above !
for (ChildAssociationRef versionAssoc : versionAssocs)
{
versions.add(getVersion(versionAssoc.getChildRef()));
}
}
return versions;
}
private List<ChildAssociationRef> getVersionAssocs(NodeRef versionHistoryRef, boolean preLoad)
{
// note: resultant list is ordered by (a) explicit index and (b) association creation time
return dbNodeService.getChildAssocs(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, RegexQNamePattern.MATCH_ALL, preLoad);
}
/**
* Builds a version history object from the version history reference.
* <p>
@@ -871,26 +894,39 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
/**
* Gets a reference to the node for the current version of the passed node ref.
* Gets current version of the passed node ref
*
* This uses the version label as a mechanism for looking up the version node in
* the version history.
*
* @param nodeRef a node reference
* @return a reference to a version reference
* This uses the version label as a mechanism for looking up the version node.
*/
private NodeRef getCurrentVersionNodeRef(NodeRef versionHistory, NodeRef nodeRef)
private Pair<Boolean, Version> getCurrentVersionImpl(NodeRef versionHistoryRef, NodeRef nodeRef)
{
NodeRef result = null;
Pair<Boolean, Version> result = null;
String versionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
Collection<ChildAssociationRef> versions = this.dbNodeService.getChildAssocs(versionHistory);
for (ChildAssociationRef version : versions)
// note: resultant list is ordered by (a) explicit index and (b) association creation time
List<ChildAssociationRef> versionAssocs = getVersionAssocs(versionHistoryRef, false);
// Current version should be head version (since no branching)
int cnt = versionAssocs.size();
for (int i = cnt; i > 0; i--)
{
String tempLabel = (String)this.dbNodeService.getProperty(version.getChildRef(), Version2Model.PROP_QNAME_VERSION_LABEL);
ChildAssociationRef versionAssoc = versionAssocs.get(i-1);
String tempLabel = (String)this.dbNodeService.getProperty(versionAssoc.getChildRef(), Version2Model.PROP_QNAME_VERSION_LABEL);
if (tempLabel != null && tempLabel.equals(versionLabel) == true)
{
result = version.getChildRef();
boolean headVersion = (i == cnt);
if (! headVersion)
{
if (logger.isDebugEnabled())
{
logger.debug("Unexpected: current version does not appear to be 1st version in the list ["+versionHistoryRef+", "+nodeRef+"]");
}
}
result = new Pair<Boolean, Version>(headVersion, getVersion(versionAssoc.getChildRef()));
break;
}
}