KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > dao > support > PersistenceExceptionTranslator


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.dao.support;
18
19 import org.springframework.dao.DataAccessException;
20
21 /**
22  * Interface implemented by Spring integrations with data access technologies
23  * that throw runtime exceptions, such as JPA, TopLink, JDO and Hibernate.
24  *
25  * <p>This allows consistent usage of combined exception translation functionality,
26  * without forcing a single translator to understand every single possible type
27  * of exception.
28  *
29  * @author Rod Johnson
30  * @author Juergen Hoeller
31  * @since 2.0
32  */

33 public interface PersistenceExceptionTranslator {
34     
35     /**
36      * Translate the given runtime exception thrown by a persistence framework to a
37      * corresponding exception from Spring's generic DataAccessException hierarchy,
38      * if possible.
39      * <p>Do not translate exceptions that are not understand by this translator:
40      * for example, if coming from another persistence framework, or resulting
41      * from user code and unrelated to persistence.
42      * <p>Of particular importance is the correct translation to
43      * DataIntegrityViolationException, for example on constraint violation.
44      * Implementations may use Spring JDBC's sophisticated exception translation
45      * to provide further information in the event of SQLException as a root cause.
46      * @param ex a RuntimeException thrown
47      * @return the corresponding DataAccessException (or <code>null</code> if the
48      * exception could not be translated, as in this case it may result from
49      * user code rather than an actual persistence problem)
50      * @see org.springframework.dao.DataIntegrityViolationException
51      * @see org.springframework.jdbc.support.SQLExceptionTranslator
52      */

53     DataAccessException translateExceptionIfPossible(RuntimeException JavaDoc ex);
54
55 }
56
Popular Tags