KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > support > CustomSQLErrorCodesTranslation


1 /*
2  * Copyright 2002-2005 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.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 JavaDoc[] errorCodes = new String JavaDoc[0];
37
38     private Class JavaDoc exceptionClass;
39     
40     /**
41      * Set the SQL error codes to match.
42      */

43     public void setErrorCodes(String JavaDoc[] errorCodes) {
44         this.errorCodes = StringUtils.sortStringArray(errorCodes);
45     }
46
47     /**
48      * Return the SQL error codes to match.
49      */

50     public String JavaDoc[] getErrorCodes() {
51         return errorCodes;
52     }
53
54     /**
55      * Set the exception class for the specified error codes.
56      */

57     public void setExceptionClass(Class JavaDoc exceptionClass) {
58         if (!DataAccessException.class.isAssignableFrom(exceptionClass)) {
59             throw new IllegalArgumentException JavaDoc("Invalid exception class [" + exceptionClass +
60                     "]: needs to be a subclass of [org.springframework.dao.DataAccessException]");
61         }
62         this.exceptionClass = exceptionClass;
63     }
64
65     /**
66      * Return the exception class for the specified error codes.
67      */

68     public Class JavaDoc getExceptionClass() {
69         return exceptionClass;
70     }
71
72 }
73
Popular Tags