Class AutoNumServiceImpl
- All Implemented Interfaces:
AutoNumService
- Version:
- $Id: $Id
- Author:
- querephi
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BeCPGCacheServiceprivate static final StringConstantCACHE_KEY_SEPARATOR="-"private static final LongConstantDEFAULT_AUTO_NUMprivate static final PatternConstantDEFAULT_PATTERNprivate static final StringConstantDEFAULT_PREFIX=""private org.alfresco.service.cmr.dictionary.DictionaryServiceprivate final ConcurrentHashMap<String, ReentrantLock> private static final org.apache.commons.logging.LogConstantloggerprivate static final StringConstantNAME_TEMPLATE="%s - %s"private org.alfresco.repo.domain.node.NodeDAOprivate org.alfresco.service.cmr.repository.NodeServiceprivate org.alfresco.repo.policy.BehaviourFilterprivate static final StringConstantPREFIX_MSG_PREFIX="autonum.prefix."private RepoServiceprivate org.alfresco.repo.model.Repositoryprivate org.alfresco.service.transaction.TransactionService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringbuildPrefixPattern(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) buildPrefixPattern.private LongcreateAutoNum(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long autoNumValue, String autoNumPrefix) createAutoNum.private Map<org.alfresco.service.namespace.QName, Serializable> createAutoNumProperties(String name, org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long autoNumValue, String autoNumPrefix) createAutoNumProperties.private StringcreateCacheKey(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createCacheKey.private StringcreateLockKey(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createLockKey.private StringcreateMatchPattern(String prefix) createMatchPattern.private StringcreateNewAutoNum(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createNewAutoNum.private voidcreateOrUpdateAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, String autoNumCode) createOrUpdateAutoNumValue.voiddeleteAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Delete auto num value.private voiddeleteCounter(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Deletes a counter node and evicts it from the cache.private Optional<org.alfresco.service.cmr.repository.NodeRef> findAutoNumNodeRef(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) findAutoNumNodeRef.private StringformatCode(String prefix, Long autoNumValue) formatCode.private StringgenerateAndSetNewCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName typeQName, org.alfresco.service.namespace.QName codeQName) generateAndSetNewCode.private StringgenerateNextAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) generateNextAutoNumValue.getAutoNumMatchPattern(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) getAutoNumMatchPattern.org.alfresco.service.cmr.repository.NodeRefgetAutoNumNodeRef(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) getAutoNumNodeRef.private StringgetAutoNumPrefix(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) getAutoNumPrefix.getAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Gets the auto num value.private StringgetDefaultPrefix(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) getDefaultPrefix.getOrCreateBeCPGCode(org.alfresco.service.cmr.repository.NodeRef nodeRef) getOrCreateBeCPGCode.getOrCreateCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName codeQName) getOrCreateCode.private StringgetPrefix.getPrefixedCode(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName, Long autoNumValue) getPrefixedCode.private StringincrementExistingAutoNum(org.alfresco.service.cmr.repository.NodeRef autoNumNodeRef) incrementExistingAutoNum.private booleanisCodeAlreadyUsed(org.alfresco.service.namespace.QName typeQName, org.alfresco.service.namespace.QName codeQName, String code, org.alfresco.service.cmr.repository.NodeRef excludeNodeRef) isCodeAlreadyUsed.private booleanisCommittedByAnotherTransaction(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Tells whether the counter exists and was last written by a transaction other than the current one.private AutoNumServiceImpl.AutoNumInfoparseAutoNumCode(String autoNumCode, org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) parseAutoNumCode.private StringprocessNodeCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName codeQName) processNodeCode.booleansetAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long counter) setAutoNumValue.private booleanupdateCounterValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long counter) Sets the value of an existing counter.private voidupdateExistingAutoNumIfNecessary(org.alfresco.service.cmr.repository.NodeRef autoNumNodeRef, Long newValue) updateExistingAutoNumIfNecessary.private voidvalidateInputs(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) validateInputs.private <T> TwriteCounter(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Supplier<T> write) Runs a write on a counter node under the lock of that counter, in its own short transaction whenever the counter is already committed.private <T> TwriteWithoutAuditing(Supplier<T> write) Runs a counter write without updating the auditable properties of the counter, as the caller transaction does for the entity it codes.
-
Field Details
-
NAME_TEMPLATE
ConstantNAME_TEMPLATE="%s - %s"- See Also:
-
DEFAULT_AUTO_NUM
ConstantDEFAULT_AUTO_NUM -
PREFIX_MSG_PREFIX
ConstantPREFIX_MSG_PREFIX="autonum.prefix."- See Also:
-
DEFAULT_PREFIX
ConstantDEFAULT_PREFIX=""- See Also:
-
DEFAULT_PATTERN
ConstantDEFAULT_PATTERN -
CACHE_KEY_SEPARATOR
ConstantCACHE_KEY_SEPARATOR="-"- See Also:
-
logger
private static final org.apache.commons.logging.Log loggerConstantlogger -
lockMap
-
nodeService
@Autowired private org.alfresco.service.cmr.repository.NodeService nodeService -
repoService
-
repositoryHelper
@Autowired private org.alfresco.repo.model.Repository repositoryHelper -
dictionaryService
@Autowired private org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService -
beCPGCacheService
-
policyBehaviourFilter
@Autowired private org.alfresco.repo.policy.BehaviourFilter policyBehaviourFilter -
transactionService
@Autowired private org.alfresco.service.transaction.TransactionService transactionService -
nodeDAO
@Autowired private org.alfresco.repo.domain.node.NodeDAO nodeDAO
-
-
Constructor Details
-
AutoNumServiceImpl
public AutoNumServiceImpl()
-
-
Method Details
-
getAutoNumValue
public String getAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Gets the auto num value.- Specified by:
getAutoNumValuein interfaceAutoNumService- Parameters:
className- the class namepropertyName- the property name- Returns:
- the auto num value
-
setAutoNumValue
public boolean setAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long counter) setAutoNumValue.
- Specified by:
setAutoNumValuein interfaceAutoNumService- Parameters:
className- aQNameobjectpropertyName- aQNameobjectcounter- aLongobject- Returns:
- a boolean
-
deleteAutoNumValue
public void deleteAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Delete auto num value.- Specified by:
deleteAutoNumValuein interfaceAutoNumService- Parameters:
className- the class namepropertyName- the property name
-
getAutoNumMatchPattern
public String getAutoNumMatchPattern(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) getAutoNumMatchPattern.
- Specified by:
getAutoNumMatchPatternin interfaceAutoNumService- Parameters:
type- aQNameobject.propertyName- aQNameobject.- Returns:
- the pattern string for the corresponding code
-
getPrefixedCode
public String getPrefixedCode(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName, Long autoNumValue) getPrefixedCode.
- Specified by:
getPrefixedCodein interfaceAutoNumService- Parameters:
type- aQNameobject.propertyName- aQNameobject.autoNumValue- aLongobject.- Returns:
- the prefixed String for the given type
-
getOrCreateCode
public String getOrCreateCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName codeQName) getOrCreateCode.
- Specified by:
getOrCreateCodein interfaceAutoNumService- Parameters:
nodeRef- aNodeRefobject.codeQName- aQNameobject.- Returns:
- a
Stringobject.
-
getOrCreateBeCPGCode
getOrCreateBeCPGCode.
- Specified by:
getOrCreateBeCPGCodein interfaceAutoNumService- Parameters:
nodeRef- aNodeRefobject.- Returns:
- a
Stringobject.
-
getAutoNumNodeRef
public org.alfresco.service.cmr.repository.NodeRef getAutoNumNodeRef(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) getAutoNumNodeRef.
- Specified by:
getAutoNumNodeRefin interfaceAutoNumService- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- the NodeRef of the AutoNum value
-
validateInputs
private void validateInputs(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) validateInputs.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject
-
writeCounter
private <T> T writeCounter(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Supplier<T> write) Runs a write on a counter node under the lock of that counter, in its own short transaction whenever the counter is already committed.The database row lock taken by the write is then released when the inner transaction commits, before the Java lock is released. A caller transaction therefore never holds the counter row while it waits for the Java lock: otherwise two transactions coding several entities each wait for the other one, a cycle neither the JVM nor the database can detect, that only ends with the lock wait timeout.
The write stays in the caller transaction when the counter does not exist yet, or when the caller transaction has already written it: the inner transaction cannot see the counter, or the folders it lives in, before the caller commits, and would wait for a row locked by its own suspended caller.
A counter value consumed by a caller transaction that rolls back or retries is lost, leaving a gap in the numbering.
- Type Parameters:
T- the type returned by the write- Parameters:
className- the class the counter belongs topropertyName- the property the counter numberswrite- the write to run on the counter node- Returns:
- the value returned by the write
-
isCommittedByAnotherTransaction
private boolean isCommittedByAnotherTransaction(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Tells whether the counter exists and was last written by a transaction other than the current one.- Parameters:
className- the class the counter belongs topropertyName- the property the counter numbers- Returns:
- true if the counter can be written in its own transaction
-
writeWithoutAuditing
Runs a counter write without updating the auditable properties of the counter, as the caller transaction does for the entity it codes.- Type Parameters:
T- the type returned by the write- Parameters:
write- the write to run on the counter node- Returns:
- the value returned by the write
-
updateCounterValue
private boolean updateCounterValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long counter) Sets the value of an existing counter.- Parameters:
className- the class the counter belongs topropertyName- the property the counter numberscounter- the new value of the counter- Returns:
- true if the counter exists and was updated, false otherwise
-
deleteCounter
private void deleteCounter(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) Deletes a counter node and evicts it from the cache.- Parameters:
className- the class the counter belongs topropertyName- the property the counter numbers
-
createLockKey
private String createLockKey(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createLockKey.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
createCacheKey
private String createCacheKey(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createCacheKey.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
generateNextAutoNumValue
private String generateNextAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) generateNextAutoNumValue.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
incrementExistingAutoNum
incrementExistingAutoNum.
- Parameters:
autoNumNodeRef- aNodeRefobject- Returns:
- a
Stringobject
-
createNewAutoNum
private String createNewAutoNum(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) createNewAutoNum.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
findAutoNumNodeRef
private Optional<org.alfresco.service.cmr.repository.NodeRef> findAutoNumNodeRef(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) findAutoNumNodeRef.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Optionalobject
-
buildPrefixPattern
private String buildPrefixPattern(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) buildPrefixPattern.
- Parameters:
type- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
createMatchPattern
createMatchPattern.
-
getAutoNumPrefix
private String getAutoNumPrefix(org.alfresco.service.namespace.QName type, org.alfresco.service.namespace.QName propertyName) getAutoNumPrefix.
- Parameters:
type- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
processNodeCode
private String processNodeCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName codeQName) processNodeCode.
- Parameters:
nodeRef- aNodeRefobjectcodeQName- aQNameobject- Returns:
- a
Stringobject
-
isCodeAlreadyUsed
private boolean isCodeAlreadyUsed(org.alfresco.service.namespace.QName typeQName, org.alfresco.service.namespace.QName codeQName, String code, org.alfresco.service.cmr.repository.NodeRef excludeNodeRef) isCodeAlreadyUsed.
- Parameters:
typeQName- aQNameobjectcodeQName- aQNameobjectcode- aStringobjectexcludeNodeRef- aNodeRefobject- Returns:
- a boolean
-
generateAndSetNewCode
private String generateAndSetNewCode(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName typeQName, org.alfresco.service.namespace.QName codeQName) generateAndSetNewCode.
- Parameters:
nodeRef- aNodeRefobjecttypeQName- aQNameobjectcodeQName- aQNameobject- Returns:
- a
Stringobject
-
createOrUpdateAutoNumValue
private void createOrUpdateAutoNumValue(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, String autoNumCode) createOrUpdateAutoNumValue.
- Parameters:
className- aQNameobjectpropertyName- aQNameobjectautoNumCode- aStringobject
-
parseAutoNumCode
private AutoNumServiceImpl.AutoNumInfo parseAutoNumCode(String autoNumCode, org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) parseAutoNumCode.
- Parameters:
autoNumCode- aStringobjectclassName- aQNameobjectpropertyName- aQNameobject- Returns:
- a
AutoNumServiceImpl.AutoNumInfoobject
-
updateExistingAutoNumIfNecessary
private void updateExistingAutoNumIfNecessary(org.alfresco.service.cmr.repository.NodeRef autoNumNodeRef, Long newValue) updateExistingAutoNumIfNecessary.
- Parameters:
autoNumNodeRef- aNodeRefobjectnewValue- aLongobject
-
getDefaultPrefix
private String getDefaultPrefix(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName) getDefaultPrefix.
- Parameters:
className- aQNameobjectpropertyName- aQNameobject- Returns:
- a
Stringobject
-
createAutoNum
private Long createAutoNum(org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long autoNumValue, String autoNumPrefix) createAutoNum.
-
createAutoNumProperties
private Map<org.alfresco.service.namespace.QName,Serializable> createAutoNumProperties(String name, org.alfresco.service.namespace.QName className, org.alfresco.service.namespace.QName propertyName, Long autoNumValue, String autoNumPrefix) createAutoNumProperties.
-
getPrefix
private String getPrefix(org.alfresco.service.cmr.repository.NodeRef autoNumNodeRef, String defaultPrefix) getPrefix.
-
formatCode
formatCode.
-