KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > jdbc > BrokeredConnection40


1 /*
2  
3    Derby - Class org.apache.derby.iapi.jdbc.BrokeredConnection40
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
22 package org.apache.derby.iapi.jdbc;
23
24 import java.sql.Array JavaDoc;
25 import java.sql.Blob JavaDoc;
26 import java.sql.Clob JavaDoc;
27 import java.sql.Connection JavaDoc;
28 import java.sql.SQLClientInfoException JavaDoc;
29 import java.sql.NClob JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.SQLXML JavaDoc;
32 import java.sql.Struct JavaDoc;
33 import java.util.Properties JavaDoc;
34 import org.apache.derby.impl.jdbc.Util;
35 //import org.apache.derby.impl.jdbc.EmbedConnection40;
36
import org.apache.derby.iapi.reference.SQLState;
37
38
39 public class BrokeredConnection40 extends BrokeredConnection30 {
40     
41     /** Creates a new instance of BrokeredConnection40 */
42     public BrokeredConnection40(BrokeredConnectionControl control) {
43         super(control);
44     }
45     
46     public Array JavaDoc createArrayOf(String JavaDoc typeName, Object JavaDoc[] elements)
47           throws SQLException JavaDoc {
48          try {
49              return getRealConnection().createArrayOf (typeName, elements);
50          } catch (SQLException JavaDoc sqle) {
51              notifyException(sqle);
52              throw sqle;
53          }
54     }
55     
56     /**
57      *
58      * Constructs an object that implements the <code>Blob</code> interface. The object
59      * returned initially contains no data. The <code>setBinaryStream</code> and
60      * <code>setBytes</code> methods of the <code>Blob</code> interface may be used to add data to
61      * the <code>Blob</code>.
62      *
63      * @return An object that implements the <code>Blob</code> interface
64      * @throws SQLException if an object that implements the
65      * <code>Blob</code> interface can not be constructed, this method is
66      * called on a closed connection or a database access error occurs.
67      *
68      */

69     public Blob JavaDoc createBlob() throws SQLException JavaDoc {
70         if (isClosed()) {
71             throw Util.noCurrentConnection();
72         }
73         // Forward the createBlob call to the physical connection
74
try {
75             return getRealConnection().createBlob();
76         } catch (SQLException JavaDoc sqle) {
77             notifyException(sqle);
78             throw sqle;
79         }
80     }
81
82     /**
83      *
84      * Constructs an object that implements the <code>Clob</code> interface. The object
85      * returned initially contains no data. The <code>setAsciiStream</code>,
86      * <code>setCharacterStream</code> and <code>setString</code> methods of
87      * the <code>Clob</code> interface may be used to add data to the <code>Clob</code>.
88      *
89      * @return An object that implements the <code>Clob</code> interface
90      * @throws SQLException if an object that implements the
91      * <code>Clob</code> interface can not be constructed, this method is
92      * called on a closed connection or a database access error occurs.
93      *
94      */

95     public Clob JavaDoc createClob() throws SQLException JavaDoc{
96         if (isClosed()) {
97             throw Util.noCurrentConnection();
98         }
99         // Forward the createClob call to the physical connection
100
try {
101             return getRealConnection().createClob();
102         } catch (SQLException JavaDoc sqle) {
103             notifyException(sqle);
104             throw sqle;
105         }
106     }
107     
108     
109     public NClob JavaDoc createNClob() throws SQLException JavaDoc{
110          try {
111              return getRealConnection().createNClob();
112          } catch (SQLException JavaDoc sqle) {
113              notifyException(sqle);
114              throw sqle;
115          }
116     }
117     
118     public SQLXML JavaDoc createSQLXML() throws SQLException JavaDoc{
119          try {
120              return getRealConnection().createSQLXML ();
121          } catch (SQLException JavaDoc sqle) {
122              notifyException(sqle);
123              throw sqle;
124          }
125     }
126     
127     public Struct JavaDoc createStruct(String JavaDoc typeName, Object JavaDoc[] attributes)
128           throws SQLException JavaDoc {
129          try {
130              return getRealConnection().createStruct (typeName, attributes);
131          } catch (SQLException JavaDoc sqle) {
132              notifyException(sqle);
133              throw sqle;
134          }
135     }
136
137
138     /**
139      * Checks if the connection has not been closed and is still valid.
140      * The validity is checked by running a simple query against the
141      * database.
142      *
143      * @param timeout The time in seconds to wait for the database
144      * operation used to validate the connection to complete. If the
145      * timeout period expires before the operation completes, this
146      * method returns false. A value of 0 indicates a timeout is not
147      * applied to the database operation.
148      * @return true if the connection is valid, false otherwise
149      * @throws SQLException if the call on the physical connection throws an
150      * exception.
151      */

152     public final boolean isValid(int timeout) throws SQLException JavaDoc{
153         // Check first if the Brokered connection is closed
154
if (isClosed()) {
155             return false;
156         }
157
158         // Forward the isValid call to the physical connection
159
try {
160             return getRealConnection().isValid(timeout);
161         } catch (SQLException JavaDoc sqle) {
162             notifyException(sqle);
163             throw sqle;
164         }
165     }
166     
167     
168     /**
169      * <code>setClientInfo</code> forwards to the real connection.
170      *
171      * @param name the property key <code>String</code>
172      * @param value the property value <code>String</code>
173      * @exception SQLClientInfoException if the property is not
174      * supported or the real connection could not be obtained.
175      */

