Java Code Examples for org.springframework.dao.ConcurrencyFailureException

The following examples show how to use org.springframework.dao.ConcurrencyFailureException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Check that the retries happening for simple concurrency exceptions
 */
@Test
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);
}
 
Example 2
public void updateAclMember(AclMemberEntity entity)
{
    ParameterCheck.mandatory("entity", entity);
    ParameterCheck.mandatory("entity.id", entity.getId());
    ParameterCheck.mandatory("entity.version", entity.getVersion());
    ParameterCheck.mandatory("entity.aceId", entity.getAceId());
    ParameterCheck.mandatory("entity.aclId", entity.getAclId());
    ParameterCheck.mandatory("entity.pos", entity.getPos());
    
    int updated = updateAclMemberEntity(entity);
    
    if (updated < 1)
    {
        aclEntityCache.removeByKey(entity.getId());
        throw new ConcurrencyFailureException("AclMemberEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently");
    }
}
 
Example 3
public void renameAuthority(String before, String after)
{
    ParameterCheck.mandatory("before", before);
    ParameterCheck.mandatory("after", after);
    
    AuthorityEntity entity = getAuthorityForUpdate(before);
    
    if (entity != null)
    {
        entity.setAuthority(after);
        entity.setCrc(CrcHelper.getStringCrcPair(after, 32, true, true).getSecond());
        
        int updated = authorityEntityCache.updateValue(entity.getId(), entity);
        if (updated < 1)
        {
            aclEntityCache.removeByKey(entity.getId());
            throw new ConcurrencyFailureException("AuthorityEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently");
        }
    }
}
 
Example 4
@Override
protected AuditApplicationEntity updateAuditApplication(AuditApplicationEntity entity)
{
    AuditApplicationEntity updateEntity = new AuditApplicationEntity();
    updateEntity.setId(entity.getId());
    updateEntity.setVersion(entity.getVersion());
    updateEntity.incrementVersion();
    updateEntity.setApplicationNameId(entity.getApplicationNameId());
    updateEntity.setAuditModelId(entity.getAuditModelId());
    updateEntity.setDisabledPathsId(entity.getDisabledPathsId());
    
    int updated = template.update(UPDATE_APPLICATION, updateEntity);
    if (updated != 1)
    {
        // unexpected number of rows affected
        throw new ConcurrencyFailureException("Incorrect number of rows affected for updateAuditApplication: " + updateEntity + ": expected 1, actual " + updated);
    }
    
    // Done
    return updateEntity;
}
 
Example 5
public long getTotalDeltaSize(NodeRef nodeRef, boolean removeDeltas)
{
    long nodeId = getNodeIdNotNull(nodeRef);
    UsageDeltaEntity entity = selectTotalUsageDeltaSize(nodeId);
    Long totalSize = entity.getDeltaSize();
    // Remove the deltas, making sure that the correct number are removed
    if (removeDeltas)
    {
        int deleted = deleteUsageDeltaEntitiesByNodeId(nodeId);
        if (entity.getDeltaCount() != null && entity.getDeltaCount().intValue() != deleted)
        {
            throw new ConcurrencyFailureException(
                    "The number of usage deltas was " + entity.getDeltaCount() + " but only " + deleted + " were deleted.");
        }
    }
    return (totalSize != null ? totalSize : 0L);
}
 
Example 6
public void updateNamespace(String oldNamespaceUri, String newNamespaceUri)
{
    ParameterCheck.mandatory("newNamespaceUri", newNamespaceUri);

    Pair<Long, String> oldEntityPair = getNamespace(oldNamespaceUri);   // incl. null check
    if (oldEntityPair == null)
    {
        throw new DataIntegrityViolationException(
                "Cannot update namespace as it doesn't exist: " + oldNamespaceUri);
    }
    // Find the value
    int updated = namespaceCache.updateValue(oldEntityPair.getFirst(), newNamespaceUri);
    if (updated != 1)
    {
        throw new ConcurrencyFailureException(
                "Incorrect update count: \n" +
                "   Namespace:    " + oldNamespaceUri + "\n" +
                "   Rows Updated: " + updated);
    }
    // All the QNames need to be dumped
    qnameCache.clear();
    // Done
}
 
