KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > exceptions > driver > protocol > ControllerCoreException


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Marc Herbert
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.common.exceptions.driver.protocol;
23
24 import java.io.IOException JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.continuent.sequoia.common.exceptions.NoMoreBackendException;
28 import org.continuent.sequoia.common.exceptions.NoMoreControllerException;
29 import org.continuent.sequoia.common.exceptions.NotImplementedException;
30 import org.continuent.sequoia.common.stream.DriverBufferedInputStream;
31
32 /**
33  * This class is meant for exceptions originated in controller core (i.e.,
34  * non-backend) that are serialized to the driver.
35  *
36  * @author <a HREF="mailto:Marc.Herbert@emicnetworks.com">Marc Herbert</a>
37  * @version 1.0
38  */

39 public class ControllerCoreException extends SerializableException
40 {
41   private static final long serialVersionUID = -4526646797888340909L;
42
43   private static final int UNKNOWN = 0;
44   private static final int NO_MORE_BACKEND = 1;
45   private static final int NO_MORE_CONTROLLER = 2;
46   private static final int NOT_IMPLEMENTED = 3;
47
48   private static int exceptionTypeCode(Throwable JavaDoc ex)
49   {
50     if (ex instanceof NoMoreBackendException)
51       return NO_MORE_BACKEND;
52     if (ex instanceof NoMoreControllerException)
53       return NO_MORE_CONTROLLER;
54     if (ex instanceof NotImplementedException)
55       return NOT_IMPLEMENTED;
56
57     return UNKNOWN;
58   }
59
60   /**
61    * This method returns a wrapper around 'this' ControllerCoreException, in
62    * order to stay bug for bug compatible with legacy exception handling code.
63    * This method should disappear and be implemented above, directly by the code
64    * calling it.
65    *
66    * @deprecated
67    * @return a wrapper around this object
68    */

69   public Exception JavaDoc compatibilityWrapperHack()
70   {
71     Exception JavaDoc wrapper;
72     switch (this.getErrorCode())
73     {
74       case NO_MORE_BACKEND :
75         wrapper = new NoMoreBackendException(getMessage(), getSQLState(),
76             getErrorCode());
77         break;
78       case NO_MORE_CONTROLLER :
79         wrapper = new NoMoreControllerException(getMessage(), getSQLState(),
80             getErrorCode());
81         break;
82       case NOT_IMPLEMENTED :
83         wrapper = new NotImplementedException(getMessage(), getSQLState(),
84             getErrorCode());
85         break;
86       default : // hey, why not ?
87
wrapper = new SQLException JavaDoc(getMessage(), getSQLState(), getErrorCode());
88     }
89     wrapper.initCause(this);
90     return wrapper;
91   }
92
93   /**
94    * @see SerializableException#SerializableException(DriverBufferedInputStream)
95    */

96   public ControllerCoreException(DriverBufferedInputStream in) throws IOException JavaDoc
97   {
98     super(in);
99   }
100
101   /**
102    * Converts a chain of Throwables to a new chain of SerializableExceptions
103    * starting with a <code>ControllerCoreException</code>. The returned chain
104    * has the same length.
105    *
106    * @param ex head of chain to convert
107    * @see SerializableException#SerializableException(Throwable)
108    */

109   public ControllerCoreException(Throwable JavaDoc ex)
110   {
111     super(ex);
112
113     // This is the place where we could set your own SQL codes
114
// super.SQLState = sqlE.getSQLState();
115

116     // hack: let's use vendorCode int as a type
117
setErrorCode(exceptionTypeCode(ex));
118
119   }
120
121 }
122
Popular Tags