本文整理汇总了Java中org.springframework.dao.ConcurrencyFailureException类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrencyFailureException类的具体用法?Java ConcurrencyFailureException怎么用?Java ConcurrencyFailureException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrencyFailureException类属于org.springframework.dao包,在下文中一共展示了ConcurrencyFailureException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInRetryingTransaction
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
/**
* To allow for possible 'read committed' behaviour in some databases, where a node that previously existed during a
* transaction can disappear from existence, we treat InvalidNodeRefExceptions as concurrency conditions.
*/
protected <T2> T2 doInRetryingTransaction(final RetryingTransactionCallback<T2> callback, boolean isReadThrough)
{
return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<T2>()
{
@Override
public T2 execute() throws Throwable
{
try
{
return callback.execute();
}
catch (InvalidNodeRefException e)
{
// Turn InvalidNodeRefExceptions into retryable exceptions.
throw new ConcurrencyFailureException("Possible cache integrity issue during reindexing", e);
}
}
}, true, isReadThrough);
}
示例2: updateAclMember
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
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");
}
}
示例3: renameAuthority
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
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");
}
}
}
示例4: updateAuditApplication
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@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;
}
示例5: getTotalDeltaSize
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
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);
}
示例6: updateNamespace
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
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
}
示例7: deleteQName
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@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);
}
}
示例8: updateLock
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@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;
}
示例9: updateContentData
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@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");
}
}
示例10: testSuccessWithRetry
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
/**
* Check that the retries happening for simple concurrency exceptions
*/
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);
}
示例11: doTranslate
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
String sqlState = getSqlState(ex);
if (sqlState != null && sqlState.length() >= 2) {
String classCode = sqlState.substring(0, 2);
if (logger.isDebugEnabled()) {
logger.debug("Extracted SQL state class '" + classCode + "' from value '" + sqlState + "'");
}
if (BAD_SQL_GRAMMAR_CODES.contains(classCode)) {
return new BadSqlGrammarException(task, sql, ex);
}
else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
}
else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
}
else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
}
else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
}
}
return null;
}
示例12: updateContent
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
/**
* Update an existing content item.
*
* @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;
}
示例13: pauseRollout
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void pauseRollout(final Long rolloutId) {
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
if (!RolloutStatus.RUNNING.equals(rollout.getStatus())) {
throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is "
+ rollout.getStatus().name().toLowerCase());
}
// setting the complete rollout only in paused state. This is sufficient
// due the currently running groups will be completed and new groups are
// not started until rollout goes back to running state again. The
// periodically check for running rollouts will skip rollouts in pause
// state.
rollout.setStatus(RolloutStatus.PAUSED);
rolloutRepository.save(rollout);
}
示例14: delete
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Long rolloutId) {
final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId);
if (jpaRollout == null) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}
if (RolloutStatus.DELETING.equals(jpaRollout.getStatus())) {
return;
}
jpaRollout.setStatus(RolloutStatus.DELETING);
rolloutRepository.save(jpaRollout);
}
示例15: _getOrphanMessagesWithRetries
import org.springframework.dao.ConcurrencyFailureException; //导入依赖的package包/类
/**
* Get all orphan messages (messages that were left in ephemeral storage for
* a long time), retry if deadlock.
*
* <p>
* Note: http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
* </p>
* <p>
* InnoDB uses automatic row-level locking. You can get deadlocks even in
* the case of transactions that just insert or delete a single row. That is
* because these operations are not really "atomic"; they automatically set
* locks on the (possibly several) index records of the row inserted or
* deleted.
* </p>
*
* @param thresholdTimestampMs
* @param conn
* @param numRetries
* @param maxRetries
* @return
* @since 0.2.0
*/
protected Collection<? extends IQueueMessage<ID, DATA>> _getOrphanMessagesWithRetries(
long thresholdTimestampMs, Connection conn, int numRetries, int maxRetries) {
try {
jdbcHelper.startTransaction(conn);
conn.setTransactionIsolation(transactionIsolationLevel);
Collection<? extends IQueueMessage<ID, DATA>> msgs = getOrphanFromEphemeralStorage(conn,
thresholdTimestampMs);
jdbcHelper.commitTransaction(conn);
return msgs;
} catch (DaoException de) {
if (de.getCause() instanceof ConcurrencyFailureException) {
jdbcHelper.rollbackTransaction(conn);
if (numRetries > maxRetries) {
throw new QueueException(de);
} else {
return _getOrphanMessagesWithRetries(thresholdTimestampMs, conn, numRetries + 1,
maxRetries);
}
}
throw de;
} catch (Exception e) {
jdbcHelper.rollbackTransaction(conn);
throw e instanceof QueueException ? (QueueException) e : new QueueException(e);
}
}