001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jdbc.support;
018:
019: import org.springframework.util.StringUtils;
020:
021: /**
022: * JavaBean for holding JDBC error codes for a particular database.
023: * Instances of this class are normally loaded through a bean factory.
024: *
025: * <p>Used by Spring's {@link SQLErrorCodeSQLExceptionTranslator}.
026: * The file "sql-error-codes.xml" in this package contains default
027: * <code>SQLErrorCodes</code> instances for various databases.
028: *
029: * @author Thomas Risberg
030: * @author Juergen Hoeller
031: * @see SQLErrorCodesFactory
032: * @see SQLErrorCodeSQLExceptionTranslator
033: */
034: public class SQLErrorCodes {
035:
036: private String[] databaseProductNames;
037:
038: private boolean useSqlStateForTranslation = false;
039:
040: private String[] badSqlGrammarCodes = new String[0];
041:
042: private String[] invalidResultSetAccessCodes = new String[0];
043:
044: private String[] dataAccessResourceFailureCodes = new String[0];
045:
046: private String[] permissionDeniedCodes = new String[0];
047:
048: private String[] dataIntegrityViolationCodes = new String[0];
049:
050: private String[] cannotAcquireLockCodes = new String[0];
051:
052: private String[] deadlockLoserCodes = new String[0];
053:
054: private String[] cannotSerializeTransactionCodes = new String[0];
055:
056: private CustomSQLErrorCodesTranslation[] customTranslations;
057:
058: /**
059: * Set this property if the database name contains spaces,
060: * in which case we can not use the bean name for lookup.
061: */
062: public void setDatabaseProductName(String databaseProductName) {
063: this .databaseProductNames = new String[] { databaseProductName };
064: }
065:
066: public String getDatabaseProductName() {
067: return (this .databaseProductNames != null
068: && this .databaseProductNames.length > 0 ? this .databaseProductNames[0]
069: : null);
070: }
071:
072: /**
073: * Set this property to specify multiple database names that contains spaces,
074: * in which case we can not use bean names for lookup.
075: */
076: public void setDatabaseProductNames(String[] databaseProductNames) {
077: this .databaseProductNames = databaseProductNames;
078: }
079:
080: public String[] getDatabaseProductNames() {
081: return this .databaseProductNames;
082: }
083:
084: /**
085: * Set this property to true for databases that do not provide an error code
086: * but that do provide SQL State (this includes PostgreSQL).
087: */
088: public void setUseSqlStateForTranslation(
089: boolean useStateCodeForTranslation) {
090: this .useSqlStateForTranslation = useStateCodeForTranslation;
091: }
092:
093: public boolean isUseSqlStateForTranslation() {
094: return this .useSqlStateForTranslation;
095: }
096:
097: public void setBadSqlGrammarCodes(String[] badSqlGrammarCodes) {
098: this .badSqlGrammarCodes = StringUtils
099: .sortStringArray(badSqlGrammarCodes);
100: }
101:
102: public String[] getBadSqlGrammarCodes() {
103: return this .badSqlGrammarCodes;
104: }
105:
106: public void setInvalidResultSetAccessCodes(
107: String[] invalidResultSetAccessCodes) {
108: this .invalidResultSetAccessCodes = invalidResultSetAccessCodes;
109: }
110:
111: public String[] getInvalidResultSetAccessCodes() {
112: return this .invalidResultSetAccessCodes;
113: }
114:
115: public void setDataAccessResourceFailureCodes(
116: String[] dataAccessResourceFailureCodes) {
117: this .dataAccessResourceFailureCodes = dataAccessResourceFailureCodes;
118: }
119:
120: public String[] getDataAccessResourceFailureCodes() {
121: return this .dataAccessResourceFailureCodes;
122: }
123:
124: public void setPermissionDeniedCodes(String[] permissionDeniedCodes) {
125: this .permissionDeniedCodes = StringUtils
126: .sortStringArray(permissionDeniedCodes);
127: }
128:
129: public String[] getPermissionDeniedCodes() {
130: return this .permissionDeniedCodes;
131: }
132:
133: public void setDataIntegrityViolationCodes(
134: String[] dataIntegrityViolationCodes) {
135: this .dataIntegrityViolationCodes = StringUtils
136: .sortStringArray(dataIntegrityViolationCodes);
137: }
138:
139: public String[] getDataIntegrityViolationCodes() {
140: return this .dataIntegrityViolationCodes;
141: }
142:
143: public void setCannotAcquireLockCodes(
144: String[] cannotAcquireLockCodes) {
145: this .cannotAcquireLockCodes = StringUtils
146: .sortStringArray(cannotAcquireLockCodes);
147: }
148:
149: public String[] getCannotAcquireLockCodes() {
150: return this .cannotAcquireLockCodes;
151: }
152:
153: public void setDeadlockLoserCodes(String[] deadlockLoserCodes) {
154: this .deadlockLoserCodes = deadlockLoserCodes;
155: }
156:
157: public String[] getDeadlockLoserCodes() {
158: return this .deadlockLoserCodes;
159: }
160:
161: public void setCannotSerializeTransactionCodes(
162: String[] cannotSerializeTransactionCodes) {
163: this .cannotSerializeTransactionCodes = cannotSerializeTransactionCodes;
164: }
165:
166: public String[] getCannotSerializeTransactionCodes() {
167: return this .cannotSerializeTransactionCodes;
168: }
169:
170: public void setCustomTranslations(
171: CustomSQLErrorCodesTranslation[] customTranslations) {
172: this .customTranslations = customTranslations;
173: }
174:
175: public CustomSQLErrorCodesTranslation[] getCustomTranslations() {
176: return this.customTranslations;
177: }
178:
179: }
|