01: /*
02: * Copyright 2002-2005 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 org.springframework.dao.DataAccessException;
20: import org.springframework.util.StringUtils;
21:
22: /**
23: * JavaBean for holding Custom JDBC Error Codes translation for a particular
24: * database. The exceptionClass property defines which exception will be
25: * thrown for the list of error codes specified in the errorCodes property.
26: *
27: * <p>Normally loaded through a BeanFactory implementation.
28: * Used by the SQLErrorCodeSQLExceptionTranslator.
29: *
30: * @author Thomas Risberg
31: * @since 1.1
32: * @see SQLErrorCodeSQLExceptionTranslator
33: */
34: public class CustomSQLErrorCodesTranslation {
35:
36: private String[] errorCodes = new String[0];
37:
38: private Class exceptionClass;
39:
40: /**
41: * Set the SQL error codes to match.
42: */
43: public void setErrorCodes(String[] errorCodes) {
44: this .errorCodes = StringUtils.sortStringArray(errorCodes);
45: }
46:
47: /**
48: * Return the SQL error codes to match.
49: */
50: public String[] getErrorCodes() {
51: return errorCodes;
52: }
53:
54: /**
55: * Set the exception class for the specified error codes.
56: */
57: public void setExceptionClass(Class exceptionClass) {
58: if (!DataAccessException.class.isAssignableFrom(exceptionClass)) {
59: throw new IllegalArgumentException(
60: "Invalid exception class ["
61: + exceptionClass
62: + "]: needs to be a subclass of [org.springframework.dao.DataAccessException]");
63: }
64: this .exceptionClass = exceptionClass;
65: }
66:
67: /**
68: * Return the exception class for the specified error codes.
69: */
70: public Class getExceptionClass() {
71: return exceptionClass;
72: }
73:
74: }
|