176     public void setClientInfo(String JavaDoc name, String JavaDoc value)
177     throws SQLClientInfoException JavaDoc{
178         try {
179             getRealConnection().setClientInfo(name, value);
180         } catch (SQLClientInfoException JavaDoc se) {
181             notifyException(se);
182             throw se;
183         }
184         catch (SQLException JavaDoc se) {
185             throw new SQLClientInfoException JavaDoc
186                 (se.getMessage(), se.getSQLState(),
187          (new FailedProperties40
188           (FailedProperties40.makeProperties(name,value))).
189          getProperties());
190         }
191     }
192
193     /**
194      * <code>setClientInfo</code> forwards to the real connection. If
195      * the call to <code>getRealConnection</code> fails the resulting
196      * <code>SQLException</code> is wrapped in a
197      * <code>SQLClientInfoException</code> to satisfy the specified
198      * signature.
199      * @param properties a <code>Properties</code> object with the
200      * properties to set.
201      * @exception SQLClientInfoException if the properties are not
202      * supported or the real connection could not be obtained.
203      */

204     public void setClientInfo(Properties JavaDoc properties)
205     throws SQLClientInfoException JavaDoc{
206         try {
207             getRealConnection().setClientInfo(properties);
208         } catch (SQLClientInfoException JavaDoc cie) {
209             notifyException(cie);
210             throw cie;
211         }
212         catch (SQLException JavaDoc se) {
213             throw new SQLClientInfoException JavaDoc
214                 (se.getMessage(), se.getSQLState(),
215          (new FailedProperties40(properties)).getProperties());
216         }
217     }
218     
219     /**
220      * <code>getClientInfo</code> forwards to the real connection.
221      *
222      * @param name a <code>String</code> that is the property key to get.
223      * @return a <code>String</code> that is returned from the real connection.
224      * @exception SQLException if a database access error occurs.
225      */

226     public String JavaDoc getClientInfo(String JavaDoc name)
227     throws SQLException JavaDoc{
228         try {
229             return getRealConnection().getClientInfo(name);
230         } catch (SQLException JavaDoc se) {
231             notifyException(se);
232             throw se;
233         }
234     }
235     
236     /**
237      * <code>getClientInfo</code> forwards to the real connection.
238      *
239      * @return a <code>Properties</code> object
240      * from the real connection.
241      * @exception SQLException if a database access error occurs.
242      */

243     public Properties JavaDoc getClientInfo()
244     throws SQLException JavaDoc{
245         try {
246             return getRealConnection().getClientInfo();
247         } catch (SQLException JavaDoc se) {
248             notifyException(se);
249             throw se;
250         }
251     }
252     
253     /**
254      * returns an instance of JDBC4.0 speccific class BrokeredStatement40
255      * @param statementControl BrokeredStatementControl
256      * @return an instance of BrokeredStatement40
257      * throws java.sql.SQLException
258      */

259     public final BrokeredStatement newBrokeredStatement
260             (BrokeredStatementControl statementControl) throws SQLException JavaDoc {
261         try {
262             return new BrokeredStatement40(statementControl, getJDBCLevel());
263         } catch (SQLException JavaDoc sqle) {
264             notifyException(sqle);
265             throw sqle;
266         }
267     }
268     public final BrokeredPreparedStatement newBrokeredStatement(BrokeredStatementControl statementControl, String JavaDoc sql, Object JavaDoc generatedKeys) throws SQLException JavaDoc {
269         try {
270             return new BrokeredPreparedStatement40(statementControl, getJDBCLevel(), sql, generatedKeys);
271         } catch (SQLException JavaDoc sqle) {
272             notifyException(sqle);
273             throw sqle;
274         }
275     }
276     public final BrokeredCallableStatement newBrokeredStatement(BrokeredStatementControl statementControl, String JavaDoc sql) throws SQLException JavaDoc {
277         try {
278             return new BrokeredCallableStatement40(statementControl, getJDBCLevel(), sql);
279         } catch (SQLException JavaDoc sqle) {
280             notifyException(sqle);
281             throw sqle;
282         }
283     }
284     
285     /**
286      * Returns the type map for this connection.
287      *
288      * @return type map for this connection
289      * @exception SQLException if a database access error occurs
290      */

291     public final java.util.Map JavaDoc<String JavaDoc,Class JavaDoc<?>> getTypeMap() throws SQLException JavaDoc {
292         try {
293             return getRealConnection().getTypeMap();
294         } catch (SQLException JavaDoc se) {
295             notifyException(se);
296             throw se;
297         }
298     }
299     
300     final int getJDBCLevel() { return 4;}
301     
302     /**
303      * Returns false unless <code>interfaces</code> is implemented
304      *
305      * @param interfaces a Class defining an interface.
306      * @return true if this implements the interface or
307      * directly or indirectly wraps an object
308      * that does.
309      * @throws java.sql.SQLException if an error occurs while determining
310      * whether this is a wrapper for an object
311      * with the given interface.
312      */

313     public final boolean isWrapperFor(Class JavaDoc<?> interfaces) throws SQLException JavaDoc {
314         checkIfClosed();
315         return interfaces.isInstance(this);
316     }
317     
318     /**
319      * Returns <code>this</code> if this class implements the interface
320      *
321      * @param interfaces a Class defining an interface
322      * @return an object that implements the interface
323      * @throws java.sql.SQLExption if no object if found that implements the
324      * interface
325      */

326     public final <T> T unwrap(java.lang.Class JavaDoc<T> interfaces)
327                             throws SQLException JavaDoc{
328         checkIfClosed();
329         //Derby does not implement non-standard methods on
330
//JDBC objects
331
try {
332             return interfaces.cast(this);
333         } catch (ClassCastException JavaDoc cce) {
334             throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP,
335                     interfaces);
336         }
337     }
338 }
339
Popular Tags