List of usage examples for org.springframework.dao ConcurrencyFailureException ConcurrencyFailureException
public ConcurrencyFailureException(String msg)
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
/** * Get a node instance regardless of whether it is considered <b>live</b> or <b>deleted</b> * /*w ww .java2 s . c o m*/ * @param nodeId the node ID to look for * @param liveOnly <tt>true</tt> to ensure that only <b>live</b> nodes are retrieved * @return a node that will be <b>live</b> if requested * @throws ConcurrencyFailureException if a valid node is not found */ private Node getNodeNotNull(Long nodeId, boolean liveOnly) { Pair<Long, Node> pair = nodesCache.getByKey(nodeId); if (pair == null) { // The node has no entry in the database NodeEntity dbNode = selectNodeById(nodeId); nodesCache.removeByKey(nodeId); throw new ConcurrencyFailureException( "No node row exists: \n" + " ID: " + nodeId + "\n" + " DB row: " + dbNode); } else if (pair.getSecond().getDeleted(qnameDAO) && liveOnly) { // The node is not 'live' as was requested NodeEntity dbNode = selectNodeById(nodeId); nodesCache.removeByKey(nodeId); // Make absolutely sure that the node is not referenced by any associations pruneDanglingAssocs(nodeId); // Force a retry on the transaction throw new ConcurrencyFailureException( "No live node exists: \n" + " ID: " + nodeId + "\n" + " DB row: " + dbNode); } else { return pair.getSecond(); } }
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
/** * Physical deletion of the node//from w w w . j a v a 2s . co m * * @param nodeId the node to delete * @param deleteAcl <tt>true</tt> to delete any associated ACLs otherwise * <tt>false</tt> if the ACLs get reused elsewhere */ private void deleteNodeImpl(Long nodeId, boolean deleteAcl) { Node node = getNodeNotNull(nodeId, true); // Gather data for later Long aclId = node.getAclId(); Set<QName> nodeAspects = getNodeAspects(nodeId); // Clean up content data Set<QName> contentQNames = new HashSet<QName>( dictionaryService.getAllProperties(DataTypeDefinition.CONTENT)); Set<Long> contentQNamesToRemoveIds = qnameDAO.convertQNamesToIds(contentQNames, false); contentDataDAO.deleteContentDataForNode(nodeId, contentQNamesToRemoveIds); // Delete content usage deltas usageDAO.deleteDeltas(nodeId); // Handle sys:aspect_root if (nodeAspects.contains(ContentModel.ASPECT_ROOT)) { StoreRef storeRef = node.getStore().getStoreRef(); allRootNodesCache.remove(storeRef); } // Remove child associations (invalidate children) invalidateNodeChildrenCaches(nodeId, true, true); invalidateNodeChildrenCaches(nodeId, false, true); // Remove aspects deleteNodeAspects(nodeId, null); // Remove properties deleteNodeProperties(nodeId, (Set<Long>) null); // Remove subscriptions deleteSubscriptions(nodeId); // Delete the row completely: // ALF-12358: Concurrency: Possible to create association references to deleted nodes // There will be no way that any references can be made to a deleted node because we // are really going to delete it. However, for tracking purposes we need to maintain // a list of nodes deleted in the transaction. We store that information against a // new node of type 'sys:deleted'. This means that 'deleted' nodes are really just // orphaned (read standalone) nodes that remain invisible outside of the DAO. int deleted = deleteNodeById(nodeId); // We will always have to invalidate the cache for the node invalidateNodeCaches(nodeId); // Concurrency check if (deleted != 1) { // We thought that the row existed throw new ConcurrencyFailureException("Failed to delete node: \n" + " Node: " + node); } // Remove ACLs if (deleteAcl && aclId != null) { aclDAO.deleteAclForNode(aclId); } // The node has been cleaned up. Now we recreate the node for index tracking purposes. // Use a 'deleted' type QName StoreEntity store = node.getStore(); String uuid = node.getUuid(); Long deletedQNameId = qnameDAO.getOrCreateQName(ContentModel.TYPE_DELETED).getFirst(); Long defaultLocaleId = localeDAO.getOrCreateDefaultLocalePair().getFirst(); Node deletedNode = newNodeImpl(store, uuid, deletedQNameId, defaultLocaleId, null, null, true); Long deletedNodeId = deletedNode.getId(); // Store the original ID as a property Map<QName, Serializable> trackingProps = Collections.singletonMap(ContentModel.PROP_ORIGINAL_ID, (Serializable) nodeId); setNodePropertiesImpl(deletedNodeId, trackingProps, true); }
From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java
protected int updateChildAssocUniqueNameImpl(final Long childNodeId, final String childName) { int total = 0; Savepoint savepoint = controlDAO.createSavepoint("DuplicateChildNodeNameException"); try {/*from ww w. j a va 2 s .com*/ for (ChildAssocEntity parentAssoc : getParentAssocsCached(childNodeId).getParentAssocs().values()) { // Subtlety: We only update those associations for which name uniqueness checking is enforced. // Such associations have a positive CRC if (parentAssoc.getChildNodeNameCrc() <= 0) { continue; } Pair<Long, QName> oldTypeQnamePair = qnameDAO.getQName(parentAssoc.getTypeQNameId()); // Ensure we invalidate the name cache (the child version key might not be 'bumped' by the next // 'touch') if (oldTypeQnamePair != null) { childByNameCache.remove(new ChildByNameKey(parentAssoc.getParentNode().getId(), oldTypeQnamePair.getSecond(), parentAssoc.getChildNodeName())); } int count = updateChildAssocUniqueName(parentAssoc.getId(), childName); if (count <= 0) { // Should not be attempting to delete a deleted node throw new ConcurrencyFailureException( "Failed to update an existing parent association " + parentAssoc.getId()); } total += count; } controlDAO.releaseSavepoint(savepoint); return total; } catch (Throwable e) { controlDAO.rollbackToSavepoint(savepoint); // We assume that this is from the child cm:name constraint violation throw new DuplicateChildNodeNameException(null, null, childName, e); } }
From source file:org.alfresco.repo.domain.permissions.ADMAccessControlListDAO.java
/** * Support to set a shared ACL on a node and all of its children * /*ww w.j av a2s. c o m*/ * @param nodeId * the parent node * @param inheritFrom * the parent node's ACL * @param mergeFrom * the shared ACL, if already known. If <code>null</code>, will be retrieved / created lazily * @param changes * the list in which to record changes * @param set * set the shared ACL on the parent ? * @param asyncCall * function may require asynchronous call depending the execution time; if time exceeds configured <code>fixedAclMaxTransactionTime</code> value, * recursion is stopped using propagateOnChildren parameter(set on false) and those nodes for which the method execution was not finished * in the classical way, will have ASPECT_PENDING_FIX_ACL, which will be used in {@link FixedAclUpdater} for later processing */ public void setFixedAcls(Long nodeId, Long inheritFrom, Long mergeFrom, Long sharedAclToReplace, List<AclChange> changes, boolean set, boolean asyncCall, boolean propagateOnChildren) { if (log.isDebugEnabled()) { log.debug(" Set fixed acl for nodeId=" + nodeId + " inheritFrom=" + inheritFrom + " sharedAclToReplace=" + sharedAclToReplace + " mergefrom= " + mergeFrom); } if (nodeId == null) { return; } else { // Lazily retrieve/create the shared ACL if (mergeFrom == null) { mergeFrom = aclDaoComponent.getInheritedAccessControlList(inheritFrom); } if (set) { nodeDAO.setNodeAclId(nodeId, mergeFrom); } List<NodeIdAndAclId> children = nodeDAO.getPrimaryChildrenAcls(nodeId); if (children.size() > 0) { nodeDAO.setPrimaryChildrenSharedAclId(nodeId, sharedAclToReplace, mergeFrom); } if (!propagateOnChildren) { return; } for (NodeIdAndAclId child : children) { Long acl = child.getAclId(); if (acl == null) { propagateOnChildren = setFixAclPending(child.getId(), inheritFrom, mergeFrom, sharedAclToReplace, changes, false, asyncCall, propagateOnChildren); } else { // if(acl.equals(mergeFrom)) // { // setFixedAcls(child.getId(), inheritFrom, mergeFrom, sharedAclToReplace, changes, false); // } // Already replaced if (acl.equals(sharedAclToReplace)) { propagateOnChildren = setFixAclPending(child.getId(), inheritFrom, mergeFrom, sharedAclToReplace, changes, false, asyncCall, propagateOnChildren); } else { Acl dbAcl = aclDaoComponent.getAcl(acl); if (dbAcl.getAclType() == ACLType.LAYERED) { throw new UnsupportedOperationException(); } else if (dbAcl.getAclType() == ACLType.DEFINING) { if (dbAcl.getInherits()) { @SuppressWarnings("unused") List<AclChange> newChanges = aclDaoComponent .mergeInheritedAccessControlList(mergeFrom, acl); } } else if (dbAcl.getAclType() == ACLType.SHARED) { throw new ConcurrencyFailureException("setFixedAcls: unexpected shared acl: " + dbAcl); } } } } } }
From source file:org.alfresco.repo.transaction.RetryingTransactionHelperTest.java
/** * Check that the retries happening for simple concurrency exceptions *///from ww w . j av a 2s .c o m public void testSuccessWithRetry() { RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>() { private int maxCalls = 3; private int callCount = 0; public Long execute() throws Throwable { callCount++; Long checkValue = incrementCheckValue(); if (callCount == maxCalls) { return checkValue; } else { throw new ConcurrencyFailureException("Testing"); } } }; long txnValue = txnHelper.doInTransaction(callback); assertEquals("Only one increment expected", 1, txnValue); }
From source file:org.alfresco.repo.version.Version2ServiceImpl.java
/** * Gets current version of the passed node ref * * This uses the version label as a mechanism for looking up the version node. */// w w w.j a va 2 s .c om private Pair<Boolean, Version> getCurrentVersionImpl(NodeRef versionHistoryRef, NodeRef nodeRef) { Pair<Boolean, Version> result = null; String versionLabel = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL); // 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--) { 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) { boolean headVersion = (i == cnt); if (!headVersion) { throw new ConcurrencyFailureException( "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; } } return result; }
From source file:org.alfresco.rest.api.impl.NodesImpl.java
private NodeRef makeFolders(NodeRef parentNodeRef, List<String> pathElements) { NodeRef currentParentRef = parentNodeRef; // just loop and create if necessary for (final String element : pathElements) { final NodeRef contextNodeRef = currentParentRef; // does it exist? // Navigation should not check permissions NodeRef nodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() { @Override/*from w w w. j a v a 2 s . c om*/ public NodeRef doWork() throws Exception { return nodeService.getChildByName(contextNodeRef, ContentModel.ASSOC_CONTAINS, element); } }, AuthenticationUtil.getSystemUserName()); if (nodeRef == null) { try { // Checks for create permissions as the fileFolderService is a public service. FileInfo createdFileInfo = fileFolderService.create(currentParentRef, element, ContentModel.TYPE_FOLDER); currentParentRef = createdFileInfo.getNodeRef(); } catch (AccessDeniedException ade) { throw new PermissionDeniedException(ade.getMessage()); } catch (FileExistsException fex) { // Assume concurrency failure, so retry throw new ConcurrencyFailureException(fex.getMessage()); } } else if (!isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)) { String parentName = (String) nodeService.getProperty(contextNodeRef, ContentModel.PROP_NAME); throw new ConstraintViolatedException( "Name [" + element + "] already exists in the target parent: " + parentName); } else { // it exists currentParentRef = nodeRef; } } return currentParentRef; }
From source file:org.osaf.cosmo.dao.mock.MockContentDao.java
/** * Create new content item. A content item represents a piece of content or * file./*from w w w .ja va 2s.co m*/ * * @param parent * parent collection of content. If null, content is assumed to * live in the top-level user collection * @param content * content to create * @return newly created content */ public ContentItem createContent(CollectionItem parent, ContentItem content) { if (parent == null) throw new IllegalArgumentException("parent cannot be null"); if (content == null) throw new IllegalArgumentException("collection cannot be null"); if (THROW_CONCURRENT_EXCEPTION) throw new ConcurrencyFailureException("fail!"); if (getStorage().getItemByUid(content.getUid()) != null) throw new UidInUseException(content.getUid(), "Uid " + content.getUid() + " already in use"); ((MockItem) content).addParent(parent); getStorage().storeItem((Item) content); return content; }
From source file:org.osaf.cosmo.dao.mock.MockContentDao.java
/** * Update an existing content item.//ww w .j av a 2 s.co m * * @param content * content item to update * @return updated content item */ public ContentItem updateContent(ContentItem content) { if (content == null) throw new IllegalArgumentException("content cannot be null"); if (THROW_CONCURRENT_EXCEPTION) throw new ConcurrencyFailureException("fail!"); Item stored = getStorage().getItemByUid(content.getUid()); if (stored != null && stored != content) throw new UidInUseException(content.getUid(), "Uid " + content.getUid() + " already in use"); getStorage().updateItem((Item) content); return content; }
From source file:org.osaf.cosmo.dao.mock.MockContentDao.java
public ContentItem createContent(Set<CollectionItem> parents, ContentItem content) { if (parents == null || parents.size() == 0) throw new IllegalArgumentException("parents cannot be null or empty"); if (content == null) throw new IllegalArgumentException("collection cannot be null"); if (THROW_CONCURRENT_EXCEPTION) throw new ConcurrencyFailureException("fail!"); if (getStorage().getItemByUid(content.getUid()) != null) throw new UidInUseException(content.getUid(), "Uid " + content.getUid() + " already in use"); for (CollectionItem parent : parents) ((MockItem) content).addParent(parent); getStorage().storeItem((Item) content); return content; }