org.springframework.dao.ConcurrencyFailureException Java Examples
The following examples show how to use
org.springframework.dao.ConcurrencyFailureException.
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
Source File: AbstractContentDataDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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 #2
Source File: AbstractQNameDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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 #3
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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
Source File: AbstractUsageDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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 #5
Source File: AbstractQNameDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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 #6
Source File: AuditDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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 #7
Source File: LockDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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 #8
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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 #9
Source File: RetryingTransactionHelperTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 #10
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void deleteAuthority(long id) { Pair<Long, AuthorityEntity> entityPair = authorityEntityCache.getByKey(id); if (entityPair == null) { return; } int deleted = authorityEntityCache.deleteByKey(id); if (deleted < 1) { aclEntityCache.removeByKey(id); throw new ConcurrencyFailureException("AuthorityEntity with ID " + id + " no longer exists"); } }
Example #11
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void renamePermission(QName oldTypeQName, String oldName, QName newTypeQName, String newName) { ParameterCheck.mandatory("oldTypeQName", oldTypeQName); ParameterCheck.mandatory("oldName", oldName); ParameterCheck.mandatory("newTypeQName", newTypeQName); ParameterCheck.mandatory("newName", newName); if (oldTypeQName.equals(newTypeQName) && oldName.equals(newName)) { throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName); } SimplePermissionReference oldPermRef = SimplePermissionReference.getPermissionReference(oldTypeQName, oldName); PermissionEntity permission = getPermissionForUpdate(oldPermRef); if (permission != null) { Long newTypeQNameId = qnameDAO.getOrCreateQName(newTypeQName).getFirst(); permission.setTypeQNameId(newTypeQNameId); permission.setName(newName); int updated = permissionEntityCache.updateValue(permission.getId(), permission); if (updated < 1) { aclEntityCache.removeByKey(permission.getId()); throw new ConcurrencyFailureException("PermissionEntity with ID (" + permission.getId() + ") no longer exists or has been updated concurrently"); } } }
Example #12
Source File: ExceptionTranslator.java From e-commerce-microservice with Apache License 2.0 | 5 votes |
@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 #13
Source File: AbstractNodeDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@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 #14
Source File: ExceptionTranslator.java From Spring-5.0-Projects with MIT License | 5 votes |
@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 #15
Source File: AbstractMimetypeDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public int updateMimetype(String oldMimetype, String newMimetype) { ParameterCheck.mandatory("oldMimetype", oldMimetype); oldMimetype = sanitizeMimetype(oldMimetype); ParameterCheck.mandatory("newMimetype", newMimetype); newMimetype = sanitizeMimetype(newMimetype); Pair<Long, String> oldMimetypePair = getMimetype(oldMimetype); if (oldMimetypePair == null) { // There is no mimetype currently, so there is nothing to update. // Just do a create getOrCreateMimetype(newMimetype); return 0; } // The ID will remain the same Long id = oldMimetypePair.getFirst(); // We have to update it int count = updateMimetypeEntity(id, newMimetype); if (count != 1) { throw new ConcurrencyFailureException("Concurrent update of mimetype: " + oldMimetype); } // Cache it mimetypeEntityCache.remove(oldMimetype); mimetypeEntityCache.put(id, newMimetype); mimetypeEntityCache.put(newMimetype, id); // Done return count; }
Example #16
Source File: ExceptionTranslator.java From TeamDojo with Apache License 2.0 | 5 votes |
@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 #17
Source File: ExceptionTranslator.java From e-commerce-microservice with Apache License 2.0 | 5 votes |
@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 #18
Source File: ExceptionTranslator.java From java-microservices-examples with Apache License 2.0 | 5 votes |
@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 #19
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void deletePermission(long id) { Pair<Long, PermissionEntity> entityPair = permissionEntityCache.getByKey(id); if (entityPair == null) { return; } int deleted = permissionEntityCache.deleteByKey(id); if (deleted < 1) { aclEntityCache.removeByKey(id); throw new ConcurrencyFailureException("PermissionEntity with ID " + id + " no longer exists"); } }
Example #20
Source File: ExceptionTranslator.java From Full-Stack-Development-with-JHipster with MIT License | 5 votes |
@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 #21
Source File: PropertyValueDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected PropertyUniqueContextEntity updatePropertyUniqueContext(PropertyUniqueContextEntity entity) { entity.incrementVersion(); int updated = template.update(UPDATE_PROPERTY_UNIQUE_CTX, entity); if (updated != 1) { // unexpected number of rows affected throw new ConcurrencyFailureException("Incorrect number of rows affected for updatePropertyUniqueContext: " + entity + ": expected 1, actual " + updated); } return entity; }
Example #22
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void deleteAclChangeSet(Long changeSetId) { int deleted = deleteAclChangeSetEntity(changeSetId); if (deleted != 1) { aclEntityCache.removeByKey(changeSetId); throw new ConcurrencyFailureException("Deleted by ID should delete exactly 1: " + changeSetId); } }
Example #23
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void updateAclChangeSet(Long aclChangeSetEntityId, long commitTimeMs) { int updated = updateChangeSetEntity(aclChangeSetEntityId, commitTimeMs); if (updated != 1) { throw new ConcurrencyFailureException("Update by ID should delete exactly 1: " + aclChangeSetEntityId); } }
Example #24
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void deleteAcl(long id) { Pair<Long, AclEntity> entityPair = aclEntityCache.getByKey(id); if (entityPair == null) { return; } int deleted = aclEntityCache.deleteByKey(id); if (deleted < 1) { aclEntityCache.removeByKey(id); throw new ConcurrencyFailureException("AclEntity with ID " + id + " no longer exists"); } }
Example #25
Source File: ExceptionTranslator.java From jhipster-online with Apache License 2.0 | 5 votes |
@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 #26
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void updateAcl(AclUpdateEntity entity) { ParameterCheck.mandatory("entity", entity); ParameterCheck.mandatory("entity.id", entity.getId()); ParameterCheck.mandatory("entity.aclVersion", entity.getAclVersion()); ParameterCheck.mandatory("entity.version", entity.getVersion()); int updated = aclEntityCache.updateValue(entity.getId(), entity); if (updated < 1) { aclEntityCache.removeByKey(entity.getId()); throw new ConcurrencyFailureException("AclEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently"); } }
Example #27
Source File: SQLExceptionSubclassTranslator.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #28
Source File: Version2ServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #29
Source File: MultilingualContentServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** @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); } }
Example #30
Source File: EmptyContentReader.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException { // ALF-17708: If we got the contentdata from the transactional cache, there's a chance that eager cleaning can // remove the content from under our feet throw new ConcurrencyFailureException(getContentUrl() + " no longer exists"); }