Example 7
@Override
public void deleteQName(QName qname)
{
    if (qname == null)
    {
        throw new IllegalArgumentException("QName cannot be null");
    }
    // See if the QName exists
    Pair<Long, QName> qnamePair = qnameCache.getByValue(qname);
    if (qnamePair == null)
    {
        throw new IllegalArgumentException("Cannot delete QName.  QName " + qname + " does not exist");
    }
    // Delete
    Long qnameId = qnamePair.getFirst();
    int deleted = qnameCache.deleteByKey(qnameId);
    if (deleted != 1)
    {
        throw new ConcurrencyFailureException("Failed to delete QName entity " + qnameId);
    }
}
 
Example 8
@Override
protected LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive)
{
    LockEntity updateLockEntity = new LockEntity();
    updateLockEntity.setId(lockEntity.getId());
    updateLockEntity.setVersion(lockEntity.getVersion());
    updateLockEntity.incrementVersion();            // Increment the version number
    updateLockEntity.setSharedResourceId(lockEntity.getSharedResourceId());
    updateLockEntity.setExclusiveResourceId(lockEntity.getExclusiveResourceId());
    updateLockEntity.setLockToken(lockToken == null ? null : lockToken.toLowerCase());
    long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
    long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
    updateLockEntity.setStartTime(new Long(now));
    updateLockEntity.setExpiryTime(new Long(exp));
    
    int updated = template.update(UPDATE_LOCK, updateLockEntity);
    if (updated != 1)
    {
        // unexpected number of rows affected
        throw new ConcurrencyFailureException("Incorrect number of rows affected for updateLock: " + updateLockEntity + ": expected 1, actual " + updated);
    }
    
    // Done
    return updateLockEntity;
}
 
Example 9
@Override
public void updateContentData(Long id, ContentData contentData)
{
    if (id == null)
    {
        throw new IllegalArgumentException("Cannot look up ContentData by null ID.");
    }
    if (contentData == null)
    {
        throw new IllegalArgumentException("Cannot update ContentData with a null.");
    }
    contentData = sanitizeMimetype(contentData);
    int updated = contentDataCache.updateValue(id, contentData);
    if (updated < 1)
    {
        throw new ConcurrencyFailureException("ContentData with ID " + id + " not updated");
    }
}
 
Example 10
@Override
public void setNodeAssocIndex(Long id, int assocIndex)
{
    int updated = updateNodeAssoc(id, assocIndex);
    if (updated != 1)
    {
        throw new ConcurrencyFailureException("Expected to update exactly one row: " + id);
    }
}
 
Example 11
@Override
public Pair<Long, ChildAssociationRef> getChildAssoc(Long assocId)
{
    ChildAssocEntity assoc = selectChildAssoc(assocId);
    if (assoc == null)
    {
        throw new ConcurrencyFailureException("Child association not found: " + assocId);
    }
    return assoc.getPair(qnameDAO);
}
 
