01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.jdbc.support;
18:
19: import java.sql.SQLException;
20:
21: import org.springframework.dao.DataAccessException;
22:
23: /**
24: * Strategy interface for translating between {@link SQLException SQLExceptions}
25: * and Spring's data access strategy-agnostic {@link DataAccessException}
26: * hierarchy.
27: *
28: * <p>Implementations can be generic (for example, using
29: * {@link java.sql.SQLException#getSQLState() SQLState} codes for JDBC) or wholly
30: * proprietary (for example, using Oracle error codes) for greater precision.
31: *
32: * @author Rod Johnson
33: * @author Juergen Hoeller
34: * @see org.springframework.dao.DataAccessException
35: */
36: public interface SQLExceptionTranslator {
37:
38: /**
39: * Translate the given {@link SQLException} into a generic {@link DataAccessException}.
40: * <p>The returned DataAccessException is supposed to contain the original
41: * <code>SQLException</code> as root cause. However, client code may not generally
42: * rely on this due to DataAccessExceptions possibly being caused by other resource
43: * APIs as well. That said, a <code>getRootCause() instanceof SQLException</code>
44: * check (and subsequent cast) is considered reliable when expecting JDBC-based
45: * access to have happened.
46: * @param task readable text describing the task being attempted
47: * @param sql SQL query or update that caused the problem (may be <code>null</code>)
48: * @param ex the offending <code>SQLException</code>
49: * @return the DataAccessException, wrapping the <code>SQLException</code>
50: * @see org.springframework.dao.DataAccessException#getRootCause()
51: */
52: DataAccessException translate(String task, String sql,
53: SQLException ex);
54:
55: }
|