KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdbc.support;
18
19 import org.springframework.util.StringUtils;
20
21 /**
22  * JavaBean for holding JDBC error codes for a particular database.
23  * Instances of this class are normally loaded through a bean factory.
24  *
25  * <p>Used by Spring's SQLErrorCodeSQLExceptionTranslator.
26  * The file "sql-error-codes.xml" in this package contains default
27  * SQLErrorCodes instances for various databases.
28  *
29  * @author Thomas Risberg
30  * @author Juergen Hoeller
31  * @see SQLErrorCodesFactory
32  * @see SQLErrorCodeSQLExceptionTranslator
33  */

34 public class SQLErrorCodes {
35
36     private String JavaDoc[] databaseProductNames;
37
38     private boolean useSqlStateForTranslation = false;
39
40     private String JavaDoc[] badSqlGrammarCodes = new String JavaDoc[0];
41
42     private String JavaDoc[] invalidResultSetAccessCodes = new String JavaDoc[0];
43
44     private String JavaDoc[] dataAccessResourceFailureCodes = new String JavaDoc[0];
45
46     private String JavaDoc[] permissionDeniedCodes = new String JavaDoc[0];
47
48     private String JavaDoc[] dataIntegrityViolationCodes = new String JavaDoc[0];
49     
50     private String JavaDoc[] cannotAcquireLockCodes = new String JavaDoc[0];
51
52     private String JavaDoc[] deadlockLoserCodes = new String JavaDoc[0];
53
54     private String JavaDoc[] cannotSerializeTransactionCodes = new String JavaDoc[0];
55
56     private CustomSQLErrorCodesTranslation[] customTranslations;
57
58
59     /**
60      * Set this property if the database name contains spaces,
61      * in which case we can not use the bean name for lookup.
62      */

63     public void setDatabaseProductName(String JavaDoc databaseProductName) {
64         this.databaseProductNames = new String JavaDoc[] {databaseProductName};
65     }
66
67     public String JavaDoc getDatabaseProductName() {
68         return (this.databaseProductNames != null && this.databaseProductNames.length > 0 ?
69                 this.databaseProductNames[0] : null);
70     }
71
72     /**
73      * Set this property to specify multiple database names that contains spaces,
74      * in which case we can not use bean names for lookup.
75      */

76     public void setDatabaseProductNames(String JavaDoc[] databaseProductNames) {
77         this.databaseProductNames = databaseProductNames;
78     }
79
80     public String JavaDoc[] getDatabaseProductNames() {
81         return databaseProductNames;
82     }
83
84     /**
85      * Set this property to true for databases that do not provide an error code
86      * but that do provide SQL State (this includes PostgreSQL).
87      */

88     public void setUseSqlStateForTranslation(boolean useStateCodeForTranslation) {
89         this.useSqlStateForTranslation = useStateCodeForTranslation;
90     }
91
92     public boolean isUseSqlStateForTranslation() {
93         return useSqlStateForTranslation;
94     }
95
96
97     public void setBadSqlGrammarCodes(String JavaDoc[] badSqlGrammarCodes) {
98         this.badSqlGrammarCodes = StringUtils.sortStringArray(badSqlGrammarCodes);
99     }
100
101     public String JavaDoc[] getBadSqlGrammarCodes() {
102         return badSqlGrammarCodes;
103     }
104
105     public void setInvalidResultSetAccessCodes(String JavaDoc[] invalidResultSetAccessCodes) {
106         this.invalidResultSetAccessCodes = invalidResultSetAccessCodes;
107     }
108
109     public String JavaDoc[] getInvalidResultSetAccessCodes() {
110         return invalidResultSetAccessCodes;
111     }
112
113     public void setDataAccessResourceFailureCodes(String JavaDoc[] dataAccessResourceFailureCodes) {
114         this.dataAccessResourceFailureCodes = dataAccessResourceFailureCodes;
115     }
116
117     public String JavaDoc[] getDataAccessResourceFailureCodes() {
118         return dataAccessResourceFailureCodes;
119     }
120
121     public void setPermissionDeniedCodes(String JavaDoc[] permissionDeniedCodes) {
122         this.permissionDeniedCodes = StringUtils.sortStringArray(permissionDeniedCodes);
123     }
124
125     public String JavaDoc[] getPermissionDeniedCodes() {
126         return permissionDeniedCodes;
127     }
128
129     public void setDataIntegrityViolationCodes(String JavaDoc[] dataIntegrityViolationCodes) {
130         this.dataIntegrityViolationCodes = StringUtils.sortStringArray(dataIntegrityViolationCodes);
131     }
132
133     public String JavaDoc[] getDataIntegrityViolationCodes() {
134         return dataIntegrityViolationCodes;
135     }
136
137     public void setCannotAcquireLockCodes(String JavaDoc[] cannotAcquireLockCodes) {
138         this.cannotAcquireLockCodes = StringUtils.sortStringArray(cannotAcquireLockCodes);
139     }
140
141     public String JavaDoc[] getCannotAcquireLockCodes() {
142         return cannotAcquireLockCodes;
143     }
144
145     public void setDeadlockLoserCodes(String JavaDoc[] deadlockLoserCodes) {
146         this.deadlockLoserCodes = deadlockLoserCodes;
147     }
148
149     public String JavaDoc[] getDeadlockLoserCodes() {
150         return deadlockLoserCodes;
151     }
152
153     public void setCannotSerializeTransactionCodes(String JavaDoc[] cannotSerializeTransactionCodes) {
154         this.cannotSerializeTransactionCodes = cannotSerializeTransactionCodes;
155     }
156     
157     public String JavaDoc[] getCannotSerializeTransactionCodes() {
158         return cannotSerializeTransactionCodes;
159     }
160
161     public void setCustomTranslations(CustomSQLErrorCodesTranslation[] customTranslations) {
162         this.customTranslations = customTranslations;
163     }
164
165     public CustomSQLErrorCodesTranslation[] getCustomTranslations() {
166         return customTranslations;
167     }
168
169 }
170
Popular Tags