1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.util; |
17 | |
|
18 | |
import java.util.HashSet; |
19 | |
import java.util.Set; |
20 | |
|
21 | |
import org.apache.ojb.broker.OptimisticLockException; |
22 | |
import org.springframework.dao.OptimisticLockingFailureException; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class DataAccessUtils { |
31 | |
|
32 | 0 | private static final Set<Class<?>> OPTIMISTIC_LOCK_EXCEPTION_CLASSES = new HashSet<Class<?>>(); |
33 | |
|
34 | |
|
35 | |
static { |
36 | 0 | addOptimisticLockExceptionClass(OptimisticLockException.class); |
37 | 0 | addOptimisticLockExceptionClass(OptimisticLockingFailureException.class); |
38 | 0 | } |
39 | |
|
40 | |
public static boolean isOptimisticLockFailure(Exception exception) { |
41 | 0 | if (exception == null) { |
42 | 0 | return false; |
43 | |
} |
44 | 0 | for (final Class<?> exceptionClass : getOptimisticLockExceptionClasses()) { |
45 | 0 | if (exceptionClass.isInstance(exception) || exceptionClass.isInstance(exception.getCause())) { |
46 | 0 | return true; |
47 | |
} |
48 | |
} |
49 | 0 | return false; |
50 | |
} |
51 | |
|
52 | |
public static void addOptimisticLockExceptionClass(Class exceptionClass) { |
53 | 0 | OPTIMISTIC_LOCK_EXCEPTION_CLASSES.add(exceptionClass); |
54 | 0 | } |
55 | |
|
56 | |
public static Set<Class<?>> getOptimisticLockExceptionClasses() { |
57 | 0 | return OPTIMISTIC_LOCK_EXCEPTION_CLASSES; |
58 | |
} |
59 | |
|
60 | |
} |