Merged DEV/V3.3-DAO-REFACTOR to HEAD

18684: SAIL-238 - VersionCount.hbm.xml (removal)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18778 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-02-23 11:53:43 +00:00
parent 354d14e7f5
commit 9a414238af
34 changed files with 281 additions and 1193 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -40,7 +40,6 @@ import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.version.common.counter.VersionCounterService;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
@@ -59,14 +58,13 @@ import org.alfresco.util.BaseSpringTest;
public abstract class BaseVersionStoreTest extends BaseSpringTest
{
/*
/*
* Services used by the tests
*/
protected NodeService dbNodeService;
protected NodeService dbNodeService;
protected VersionService versionService;
protected VersionCounterService versionCounterDaoService;
protected ContentService contentService;
protected DictionaryDAO dictionaryDAO;
protected DictionaryDAO dictionaryDAO;
protected MutableAuthenticationService authenticationService;
protected TransactionService transactionService;
protected RetryingTransactionHelper txnHelper;
@@ -74,7 +72,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
protected NodeArchiveService nodeArchiveService;
protected NodeService nodeService;
protected PermissionService permissionService;
/*
* Data used by tests
*/
@@ -89,24 +87,24 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
protected HashMap<String, NodeRef> versionableNodes;
/*
* Proprety names and values
* Property names and values
*/
protected static final String TEST_NAMESPACE = "http://www.alfresco.org/test/versionstorebasetest/1.0";
protected static final QName TEST_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "testtype");
protected static final QName TEST_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "testtype");
protected static final QName TEST_ASPECT_QNAME = QName.createQName(TEST_NAMESPACE, "testaspect");
protected static final QName PROP_1 = QName.createQName(TEST_NAMESPACE, "prop1");
protected static final QName PROP_2 = QName.createQName(TEST_NAMESPACE, "prop2");
protected static final QName PROP_3 = QName.createQName(TEST_NAMESPACE, "prop3");
protected static final QName PROP_1 = QName.createQName(TEST_NAMESPACE, "prop1");
protected static final QName PROP_2 = QName.createQName(TEST_NAMESPACE, "prop2");
protected static final QName PROP_3 = QName.createQName(TEST_NAMESPACE, "prop3");
protected static final QName MULTI_PROP = QName.createQName(TEST_NAMESPACE, "multiProp");
protected static final String VERSION_PROP_1 = "versionProp1";
protected static final String VERSION_PROP_2 = "versionProp2";
protected static final String VERSION_PROP_3 = "versionProp3";
protected static final String VALUE_1 = "value1";
protected static final String VALUE_2 = "value2";
protected static final String VALUE_3 = "value3";
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
protected static final String VERSION_PROP_1 = "versionProp1";
protected static final String VERSION_PROP_2 = "versionProp2";
protected static final String VERSION_PROP_3 = "versionProp3";
protected static final String VALUE_1 = "value1";
protected static final String VALUE_2 = "value2";
protected static final String VALUE_3 = "value3";
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
protected Collection<String> multiValue = null;
protected static final String MULTI_VALUE_1 = "multi1";
@@ -155,7 +153,6 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
// Get the services by name from the application context
this.dbNodeService = (NodeService)applicationContext.getBean("dbNodeService");
this.versionCounterDaoService = (VersionCounterService)applicationContext.getBean("versionCounterService");
this.contentService = (ContentService)applicationContext.getBean("contentService");
this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
@@ -176,7 +173,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
this.versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VERSION_PROP_1, VALUE_1);
versionProperties.put(VERSION_PROP_2, VALUE_2);
versionProperties.put(VERSION_PROP_3, VALUE_3);
versionProperties.put(VERSION_PROP_3, VALUE_3);
// Create the node properties
this.nodeProperties = new HashMap<QName, Serializable>();
@@ -188,7 +185,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
// Add mlText property
this.mlText = new MLText(Locale.UK, "UK value");
this.mlText.addValue(Locale.US, "Y'all US value");
this.mlText.addValue(Locale.US, "Y'all US value");
this.nodeProperties.put(MLTEXT_PROP, this.mlText);
// Create a workspace that contains the 'live' nodes
@@ -249,10 +246,10 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}MyVersionableNode"),
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(nodeRef);
@@ -270,23 +267,23 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
// Add some children to the node
NodeRef child1 = this.dbNodeService.createNode(
nodeRef,
TEST_CHILD_ASSOC_1,
TEST_CHILD_ASSOC_1,
TEST_TYPE_QNAME,
TEST_CHILD_ASSOC_1,
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(child1, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
this.dbNodeService.addAspect(child1, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(child1);
this.versionableNodes.put(child1.getId(), child1);
NodeRef child2 = this.dbNodeService.createNode(
nodeRef,
TEST_CHILD_ASSOC_2,
TEST_CHILD_ASSOC_2,
TEST_TYPE_QNAME,
TEST_CHILD_ASSOC_2,
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
if (versionable)
@@ -300,9 +297,9 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
// Create a node that can be associated with the root node
NodeRef assocNode = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}MyAssocNode"),
TEST_TYPE_QNAME,
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
assertNotNull(assocNode);
this.dbNodeService.createAssociation(nodeRef, assocNode, TEST_ASSOC);
@@ -332,16 +329,15 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
*/
protected Version createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties)
{
// Get the next version number
int nextVersion = peekNextVersionNumber();
String nextVersionLabel = peekNextVersionLabel(versionableNode, nextVersion, versionProperties);
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
// Now lets create a new version for this node
Version newVersion = versionService.createVersion(versionableNode, this.versionProperties);
checkNewVersion(beforeVersionTime, nextVersion, nextVersionLabel, newVersion, versionableNode);
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
// Return the new version
return newVersion;
@@ -349,9 +345,8 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
protected Collection<Version> createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties, boolean versionChildren)
{
// Get the next version number
int nextVersion = peekNextVersionNumber();
String nextVersionLabel = peekNextVersionLabel(versionableNode, nextVersion, versionProperties);
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
@@ -360,56 +355,49 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
Collection<Version> versions = versionService.createVersion(versionableNode, this.versionProperties, versionChildren);
// Check the returned versions are correct
checkVersionCollection(nextVersion, nextVersionLabel, beforeVersionTime, versions);
checkVersionCollection(nextVersionLabel, beforeVersionTime, versions);
// Return the new versions
return versions;
}
/**
* Gets the next version label
*/
protected String peekNextVersionLabel(NodeRef nodeRef, int versionNumber, Map<String, Serializable> versionProperties)
{
Version version = this.versionService.getCurrentVersion(nodeRef);
SerialVersionLabelPolicy policy = new SerialVersionLabelPolicy();
return policy.calculateVersionLabel(ContentModel.TYPE_CMOBJECT, version, versionNumber, versionProperties);
}
/**
* Gets the next version label
*/
protected String peekNextVersionLabel(NodeRef nodeRef, Map<String, Serializable> versionProperties)
{
Version version = this.versionService.getCurrentVersion(nodeRef);
SerialVersionLabelPolicy policy = new SerialVersionLabelPolicy();
return policy.calculateVersionLabel(ContentModel.TYPE_CMOBJECT, version, versionProperties);
}
/**
* Checkd the validity of a new version
*
* @param beforeVersionTime the time snap shot before the version was created
* @param expectedVersionNumber the expected version number
* @param newVersion the new version
* @param versionableNode the versioned node
*/
protected void checkVersion(long beforeVersionTime, int expectedVersionNumber, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
protected void checkVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
{
assertNotNull(newVersion);
// Check the version label and version number
// Check the version label
assertEquals(
"The expected version number was not used.",
Integer.toString(expectedVersionNumber),
newVersion.getVersionProperty(VersionBaseModel.PROP_VERSION_NUMBER).toString());
assertEquals(
"The expected version label was not used.",
expectedVersionLabel,
newVersion.getVersionLabel());
"The expected version label was not used.",
expectedVersionLabel,
newVersion.getVersionLabel());
// Check the created date
long afterVersionTime = System.currentTimeMillis();
long createdDate = newVersion.getCreatedDate().getTime();
long createdDate = newVersion.getFrozenModifiedDate().getTime();
if (createdDate < beforeVersionTime || createdDate > afterVersionTime)
{
fail("The created date of the version is incorrect.");
}
// Check the creator
assertEquals(AuthenticationUtil.getAdminUserName(), newVersion.getCreator());
assertEquals(AuthenticationUtil.getAdminUserName(), newVersion.getFrozenModifier());
// Check the metadata properties of the version
Map<String, Serializable> props = newVersion.getVersionProperties();
@@ -444,7 +432,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
}
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
{
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
assertEquals(
VersionModel.STORE_ID,
nodeRef.getStoreRef().getIdentifier());
@@ -455,9 +443,9 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
}
}
protected void checkNewVersion(long beforeVersionTime, int expectedVersionNumber, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
protected void checkNewVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
{
checkVersion(beforeVersionTime, expectedVersionNumber, expectedVersionLabel, newVersion, versionableNode);
checkVersion(beforeVersionTime, expectedVersionLabel, newVersion, versionableNode);
// TODO: How do we check the frozen attributes ??
@@ -471,11 +459,10 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
/**
* Helper method to check the validity of the list of newly created versions.
*
* @param expectedVersionNumber the expected version number that all the versions should have
* @param beforeVersionTime the time before the versions where created
* @param versions the collection of version objects
*/
private void checkVersionCollection(int expectedVersionNumber, String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
private void checkVersionCollection(String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
{
for (Version version : versions)
{
@@ -485,7 +472,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
// Switch VersionStore depending on configured impl
if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID))
{
// V2 version store (eg. workspace://version2Store)
// V2 version store (eg. workspace://version2Store)
frozenNodeId = ((NodeRef)version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId();
}
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
@@ -501,19 +488,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
assertNotNull("The versionable node ref that relates to the frozen node id can not be found.", origionaNodeRef);
// Check the new version
checkNewVersion(beforeVersionTime, expectedVersionNumber, expectedVersionLabel, version, origionaNodeRef);
checkNewVersion(beforeVersionTime, expectedVersionLabel, version, origionaNodeRef);
}
}
/**
* Returns the next version number without affecting the version counter.
*
* @return the next version number to be allocated
*/
protected int peekNextVersionNumber()
{
StoreRef lwVersionStoreRef = this.versionService.getVersionStoreReference();
return this.versionCounterDaoService.currentVersionNumber(lwVersionStoreRef) + 1;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -64,7 +64,12 @@ public interface Version2Model extends VersionBaseModel
public static final String PROP_VERSION_DESCRIPTION = "versionDescription"; // maps from description
public static final QName PROP_QNAME_VERSION_LABEL = QName.createQName(NAMESPACE_URI, PROP_VERSION_LABEL);
/**
* @deprecated
*/
public static final QName PROP_QNAME_VERSION_NUMBER = QName.createQName(NAMESPACE_URI, PROP_VERSION_NUMBER);
public static final QName PROP_QNAME_VERSION_DESCRIPTION = QName.createQName(NAMESPACE_URI, PROP_VERSION_DESCRIPTION);
// frozen sys:referenceable properties (x4)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -55,9 +55,9 @@ 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.springframework.extensions.surf.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Version2 Service - implements version2Store (a lighter implementation of the lightWeightVersionStore)
@@ -123,15 +123,14 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
long startTime = System.currentTimeMillis();
// Get the next version number
int versionNumber = this.versionCounterService.nextVersionNumber(getVersionStoreReference());
int versionNumber = 0; // deprecated (unused)
// Create the version
Version version = createVersion(nodeRef, versionProperties, versionNumber);
if (logger.isDebugEnabled())
{
logger.debug("created version (" + versionNumber + " - " + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis()-startTime) + " ms");
logger.debug("created version (" + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis()-startTime) + " ms");
}
return version;
@@ -159,9 +158,8 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
Collection<Version> result = new ArrayList<Version>(nodeRefs.size());
// Get the next version number
int versionNumber = this.versionCounterService.nextVersionNumber(getVersionStoreReference());
int versionNumber = 0; // deprecated (unused)
// Version each node in the list
for (NodeRef nodeRef : nodeRefs)
{
@@ -170,7 +168,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
if (logger.isDebugEnabled())
{
logger.debug("created version list (" + versionNumber + " - " + getVersionStoreReference() + ") in "+ (System.currentTimeMillis()-startTime) +" ms (with " + nodeRefs.size() + " nodes)");
logger.debug("created version list (" + getVersionStoreReference() + ") in "+ (System.currentTimeMillis()-startTime) +" ms (with " + nodeRefs.size() + " nodes)");
}
return result;
@@ -294,7 +292,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
if (logger.isTraceEnabled())
{
logger.trace("created version (" + versionNumber + " - " + getVersionStoreReference() + ") " + newVersionRef + " " + (System.currentTimeMillis()-startTime) +" ms");
logger.trace("created version (" + getVersionStoreReference() + ") " + newVersionRef + " " + (System.currentTimeMillis()-startTime) +" ms");
}
// Return the data object representing the newly created version
@@ -387,15 +385,15 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
Map<QName, Serializable> result = new HashMap<QName, Serializable>(10);
// Set the version number
result.put(Version2Model.PROP_QNAME_VERSION_NUMBER, versionNumber);
// deprecated (unused)
//result.put(Version2Model.PROP_QNAME_VERSION_NUMBER, versionNumber);
// Set the version label
result.put(Version2Model.PROP_QNAME_VERSION_LABEL, versionLabel);
// Set the version description (can be null)
result.put(Version2Model.PROP_QNAME_VERSION_DESCRIPTION, versionDescription);
// Set the versionable node store id
result.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, nodeRef);
@@ -604,9 +602,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
VersionHistory versionHistory = null;
List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, RegexQNamePattern.MATCH_ALL);
List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, RegexQNamePattern.MATCH_ALL);
List<Version> versions = new ArrayList<Version>(versionsAssoc.size());
for (ChildAssociationRef versionAssoc : versionsAssoc)
@@ -619,7 +617,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
Collections.sort(versions, versionComparatorAsc);
// Build the version history object
boolean isRoot = true;
Version preceeding = null;
@@ -639,7 +637,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return versionHistory;
}
/**
* Constructs the a version object to contain the version information from the version node ref.
*
@@ -658,7 +656,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return null;
}
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
// Get the standard node details and get the meta data
Map<QName, Serializable> nodeProperties = this.dbNodeService.getProperties(versionRef);
@@ -692,7 +690,8 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
else if (key.equals(Version2Model.PROP_QNAME_VERSION_NUMBER))
{
versionProperties.put(VersionBaseModel.PROP_VERSION_NUMBER, (Integer)value);
// deprecated (unused)
//versionProperties.put(VersionBaseModel.PROP_VERSION_NUMBER, (Integer)value);
}
else
{
@@ -1034,45 +1033,18 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
*/
private Version getHeadVersion(NodeRef nodeRef)
{
Version version = null;
StoreRef storeRef = nodeRef.getStoreRef();
NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef);
Version headVersion = null;
if (versionHistoryNodeRef != null)
{
List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryNodeRef, Version2Model.CHILD_QNAME_VERSIONS, RegexQNamePattern.MATCH_ALL);
ChildAssociationRef headVersionAssoc = null;
int headVersionNumber = -1;
for (ChildAssociationRef versionAssoc : versionsAssoc)
VersionHistory versionHistory = buildVersionHistory(versionHistoryNodeRef, nodeRef);
if (versionHistory != null)
{
String localName = versionAssoc.getQName().getLocalName();
if (localName.indexOf(Version2Model.CHILD_VERSIONS+"-") != -1) // TODO - could remove this belts-and-braces, should match correctly above !
{
int versionNumber = Integer.parseInt(localName.substring((Version2Model.CHILD_VERSIONS+"-").length()));
if (versionNumber > headVersionNumber)
{
headVersionNumber = versionNumber;
headVersionAssoc = versionAssoc;
}
}
headVersion = versionHistory.getHeadVersion();
}
if (headVersionAssoc != null)
{
NodeRef versionNodeRef = headVersionAssoc.getChildRef();
NodeRef versionedNodeRef = (NodeRef)this.dbNodeService.getProperty(
versionNodeRef,
QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.PROP_FROZEN_NODE_REF));
StoreRef versionStoreRef = versionedNodeRef.getStoreRef();
if (storeRef.equals(versionStoreRef) == true)
{
version = getVersion(versionNodeRef);
}
}
}
return version;
return headVersion;
}
/* (non-Javadoc)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -46,6 +46,10 @@ public interface VersionBaseModel
public static final String PROP_CREATED_DATE = ContentModel.PROP_CREATED.getLocalName();
public static final String PROP_CREATOR = ContentModel.PROP_CREATOR.getLocalName();
public static final String PROP_VERSION_TYPE = "versionType";
/**
* @deprecated since 3.3
*/
public static final String PROP_VERSION_NUMBER = "versionNumber";
/** The version store root aspect localname*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -201,7 +201,7 @@ public class VersionMigrator
// ALFCOM-2658
nodeProperties.put(ContentModel.PROP_NODE_UUID, frozenStateNodeRef.getId());
int versionNumber = (Integer)dbNodeService.getProperty(VersionUtil.convertNodeRef(frozenStateNodeRef), VersionModel.PROP_QNAME_VERSION_NUMBER);
int versionNumber = 0;
// get oldVersion auditable properties (of the version node itself, rather than the live versioned node)
Date versionCreated = (Date)dbNodeService.getProperty(VersionUtil.convertNodeRef(frozenStateNodeRef), ContentModel.PROP_CREATED);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -35,13 +35,11 @@ import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.common.counter.VersionCounterService;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.NamespaceService;
@@ -65,7 +63,6 @@ public class VersionMigratorTest extends BaseVersionStoreTest
protected PolicyComponent policyComponent;
protected DictionaryService dictionaryService;
protected CheckOutCheckInService cociService;
protected VersionCounterService versionCounterService;
protected IntegrityChecker integrityChecker;
public VersionMigratorTest()
@@ -84,14 +81,11 @@ public class VersionMigratorTest extends BaseVersionStoreTest
this.versionNodeService = (NodeService)applicationContext.getBean("versionNodeService"); // note: auto-switches between V1 and V2
this.cociService = (CheckOutCheckInService)applicationContext.getBean("CheckoutCheckinService");
this.versionCounterService = (VersionCounterService)applicationContext.getBean("versionCounterService");
this.integrityChecker = (IntegrityChecker)applicationContext.getBean("integrityChecker");
// Version1Service is used to create the version nodes in Version1Store (workspace://lightWeightVersionStore)
version1Service.setDbNodeService(dbNodeService);
version1Service.setNodeService(dbNodeService);
version1Service.setVersionCounterService(versionCounterDaoService);
version1Service.setPolicyComponent(policyComponent);
version1Service.setDictionaryService(dictionaryService);
version1Service.initialiseWithoutBind(); // TODO - temp - if use intialise, get: "More than one CalculateVersionLabelPolicy behaviour has been registered for the type {http://www.alfresco.org/model/content/1.0}content"
@@ -114,9 +108,8 @@ public class VersionMigratorTest extends BaseVersionStoreTest
logger.info("testMigrateOneVersion: versionedNodeRef = " + versionableNode);
// Get the next version number
int nextVersion = peekNextVersionNumber();
String nextVersionLabel = peekNextVersionLabel(versionableNode, nextVersion, versionProperties);
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
Date beforeVersionDate = (Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED);
@@ -158,7 +151,7 @@ public class VersionMigratorTest extends BaseVersionStoreTest
// check new version - switch to new version service to do the check
super.setVersionService(version2Service);
checkNewVersion(beforeVersionTime, nextVersion, nextVersionLabel, newVersion, versionableNode);
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
// get and compare new version details - - versionNodeService will retrieve these from the new version store
@@ -212,9 +205,8 @@ public class VersionMigratorTest extends BaseVersionStoreTest
NodeRef versionableNode = createNewVersionableNode();
// Get the next version number, next version label and snapshot the date-time
int nextVersion1 = peekNextVersionNumber();
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, nextVersion1, versionProperties);
// Get the next version label and snapshot the date-time
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime1 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
@@ -222,9 +214,8 @@ public class VersionMigratorTest extends BaseVersionStoreTest
Version version1 = createVersion(versionableNode);
logger.info(version1);
// Get the next version number, next version label and snapshot the date-time
int nextVersion2 = peekNextVersionNumber();
String nextVersionLabel2 = peekNextVersionLabel(versionableNode, nextVersion2, versionProperties);
// Get the next version label and snapshot the date-time
String nextVersionLabel2 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime2 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
@@ -232,9 +223,8 @@ public class VersionMigratorTest extends BaseVersionStoreTest
Version version2 = createVersion(versionableNode);
logger.info(version2);
// Get the next version number, next version label and snapshot the date-time
int nextVersion3 = peekNextVersionNumber();
String nextVersionLabel3 = peekNextVersionLabel(versionableNode, nextVersion3, versionProperties);
// Get the next version label and snapshot the date-time
String nextVersionLabel3 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime3 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
@@ -263,9 +253,9 @@ public class VersionMigratorTest extends BaseVersionStoreTest
Version[] newVersions = vh2.getAllVersions().toArray(new Version[]{});
checkVersion(beforeVersionTime1, nextVersion1, nextVersionLabel1, newVersions[2], versionableNode);
checkVersion(beforeVersionTime2, nextVersion2, nextVersionLabel2, newVersions[1], versionableNode);
checkNewVersion(beforeVersionTime3, nextVersion3, nextVersionLabel3, newVersions[0], versionableNode);
checkVersion(beforeVersionTime1, nextVersionLabel1, newVersions[2], versionableNode);
checkVersion(beforeVersionTime2, nextVersionLabel2, newVersions[1], versionableNode);
checkNewVersion(beforeVersionTime3, nextVersionLabel3, newVersions[0], versionableNode);
// ALFCOM-2658
assertEquals(version1.getFrozenStateNodeRef().getId(), newVersions[2].getFrozenStateNodeRef().getId());
@@ -460,9 +450,6 @@ public class VersionMigratorTest extends BaseVersionStoreTest
version2Service.useDeprecatedV1 = true;
// note: for testing only - not recommended !!!
versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionModel.STORE_ID), 100);
// Add the version aspect to the created node
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
@@ -503,7 +490,7 @@ public class VersionMigratorTest extends BaseVersionStoreTest
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), nextVersionNumber);
// to force the error: https://issues.alfresco.com/jira/browse/ETHREEOH-1540
versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), 0);
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), 0);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,6 +30,8 @@ import org.alfresco.service.namespace.QName;
* Version1 Model Constants used by lightWeightVersionStore implementation
*
* @author Roy Wetherall
*
* NOTE: deprecated since 3.1 (migrate and useVersion2 Model)
*/
public interface VersionModel extends VersionBaseModel
{
@@ -66,21 +68,59 @@ public interface VersionModel extends VersionBaseModel
/**
* Version type properties and associations
*/
/**
* @deprecated since 3.1
*/
public static final String PROP_FROZEN_NODE_ID = "frozenNodeId";
/**
* @deprecated since 3.1
*/
public static final String PROP_FROZEN_NODE_STORE_PROTOCOL = "frozenNodeStoreProtocol";
/**
* @deprecated since 3.1
*/
public static final String PROP_FROZEN_NODE_STORE_ID = "frozenNodeStoreId";
/**
* @deprecated since 3.1
*/
public static final String PROP_FROZEN_NODE_TYPE = "frozenNodeType";
/**
* @deprecated since 3.1
*/
public static final String PROP_FROZEN_ASPECTS = "frozenAspects";
public static final QName PROP_QNAME_VERSION_LABEL = QName.createQName(NAMESPACE_URI, PROP_VERSION_LABEL);
/**
* @deprecated since 3.3
*/
public static final QName PROP_QNAME_VERSION_NUMBER = QName.createQName(NAMESPACE_URI, PROP_VERSION_NUMBER);
/**
* @deprecated since 3.1
*/
public static final QName PROP_QNAME_FROZEN_NODE_ID = QName.createQName(NAMESPACE_URI, PROP_FROZEN_NODE_ID);
/**
* @deprecated since 3.1
*/
public static final QName PROP_QNAME_FROZEN_NODE_TYPE = QName.createQName(NAMESPACE_URI, PROP_FROZEN_NODE_TYPE);
/**
* @deprecated since 3.1
*/
public static final QName PROP_QNAME_FROZEN_NODE_STORE_PROTOCOL = QName.createQName(NAMESPACE_URI, PROP_FROZEN_NODE_STORE_PROTOCOL);
/**
* @deprecated since 3.1
*/
public static final QName PROP_QNAME_FROZEN_NODE_STORE_ID = QName.createQName(NAMESPACE_URI, PROP_FROZEN_NODE_STORE_ID);
/**
* @deprecated since 3.1
*/
public static final QName PROP_QNAME_FROZEN_ASPECTS = QName.createQName(NAMESPACE_URI, PROP_FROZEN_ASPECTS);
/**
* @deprecated since 3.1
*/
public static final QName ASSOC_SUCCESSOR = QName.createQName(NAMESPACE_URI, "successor");
/**
* Version Meta Data Value type
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -43,7 +43,6 @@ import org.alfresco.repo.version.common.AbstractVersionServiceImpl;
import org.alfresco.repo.version.common.VersionHistoryImpl;
import org.alfresco.repo.version.common.VersionImpl;
import org.alfresco.repo.version.common.VersionUtil;
import org.alfresco.repo.version.common.counter.VersionCounterService;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
@@ -63,14 +62,16 @@ import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Version1 Service - implements lightWeightVersionStore
*
* @author Roy Wetheral
*
* NOTE: deprecated since 3.1 (migrate and use Version2 Service)
*/
public class VersionServiceImpl extends AbstractVersionServiceImpl implements VersionService, VersionModel
{
@@ -86,11 +87,6 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
protected static final String MSGID_ERR_RESTORE_NO_VERSION = "version_service.err_restore_no_version";
protected static final String MSGID_ERR_REVERT_MISMATCH = "version_service.err_revert_mismatch";
/**
* The version counter service
*/
protected VersionCounterService versionCounterService;
/**
* The db node service, used as the version store implementation
*/
@@ -123,15 +119,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
this.searcher = searcher;
}
/**
* @param versionCounterService the version counter service
*/
public void setVersionCounterService(VersionCounterService versionCounterService)
{
this.versionCounterService = versionCounterService;
}
/**
* Set the policy behaviour filter
*
@@ -195,15 +183,14 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
long startTime = System.currentTimeMillis();
// Get the next version number
int versionNumber = this.versionCounterService.nextVersionNumber(getVersionStoreReference());
int versionNumber = 0; // deprecated (unused)
// Create the version
Version version = createVersion(nodeRef, versionProperties, versionNumber);
if (logger.isDebugEnabled())
{
logger.debug("created version (" + versionNumber + " - " + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis()-startTime) + " ms");
logger.debug("created version (" + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis()-startTime) + " ms");
}
return version;
@@ -222,9 +209,8 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
long startTime = System.currentTimeMillis();
// Get the next version number
int versionNumber = this.versionCounterService.nextVersionNumber(getVersionStoreReference());
int versionNumber = 0; // deprecated (unused)
// Create the versions
Collection<Version> versions = createVersion(nodeRef, versionProperties, versionChildren, versionNumber);
@@ -232,7 +218,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
Version[] versionsArray = versions.toArray(new Version[0]);
Version version = versionsArray[versionsArray.length -1]; // last item is the new parent version
logger.debug("created version (" + versionNumber + " - " + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in "+ (System.currentTimeMillis()-startTime) +" ms "+(versionChildren ? "(with " + (versions.size() - 1) + " children)" : ""));
logger.debug("created version (" + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in "+ (System.currentTimeMillis()-startTime) +" ms "+(versionChildren ? "(with " + (versions.size() - 1) + " children)" : ""));
}
return versions;
@@ -297,10 +283,9 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
long startTime = System.currentTimeMillis();
Collection<Version> result = new ArrayList<Version>(nodeRefs.size());
// Get the next version number
int versionNumber = this.versionCounterService.nextVersionNumber(getVersionStoreReference());
int versionNumber = 0; // deprecated (unused)
// Version each node in the list
for (NodeRef nodeRef : nodeRefs)
{
@@ -309,7 +294,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
if (logger.isDebugEnabled())
{
logger.debug("created version list (" + versionNumber + " - " + getVersionStoreReference() + ") in "+ (System.currentTimeMillis()-startTime) +" ms (with " + nodeRefs.size() + " nodes)");
logger.debug("created version list (" + getVersionStoreReference() + ") in "+ (System.currentTimeMillis()-startTime) +" ms (with " + nodeRefs.size() + " nodes)");
}
return result;
@@ -433,7 +418,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
if (logger.isTraceEnabled())
{
logger.trace("created Version (" + versionNumber + " - " + getVersionStoreReference() + ") " + nodeRef + " in " + (System.currentTimeMillis()-startTime) +" ms");
logger.trace("created Version (" + getVersionStoreReference() + ") " + nodeRef + " in " + (System.currentTimeMillis()-startTime) +" ms");
}
// Return the data object representing the newly created version
@@ -514,8 +499,8 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
Map<QName, Serializable> result = new HashMap<QName, Serializable>(10);
// Set the version number for the new version
result.put(VersionModel.PROP_QNAME_VERSION_NUMBER, Integer.toString(versionNumber));
// deprecated (unused)
//result.put(VersionModel.PROP_QNAME_VERSION_NUMBER, Integer.toString(versionNumber));
// Set the versionable node id
result.put(VersionModel.PROP_QNAME_FROZEN_NODE_ID, nodeRef.getId());

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -149,10 +149,9 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
NodeRef versionableNode = createNewVersionableNode();
// Snap shot data
int expectedVersionNumber = peekNextVersionNumber();
String expectedVersionLabel = peekNextVersionLabel(versionableNode, expectedVersionNumber, versionProperties);
// Snap-shot the node created date-time
String expectedVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
// Version the node and its children
@@ -162,7 +161,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
true);
// Check the returned versions are correct
CheckVersionCollection(expectedVersionNumber, expectedVersionLabel, beforeVersionTime, versions);
CheckVersionCollection(expectedVersionLabel, beforeVersionTime, versions);
// TODO check the version history is correct
}
@@ -175,10 +174,9 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
NodeRef versionableNode = createNewVersionableNode();
// Snap shot data
int expectedVersionNumber = peekNextVersionNumber();
String expectedVersionLabel = peekNextVersionLabel(versionableNode, expectedVersionNumber, versionProperties);
// Snap-shot the node created date-time
String expectedVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
// Version the list of nodes created
@@ -187,19 +185,18 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
this.versionProperties);
// Check the returned versions are correct
CheckVersionCollection(expectedVersionNumber, expectedVersionLabel, beforeVersionTime, versions);
CheckVersionCollection(expectedVersionLabel, beforeVersionTime, versions);
// TODO check the version histories
}
/**
* Helper method to check the validity of the list of newly created versions.
*
* @param expectedVersionNumber the expected version number that all the versions should have
* @param beforeVersionTime the time before the versions where created
* @param versions the collection of version objects
*/
private void CheckVersionCollection(int expectedVersionNumber, String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
private void CheckVersionCollection(String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
{
for (Version version : versions)
{
@@ -225,7 +222,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
assertNotNull("The versionable node ref that relates to the frozen node id can not be found.", originalNodeRef);
// Check the new version
checkNewVersion(beforeVersionTime, expectedVersionNumber, expectedVersionLabel, version, originalNodeRef);
checkNewVersion(beforeVersionTime, expectedVersionLabel, version, originalNodeRef);
}
}
@@ -697,7 +694,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
// Check that the initial version has not been created
VersionHistory versionHistory = versionService.getVersionHistory(versionableNode);
assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size());
assertEquals(1, versionHistory.getAllVersions().size());
// Add some content
ContentWriter contentWriter = contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -29,7 +29,6 @@ import junit.framework.TestSuite;
import org.alfresco.repo.version.common.VersionHistoryImplTest;
import org.alfresco.repo.version.common.VersionImplTest;
import org.alfresco.repo.version.common.counter.VersionCounterServiceTest;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicyTest;
/**
@@ -50,7 +49,6 @@ public class VersionTestSuite extends TestSuite
suite.addTestSuite(VersionImplTest.class);
suite.addTestSuite(VersionHistoryImplTest.class);
suite.addTestSuite(SerialVersionLabelPolicyTest.class);
suite.addTestSuite(VersionCounterServiceTest.class);
suite.addTestSuite(VersionServiceImplTest.class);
suite.addTestSuite(NodeServiceImplTest.class);
suite.addTestSuite(ContentServiceImplTest.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -53,7 +53,7 @@ public class VersionHistoryImpl implements VersionHistory
/*
* Error message(s)
*/
private static final String ERR_MSG = "The root version must be specified when creating a version history object.";
private static final String ERR_MSG = "The root version must be specified when creating a version history object.";
/*
* Field is left here to aid in detection of old serialized versions
@@ -101,11 +101,11 @@ public class VersionHistoryImpl implements VersionHistory
this.versionsByLabel = new HashMap<String, Version>();
this.rootVersion = rootVersion;
addVersion(rootVersion, null);
addVersion(rootVersion, null);
}
/**
* Gets the root (or initial) version of the version history.
* Gets the root (initial / least recent) version of the version history.
*
* @return the root version
*/
@@ -114,6 +114,19 @@ public class VersionHistoryImpl implements VersionHistory
return this.rootVersion;
}
/**
* Gets the head (current / most recent) version of the version history.
*
* @return the head version
*/
public Version getHeadVersion()
{
Collection<Version> versions = versionsByLabel.values();
List<Version> sortedVersions = new ArrayList<Version>(versions);
Collections.sort(sortedVersions, versionComparatorDesc);
return sortedVersions.get(0);
}
/**
* Gets a collection containing all the versions within the
* version history.
@@ -126,7 +139,7 @@ public class VersionHistoryImpl implements VersionHistory
{
Collection<Version> versions = versionsByLabel.values();
List<Version> sortedVersions = new ArrayList<Version>(versions);
Collections.sort(sortedVersions, versionComparatorDesc);
Collections.sort(sortedVersions, versionComparatorDesc);
return sortedVersions;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -52,14 +52,14 @@ public class VersionUtil
* Reserved property names
*/
public static final String[] RESERVED_PROPERTY_NAMES = new String[]{
VersionModel.PROP_FROZEN_NODE_ID, // deprecated
VersionModel.PROP_FROZEN_NODE_STORE_ID, // deprecated
VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL, // deprecated
VersionModel.PROP_FROZEN_NODE_TYPE, // deprecated
VersionModel.PROP_FROZEN_ASPECTS, // deprecated
VersionModel.PROP_FROZEN_NODE_ID, // deprecated (since 3.1)
VersionModel.PROP_FROZEN_NODE_STORE_ID, // deprecated (since 3.1)
VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL, // deprecated (since 3.1)
VersionModel.PROP_FROZEN_NODE_TYPE, // deprecated (since 3.1)
VersionModel.PROP_FROZEN_ASPECTS, // deprecated (since 3.1)
VersionBaseModel.PROP_CREATED_DATE,
VersionBaseModel.PROP_VERSION_LABEL,
VersionBaseModel.PROP_VERSION_NUMBER,
VersionBaseModel.PROP_VERSION_NUMBER, // deprecated (since 3.3)
VersionBaseModel.PROP_VERSION_DESCRIPTION,
Version2Model.PROP_FROZEN_NODE_DBID,
Version2Model.PROP_FROZEN_CREATED,

View File

@@ -1,74 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.version.common.counter;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
/**
* Version counter service interface.
*
* @author Roy Wetherall
*/
public interface VersionCounterService
{
/**
* Get the next available version number for the specified store.
*
* @param storeRef the store reference
* @return the next version number
*/
public int nextVersionNumber(StoreRef storeRef);
/**
* Gets the current version number for the specified store.
*
* @param storeRef the store reference
* @return the current versio number
*/
public int currentVersionNumber(StoreRef storeRef);
/**
* Resets the version number for a the specified store.
*
* WARNING: calling this method will completely reset the current
* version count for the specified store and cannot be undone.
*
* @param storeRef the store reference
*/
public void resetVersionNumber(StoreRef storeRef);
/**
* Sets the version number for a specified store.
*
* WARNING: calling this method will completely reset the current
* version count for the specified store and cannot be undone.
*
* @param storeRef the store reference
* @param versionCount the new version count
*/
public void setVersionNumber(StoreRef storeRef, int versionCount);
}

View File

@@ -1,190 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.version.common.counter;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* @author Roy Wetherall
*/
public class VersionCounterServiceTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private StoreRef storeRef1;
private StoreRef storeRef2;
private TransactionService transactionService;
private NodeService nodeService;
private VersionCounterService counter;
@Override
public void setUp() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
transactionService = serviceRegistry.getTransactionService();
nodeService = serviceRegistry.getNodeService();
counter = (VersionCounterService) ctx.getBean("versionCounterService");
// authenticate
AuthenticationComponent auth = (AuthenticationComponent) ctx.getBean("authenticationComponent");
auth.setSystemUserAsCurrentUser();
storeRef1 = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "test1_" + System.currentTimeMillis());
storeRef2 = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "test2_" + System.currentTimeMillis());
}
public void testSetUp() throws Exception
{
assertNotNull(transactionService);
assertNotNull(counter);
}
/**
* Test nextVersionNumber
*/
public void testNextVersionNumber() throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
int store1Version0 = counter.nextVersionNumber(storeRef1);
assertEquals(1, store1Version0);
int store1Version1 = counter.nextVersionNumber(storeRef1);
assertEquals(2, store1Version1);
int store2Version0 = counter.nextVersionNumber(storeRef2);
assertEquals(1, store2Version0);
int store1Version2 = counter.nextVersionNumber(storeRef1);
assertEquals(3, store1Version2);
int store2Version1 = counter.nextVersionNumber(storeRef2);
assertEquals(2, store2Version1);
int store1Current = counter.currentVersionNumber(storeRef1);
assertEquals(3, store1Current);
int store2Current = counter.currentVersionNumber(storeRef2);
assertEquals(2, store2Current);
// Need to clean-up since the version counter works in its own transaction
counter.resetVersionNumber(storeRef1);
counter.resetVersionNumber(storeRef2);
}
finally
{
try { txn.rollback(); } catch (Throwable e) {}
}
}
public void testConcurrentVersionNumber() throws Throwable
{
counter.currentVersionNumber(storeRef1);
VersionCounterThread[] threads = new VersionCounterThread[threadCount];
for (int i = 0; i < threadCount; i++)
{
threads[i] = new VersionCounterThread("VersionCounterThread_" + i);
// start the thread
threads[i].start();
}
// wait for the threads to all be done (or 10 seconds has passed)
endSignal.await(10, TimeUnit.SECONDS);
// check for exceptions
for (VersionCounterThread thread : threads)
{
if (thread.error != null)
{
throw thread.error;
}
}
}
private int threadCount = 5;
private CountDownLatch startSignal = new CountDownLatch(threadCount);
private CountDownLatch endSignal = new CountDownLatch(threadCount);
private class VersionCounterThread extends Thread
{
private Throwable error = new RuntimeException("Execution didn't complete");
public VersionCounterThread(String name)
{
super(name);
}
@Override
public void run()
{
RetryingTransactionCallback<Object> versionWork = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{
// wait for all other threads to enter into their transactions
startSignal.countDown();
int startVersion = counter.currentVersionNumber(storeRef1);
// increment it
int incrementedVersion = counter.nextVersionNumber(storeRef1);
assertTrue("Version number was not incremented", incrementedVersion > startVersion);
return null;
}
};
try
{
transactionService.getRetryingTransactionHelper().doInTransaction(versionWork, false);
error = null;
}
catch (Throwable e)
{
error = e;
e.printStackTrace();
}
finally
{
endSignal.countDown();
}
}
}
}

View File

@@ -52,9 +52,25 @@ public class SerialVersionLabelPolicy implements CalculateVersionLabelPolicy
* @return the version label
*/
public String calculateVersionLabel(
QName classRef,
QName classRef,
Version preceedingVersion,
int versionNumber,
Map<String, Serializable> versionProperties)
{
return calculateVersionLabel(classRef, preceedingVersion, 0, versionProperties);
}
/**
* Get the version label value base on the data provided.
*
* @param preceedingVersion the preceeding version, null if none
* @param versionNumber the new version number
* @param versionProperties the version property values
* @return the version label
*/
public String calculateVersionLabel(
QName classRef,
Version preceedingVersion,
int versionNumber,
Map<String, Serializable> versionProperties)
{
SerialVersionLabel serialVersionNumber = null;