Example 12
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with(MESSAGE_KEY, ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 13
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with(MESSAGE_KEY, ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 14
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with(MESSAGE_KEY, ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 15
Source Project: cubeai   Source File: ExceptionTranslator.java    License: Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(ConcurrencyFailureException.class)
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 16
Source Project: cubeai   Source File: ExceptionTranslator.java    License: Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(ConcurrencyFailureException.class)
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 17
@Override
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId)
{
    Pair<Long, AssociationRef> ret = getNodeAssocOrNull(assocId);
    if (ret == null)
    {
        throw new ConcurrencyFailureException("Assoc ID does not point to a valid association: " + assocId);
    }
    else
    {
        return ret;
    }
}
 
Example 18
protected Long newChildAssocInsertImpl(final ChildAssocEntity assoc, final QName assocTypeQName, final String childNodeName)
{
    Savepoint savepoint = controlDAO.createSavepoint("DuplicateChildNodeNameException");
    try
    {
        Long id = insertChildAssoc(assoc);
        controlDAO.releaseSavepoint(savepoint);
        return id;
    }
    catch (Throwable e)
    {
        controlDAO.rollbackToSavepoint(savepoint);
        // DuplicateChildNodeNameException implements DoNotRetryException.
        
        // Allow real DB concurrency issues (e.g. DeadlockLoserDataAccessException) straight through for a retry
        if (e instanceof ConcurrencyFailureException)
        {
            throw e;                        
        }

        // There are some cases - FK violations, specifically - where we DO actually want to retry.
        // Detecting this is done by looking for the related FK names, 'fk_alf_cass_*' in the error message
        String lowerMsg = e.getMessage().toLowerCase();
        if (lowerMsg.contains("fk_alf_cass_"))
        {
            throw new ConcurrencyFailureException("FK violation updating primary parent association:" + assoc, e); 
        }
        
        // We assume that this is from the child cm:name constraint violation
        throw new DuplicateChildNodeNameException(
                assoc.getParentNode().getNodeRef(),
                assocTypeQName,
                childNodeName,
                e);
    }
}
 
Example 19
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 20
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 21
Source Project: TeamDojo   Source File: ExceptionTranslator.java    License: Apache License 2.0 5 votes vote down vote up
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with(MESSAGE_KEY, ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 22
Source Project: Spring-5.0-Projects   Source File: ExceptionTranslator.java    License: MIT License 5 votes vote down vote up
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 23
@Override
public int removeNodeAssocs(List<Long> ids)
{
    int toDelete = ids.size();
    if (toDelete == 0)
    {
        return 0;
    }
    int deleted = deleteNodeAssocs(ids);
    if (toDelete != deleted)
    {
        throw new ConcurrencyFailureException("Deleted " + deleted + " but expected " + toDelete);
    }
    return deleted;
}
 
Example 24
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 25
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 26
@ExceptionHandler(ConcurrencyFailureException.class)
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with("message", ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 27
Source Project: jhipster-online   Source File: ExceptionTranslator.java    License: Apache License 2.0 5 votes vote down vote up
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
    Problem problem = Problem.builder()
        .withStatus(Status.CONFLICT)
        .with(MESSAGE_KEY, ErrorConstants.ERR_CONCURRENCY_FAILURE)
        .build();
    return create(ex, problem, request);
}
 
Example 28
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	if (ex instanceof SQLTransientException) {
		if (ex instanceof SQLTransientConnectionException) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTransactionRollbackException) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTimeoutException) {
			return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLNonTransientException) {
		if (ex instanceof SQLNonTransientConnectionException) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLDataException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLIntegrityConstraintViolationException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLInvalidAuthorizationSpecException) {
			return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLSyntaxErrorException) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (ex instanceof SQLFeatureNotSupportedException) {
			return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLRecoverableException) {
		return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
	}

	// Fallback to Spring's own SQL state translation...
	return null;
}
 
Example 29
/**
 * Gets current version of the passed node reference. The node reference is expected to be the 'live' node.
 *
 * This uses the version label as a mechanism for looking up the version node.
 */
private Pair<Boolean, Version> getCurrentVersionImpl(NodeRef versionHistoryRef, NodeRef nodeRef)
{
    // The noderef should not be a version type node. 
    if (nodeRef.getStoreRef().getIdentifier().contains(Version2Model.STORE_ID))
    {
         throw new IllegalArgumentException("The node reference " + nodeRef + " is pointing to a version node, when a reference to a live node is expected.");
    }
    
    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 versionCount = versionAssocs.size();
    for (int i = versionCount; 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 == versionCount);
            
            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;
}
 
Example 30
/** @inheritDoc */
public void deleteTranslationContainer(NodeRef mlContainerNodeRef)
{
    if (!ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(mlContainerNodeRef)))
    {
        throw new IllegalArgumentException(
                "Node type must be " + ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    }

    // get the translations
    Map<Locale, NodeRef> translations = this.getTranslations(mlContainerNodeRef);

    // remember the number of childs
    int translationCount = translations.size();

    // remove the translations
    for(NodeRef translationToRemove : translations.values())
    {
        if (!nodeService.exists(translationToRemove))
        {
            // We've just queried for these
            throw new ConcurrencyFailureException("Translation has been deleted externally: " + translationToRemove);
        }
        nodeService.deleteNode(translationToRemove);
    }

    // Keep track of the container for pre-commit deletion
    TransactionalResourceHelper.getSet(KEY_ML_CONTAINERS_TO_DELETE).add(mlContainerNodeRef);
    AlfrescoTransactionSupport.bindListener(mlContainerCleaner);

    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("ML container removed: \n" +
                "   Container:  " + mlContainerNodeRef + "\n" +
                "   Number of translations: " + translationCount);
    }
}