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