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 public class DataAccessUtils {
31
32 private static final Set<Class<?>> OPTIMISTIC_LOCK_EXCEPTION_CLASSES = new HashSet<Class<?>>();
33
34
35 static {
36 addOptimisticLockExceptionClass(OptimisticLockException.class);
37 addOptimisticLockExceptionClass(OptimisticLockingFailureException.class);
38 }
39
40 public static boolean isOptimisticLockFailure(Exception exception) {
41 if (exception == null) {
42 return false;
43 }
44 for (final Class<?> exceptionClass : getOptimisticLockExceptionClasses()) {
45 if (exceptionClass.isInstance(exception) || exceptionClass.isInstance(exception.getCause())) {
46 return true;
47 }
48 }
49 return false;
50 }
51
52 public static void addOptimisticLockExceptionClass(Class exceptionClass) {
53 OPTIMISTIC_LOCK_EXCEPTION_CLASSES.add(exceptionClass);
54 }
55
56 public static Set<Class<?>> getOptimisticLockExceptionClasses() {
57 return OPTIMISTIC_LOCK_EXCEPTION_CLASSES;
58 }
59
60 }