Detect SQL state 23505/40001 as DuplicateKeyException/CannotAcquireLockException
Favors PessimisticLockingFailureException over plain ConcurrencyFailureException. Deprecates CannotSerializeTransactionException and DeadlockLoserDataAccessException. Closes gh-29511 Closes gh-29675
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,9 @@ package org.springframework.dao;
|
||||
* Exception thrown on failure to acquire a lock during an update,
|
||||
* for example during a "select for update" statement.
|
||||
*
|
||||
* <p>Consider handling the general {@link PessimisticLockingFailureException}
|
||||
* instead, semantically including a wider range of locking-related failures.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,8 +20,14 @@ package org.springframework.dao;
|
||||
* Exception thrown on failure to complete a transaction in serialized mode
|
||||
* due to update conflicts.
|
||||
*
|
||||
* <p>Consider handling the general {@link PessimisticLockingFailureException}
|
||||
* instead, semantically including a wider range of locking-related failures.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @deprecated as of 6.0.3, in favor of
|
||||
* {@link PessimisticLockingFailureException}/{@link CannotAcquireLockException}
|
||||
*/
|
||||
@Deprecated(since = "6.0.3")
|
||||
@SuppressWarnings("serial")
|
||||
public class CannotSerializeTransactionException extends PessimisticLockingFailureException {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,9 @@ package org.springframework.dao;
|
||||
* to keep the original data access exception, if any.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @deprecated as of 6.0.3 since it is not in use within core JDBC/ORM support
|
||||
*/
|
||||
@Deprecated(since = "6.0.3")
|
||||
@SuppressWarnings("serial")
|
||||
public class CleanupFailureDataAccessException extends NonTransientDataAccessException {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,17 +19,15 @@ package org.springframework.dao;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown on concurrency failure.
|
||||
* Exception thrown on various data access concurrency failures.
|
||||
*
|
||||
* <p>This exception should be subclassed to indicate the type of failure:
|
||||
* optimistic locking, failure to acquire lock, etc.
|
||||
* <p>This exception provides subclasses for specific types of failure,
|
||||
* in particular optimistic locking versus pessimistic locking.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @since 1.1
|
||||
* @see OptimisticLockingFailureException
|
||||
* @see PessimisticLockingFailureException
|
||||
* @see CannotAcquireLockException
|
||||
* @see DeadlockLoserDataAccessException
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ConcurrencyFailureException extends TransientDataAccessException {
|
||||
|
||||
@@ -19,8 +19,13 @@ package org.springframework.dao;
|
||||
/**
|
||||
* Exception thrown when an attempt to insert or update data
|
||||
* results in violation of an integrity constraint. Note that this
|
||||
* is not purely a relational concept; unique primary keys are
|
||||
* required by most database types.
|
||||
* is not purely a relational concept; integrity constraints such
|
||||
* as unique primary keys are required by most database types.
|
||||
*
|
||||
* <p>Serves as a superclass for more specific exceptions, e.g.
|
||||
* {@link DuplicateKeyException}. However, it is generally
|
||||
* recommended to handle {@code DataIntegrityViolationException}
|
||||
* itself instead of relying on specific exception subclasses.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,8 +20,14 @@ package org.springframework.dao;
|
||||
* Generic exception thrown when the current process was
|
||||
* a deadlock loser, and its transaction rolled back.
|
||||
*
|
||||
* <p>Consider handling the general {@link PessimisticLockingFailureException}
|
||||
* instead, semantically including a wider range of locking-related failures.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @deprecated as of 6.0.3, in favor of
|
||||
* {@link PessimisticLockingFailureException}/{@link CannotAcquireLockException}
|
||||
*/
|
||||
@Deprecated(since = "6.0.3")
|
||||
@SuppressWarnings("serial")
|
||||
public class DeadlockLoserDataAccessException extends PessimisticLockingFailureException {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,9 @@ package org.springframework.dao;
|
||||
* Note that this is not necessarily a purely relational concept;
|
||||
* unique primary keys are required by most database types.
|
||||
*
|
||||
* <p>Consider handling the general {@link DataIntegrityViolationException}
|
||||
* instead, semantically including a wider range of constraint violations.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,13 +21,13 @@ package org.springframework.dao;
|
||||
* Thrown by Spring's SQLException translation mechanism
|
||||
* if a corresponding database error is encountered.
|
||||
*
|
||||
* <p>Serves as superclass for more specific exceptions, like
|
||||
* CannotAcquireLockException and DeadlockLoserDataAccessException.
|
||||
* <p>Serves as a superclass for more specific exceptions, e.g.
|
||||
* {@link CannotAcquireLockException}. However, it is generally
|
||||
* recommended to handle {@code PessimisticLockingFailureException}
|
||||
* itself instead of relying on specific exception subclasses.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @since 1.2
|
||||
* @see CannotAcquireLockException
|
||||
* @see DeadlockLoserDataAccessException
|
||||
* @see OptimisticLockingFailureException
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
Reference in New Issue
Block a user