mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -51,7 +51,7 @@ import org.alfresco.service.cmr.version.VersionService;
|
|||||||
import org.alfresco.service.cmr.version.VersionServiceException;
|
import org.alfresco.service.cmr.version.VersionServiceException;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||||
@@ -260,6 +260,8 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Version currentVersion = null;
|
||||||
|
|
||||||
if (versionHistoryRef == null)
|
if (versionHistoryRef == null)
|
||||||
{
|
{
|
||||||
// Create the version history
|
// 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
|
// Since we have an existing version history we should be able to lookup
|
||||||
// the current version
|
// 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);
|
throw new VersionServiceException(MSGID_ERR_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to check that we are not about to create branch since this is not currently supported
|
// 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);
|
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);
|
throw new VersionServiceException(MSGID_ERR_NO_BRANCHES);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the node details
|
// Create the node details
|
||||||
@@ -298,8 +317,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
invokeOnCreateVersion(nodeRef, versionProperties, nodeDetails);
|
invokeOnCreateVersion(nodeRef, versionProperties, nodeDetails);
|
||||||
|
|
||||||
// Calculate the version label
|
// Calculate the version label
|
||||||
Version preceedingVersion = getVersion(currentVersionRef);
|
String versionLabel = invokeCalculateVersionLabel(classRef, currentVersion, versionNumber, versionProperties);
|
||||||
String versionLabel = invokeCalculateVersionLabel(classRef, preceedingVersion, versionNumber, versionProperties);
|
|
||||||
|
|
||||||
// Extract Type Definition
|
// Extract Type Definition
|
||||||
QName sourceTypeRef = nodeService.getType(nodeRef);
|
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
|
// get the current version, if the 'live' (versioned) node has the "versionable" aspect
|
||||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||||
{
|
{
|
||||||
VersionHistory versionHistory = getVersionHistory(nodeRef);
|
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
|
||||||
if (versionHistory != null)
|
if (versionHistoryRef != null)
|
||||||
{
|
{
|
||||||
String versionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
|
Pair<Boolean, Version> result = getCurrentVersionImpl(versionHistoryRef, nodeRef);
|
||||||
version = versionHistory.getVersion(versionLabel);
|
if (result != null)
|
||||||
|
{
|
||||||
|
version = result.getSecond();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,22 +719,24 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
*/
|
*/
|
||||||
protected List<Version> getAllVersions(NodeRef versionHistoryRef)
|
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)
|
for (ChildAssociationRef versionAssoc : versionAssocs)
|
||||||
{
|
|
||||||
String localName = versionAssoc.getQName().getLocalName();
|
|
||||||
if (localName.indexOf(Version2Model.CHILD_VERSIONS+"-") != -1) // TODO - could remove this belts-and-braces, should match correctly above !
|
|
||||||
{
|
{
|
||||||
versions.add(getVersion(versionAssoc.getChildRef()));
|
versions.add(getVersion(versionAssoc.getChildRef()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return versions;
|
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.
|
* Builds a version history object from the version history reference.
|
||||||
* <p>
|
* <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
|
* This uses the version label as a mechanism for looking up the version node.
|
||||||
* the version history.
|
|
||||||
*
|
|
||||||
* @param nodeRef a node reference
|
|
||||||
* @return a reference to a version reference
|
|
||||||
*/
|
*/
|
||||||
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);
|
String versionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
|
||||||
|
|
||||||
Collection<ChildAssociationRef> versions = this.dbNodeService.getChildAssocs(versionHistory);
|
// note: resultant list is ordered by (a) explicit index and (b) association creation time
|
||||||
for (ChildAssociationRef version : versions)
|
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)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user