KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > SQLExceptionFactory40


1 /*
2
3    Derby - Class org.apache.derby.client.am.SQLExceptionFactory40
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21 package org.apache.derby.client.am;
22
23 import org.apache.derby.shared.common.reference.SQLState;
24 import org.apache.derby.shared.common.error.ExceptionSeverity;
25
26 import java.sql.SQLDataException JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.sql.SQLFeatureNotSupportedException JavaDoc;
29 import java.sql.SQLIntegrityConstraintViolationException JavaDoc;
30 import java.sql.SQLInvalidAuthorizationSpecException JavaDoc;
31 import java.sql.SQLSyntaxErrorException JavaDoc;
32 import java.sql.SQLTransactionRollbackException JavaDoc;
33 import java.sql.SQLTransientConnectionException JavaDoc;
34
35 /**
36  * SQLException factory class to create jdbc 40 exception classes
37  */

38
39 public class SQLExceptionFactory40 extends SQLExceptionFactory {
40     
41     // Important DRDA SQL States, from DRDA v3 spec, Section 8.2
42
// We have to consider these as well as the standard SQLState classes
43
// when choosing the right exception subclass
44
private static final String JavaDoc DRDA_CONVERSATION_TERMINATED = "58009";
45     private static final String JavaDoc DRDA_COMMAND_NOT_SUPPORTED = "58014";
46     private static final String JavaDoc DRDA_OBJECT_NOT_SUPPORTED = "58015";
47     private static final String JavaDoc DRDA_PARAM_NOT_SUPPORTED = "58016";
48     private static final String JavaDoc DRDA_VALUE_NOT_SUPPORTED = "58017";
49     private static final String JavaDoc DRDA_SQLTYPE_NOT_SUPPORTED = "56084";
50     private static final String JavaDoc DRDA_CONVERSION_NOT_SUPPORTED = "57017";
51     private static final String JavaDoc DRDA_REPLY_MSG_NOT_SUPPORTED = "58018";
52        
53     /**
54      * creates jdbc4.0 SQLException and its subclass based on sql state
55      *
56      * @param message description of the
57      * @param sqlState
58      * @param errCode derby error code
59      */

60     public SQLException JavaDoc getSQLException (String JavaDoc message, String JavaDoc sqlState,
61                                                             int errCode) {
62         SQLException JavaDoc ex = null;
63         if (sqlState == null) {
64             ex = new SQLException JavaDoc(message, sqlState, errCode);
65         } else if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX) ||
66             errCode >= ExceptionSeverity.SESSION_SEVERITY) {
67             //none of the sqlstate supported by derby belongs to
68
//NonTransientConnectionException
69
ex = new SQLTransientConnectionException JavaDoc(message, sqlState, errCode);
70         } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
71             ex = new SQLDataException JavaDoc(message, sqlState, errCode);
72         } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
73             ex = new SQLIntegrityConstraintViolationException JavaDoc(message, sqlState,
74                     errCode);
75         } else if (sqlState.startsWith(SQLState.AUTHORIZATION_PREFIX)) {
76             ex = new SQLInvalidAuthorizationSpecException JavaDoc(message, sqlState,
77                     errCode);
78         } else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX) ||
79             errCode >= ExceptionSeverity.TRANSACTION_SEVERITY ) {
80             ex = new SQLTransactionRollbackException JavaDoc(message, sqlState,
81                     errCode);
82         } else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
83             ex = new SQLSyntaxErrorException JavaDoc(message, sqlState, errCode);
84         } else if (
85             sqlState.startsWith (SQLState.UNSUPPORTED_PREFIX) ||
86             sqlState.equals(DRDA_COMMAND_NOT_SUPPORTED) ||
87             sqlState.equals(DRDA_OBJECT_NOT_SUPPORTED) ||
88             sqlState.equals(DRDA_PARAM_NOT_SUPPORTED) ||
89             sqlState.equals(DRDA_VALUE_NOT_SUPPORTED) ||
90             sqlState.equals(DRDA_SQLTYPE_NOT_SUPPORTED) ||
91             sqlState.equals(DRDA_REPLY_MSG_NOT_SUPPORTED) ) {
92             ex = new SQLFeatureNotSupportedException JavaDoc(message, sqlState,
93                     errCode);
94         } else {
95             ex = new SQLException JavaDoc(message, sqlState, errCode);
96         }
97         return ex;
98     }
99 }
100
Popular Tags