001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.core.framework.persistence.ojb; 017 018import java.util.Collections; 019import java.util.HashSet; 020import java.util.Set; 021 022import org.apache.commons.lang.exception.ExceptionUtils; 023import org.apache.ojb.broker.OptimisticLockException; 024import org.springframework.dao.OptimisticLockingFailureException; 025 026/** 027 * Provides some simple utilities for working with data access exceptions. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031@Deprecated 032public final class DataAccessUtils { 033 034 private static final Set<Class<? extends Throwable>> OPTIMISTIC_LOCK_EXCEPTION_CLASSES = new HashSet<Class<? extends Throwable>>(); 035 036 private DataAccessUtils() { 037 throw new UnsupportedOperationException("do not call"); 038 } 039 040 // add some standard optimistic lock exception classes 041 static { 042 addOptimisticLockExceptionClass(OptimisticLockException.class); 043 addOptimisticLockExceptionClass(OptimisticLockingFailureException.class); 044 } 045 046 public static synchronized boolean isOptimisticLockFailure(Throwable exception) { 047 if (exception == null) { 048 return false; 049 } 050 for (final Class<?> exceptionClass : getOptimisticLockExceptionClasses()) { 051 if (ExceptionUtils.indexOfType(exception, exceptionClass) >= 0) { 052 return true; 053 } 054 } 055 return false; 056 } 057 058 public static synchronized void addOptimisticLockExceptionClass(Class<? extends Throwable> exceptionClass) { 059 OPTIMISTIC_LOCK_EXCEPTION_CLASSES.add(exceptionClass); 060 } 061 062 public static synchronized Set<Class<? extends Throwable>> getOptimisticLockExceptionClasses() { 063 return Collections.unmodifiableSet(OPTIMISTIC_LOCK_EXCEPTION_CLASSES); 064 } 065 066}