java lockmodetype_Java类javax.persistence.PessimisticLockException的实例源码 - 编程字典

/**

* Convert the given runtime exception to an appropriate exception from the

* {@code org.springframework.dao} hierarchy.

* Return null if no translation is appropriate: any other exception may

* have resulted from user code, and should not be translated.

*

The most important cases like object not found or optimistic locking failure

* are covered here. For more fine-granular conversion, JpaTransactionManager etc

* support sophisticated translation of exceptions via a JpaDialect.

* @param ex runtime exception that occurred

* @return the corresponding DataAccessException instance,

* or {@code null} if the exception should not be translated

*/

public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {

// Following the JPA specification, a persistence provider can also

// throw these two exceptions, besides PersistenceException.

if (ex instanceof IllegalStateException) {

return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);

}

if (ex instanceof IllegalArgumentException) {

return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);

}

// Check for well-known PersistenceException subclasses.

if (ex instanceof EntityNotFoundException) {

return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);

}

if (ex instanceof NoResultException) {

return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);

}

if (ex instanceof NonUniqueResultException) {

return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);

}

if (ex instanceof QueryTimeoutException) {

return new org.springframework.dao.QueryTimeoutException(ex.getMessage(), ex);

}

if (ex instanceof LockTimeoutException) {

return new CannotAcquireLockException(ex.getMessage(), ex);

}

if (ex instanceof PessimisticLockException) {

return new PessimisticLockingFailureException(ex.getMessage(), ex);

}

if (ex instanceof OptimisticLockException) {

return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);

}

if (ex instanceof EntityExistsException) {

return new DataIntegrityViolationException(ex.getMessage(), ex);

}

if (ex instanceof TransactionRequiredException) {

return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);

}

// If we have another kind of PersistenceException, throw it.

if (ex instanceof PersistenceException) {

return new JpaSystemException((PersistenceException) ex);

}

// If we get here, we have an exception that resulted from user code,

// rather than the persistence provider, so we return null to indicate

// that translation should not occur.

return null;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值