KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.client.am.LogicalConnection40
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.client.am;
23
24 import java.sql.Array JavaDoc;
25 import java.sql.Blob JavaDoc;
26 import java.sql.SQLClientInfoException JavaDoc;
27 import java.sql.Clob JavaDoc;
28 import java.sql.NClob JavaDoc;
29 import java.sql.SQLXML JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.Struct JavaDoc;
32 import java.sql.Wrapper JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 import org.apache.derby.client.ClientPooledConnection;
36 import org.apache.derby.shared.common.reference.SQLState;
37 import java.util.Map JavaDoc;
38
39 /**
40  * A simple delegation wrapper handle for a physical connection.
41  * This class only contains JDBC 4.0 specific methods.
42  *
43  * NOTE: All non-implemented JDBC 4.0 methods are located here, but when they
44  * are implemented, they should be moved to the superclass if possible.
45  */

46 public class LogicalConnection40
47     extends LogicalConnection {
48
49     public LogicalConnection40(Connection physicalConnection,
50                                ClientPooledConnection pooledConnection)
51         throws SqlException {
52         super(physicalConnection, pooledConnection);
53     }
54
55     public Array JavaDoc createArrayOf(String JavaDoc typeName, Object JavaDoc[] elements)
56         throws SQLException JavaDoc {
57         checkForNullPhysicalConnection();
58         return physicalConnection_.createArrayOf( typeName, elements );
59     }
60     
61     public Blob createBlob()
62         throws SQLException JavaDoc {
63         checkForNullPhysicalConnection();
64         return physicalConnection_.createBlob();
65     }
66
67     public Clob createClob()
68         throws SQLException JavaDoc {
69         checkForNullPhysicalConnection();
70         return physicalConnection_.createClob();
71     }
72     
73     public NClob JavaDoc createNClob()
74         throws SQLException JavaDoc {
75         checkForNullPhysicalConnection();
76         return physicalConnection_.createNClob();
77     }
78
79     public SQLXML JavaDoc createSQLXML()
80         throws SQLException JavaDoc {
81         checkForNullPhysicalConnection();
82         return physicalConnection_.createSQLXML();
83     }
84
85     public Struct JavaDoc createStruct(String JavaDoc typeName, Object JavaDoc[] attributes)
86         throws SQLException JavaDoc {
87         checkForNullPhysicalConnection();
88         return physicalConnection_.createStruct( typeName, attributes );
89     }
90
91     /**
92      * <code>getClientInfo</code> forwards to
93      * <code>physicalConnection_</code>.
94      * <code>getClientInfo</code> always returns an empty
95      * <code>Properties</code> object since Derby doesn't support
96      * ClientInfoProperties.
97      *
98      * @return an empty <code>Properties</code> object
99      * @exception SQLException if an error occurs
100      */

101     public Properties JavaDoc getClientInfo()
102         throws SQLException JavaDoc {
103     checkForNullPhysicalConnection();
104     return physicalConnection_.getClientInfo();
105     }
106     
107     /**
108      * <code>getClientInfo</code> forwards to
109      * <code>physicalConnection_</code>. Always returns a <code>null
110      * String</code> since Derby does not support
111      * ClientInfoProperties.
112      *
113      * @param name a property key to get <code>String</code>
114      * @return a property value <code>String</code>
115      * @exception SQLException if an error occurs
116      */

117     public String JavaDoc getClientInfo(String JavaDoc name)
118         throws SQLException JavaDoc {
119     checkForNullPhysicalConnection();
120     return physicalConnection_.getClientInfo(name);
121     }
122
123     /**
124      * Returns the type map for this connection.
125      *
126      * @return type map for this connection
127      * @exception SQLException if a database access error occurs
128      */

129     public Map JavaDoc<String JavaDoc, Class JavaDoc<?>> getTypeMap() throws SQLException JavaDoc {
130         checkForNullPhysicalConnection();
131         return ((java.sql.Connection JavaDoc) physicalConnection_).getTypeMap();
132     }
133
134     /**
135      * Checks if the connection has not been closed and is still valid.
136      * The validity is checked by running a simple query against the
137      * database.
138      *
139      * @param timeout The time in seconds to wait for the database
140      * operation used to validate the connection to complete. If the
141      * timeout period expires before the operation completes, this
142      * method returns false. A value of 0 indicates a timeout is not
143      * applied to the database operation.
144      * @return true if the connection is valid, false otherwise
145      * @throws SQLException if the call on the physical connection throws an
146      * exception.
147      */

148     synchronized public boolean isValid(int timeout) throws SQLException JavaDoc {
149         // Check if we have a underlying physical connection
150
if (physicalConnection_ == null) {
151             return false;
152         }
153         return physicalConnection_.isValid(timeout);
154     }
155    
156
157     public boolean isWrapperFor(Class JavaDoc<?> interfaces)
158         throws SQLException JavaDoc {
159         checkForNullPhysicalConnection();
160         return interfaces.isInstance(this);
161     }
162
163     /**
164      * <code>setClientInfo</code> forwards to
165      * <code>physicalConnection_</code>.
166      *
167      * @param properties a <code>Properties</code> object with the
168      * properties to set
169      * @exception SQLClientInfoException if an error occurs
170      */

171     public void setClientInfo(Properties JavaDoc properties)
172         throws SQLClientInfoException JavaDoc {
173     try { checkForNullPhysicalConnection(); }
174     catch (SQLException JavaDoc se) {
175         throw new SQLClientInfoException JavaDoc
176         (se.getMessage(), se.getSQLState(),
177          (new FailedProperties40(properties)).getProperties());
178     }
179     physicalConnection_.setClientInfo(properties);
180     }
181     
182     /**
183      * <code>setClientInfo</code> forwards to
184      * <code>physicalConnection_</code>.
185      *
186      * @param name a property key <code>String</code>
187      * @param value a property value <code>String</code>
188      * @exception SQLException if an error occurs
189      */

190     public void setClientInfo(String JavaDoc name, String JavaDoc value)
191         throws SQLClientInfoException JavaDoc {
192     try { checkForNullPhysicalConnection(); }
193         catch (SQLException JavaDoc se) {
194             throw new SQLClientInfoException JavaDoc
195                 (se.getMessage(), se.getSQLState(),
196                  new FailedProperties40
197                  (FailedProperties40.makeProperties
198                   (name,value)).getProperties());
199         }
200     physicalConnection_.setClientInfo(name, value);
201     }
202     
203     public <T>T unwrap(Class JavaDoc<T> interfaces)
204         throws SQLException JavaDoc {
205         checkForNullPhysicalConnection();
206         // Derby does not implement non-standard methods on JDBC objects
207
try {
208             return interfaces.cast(this);
209         } catch (ClassCastException JavaDoc cce) {
210             throw new SqlException(null,
211                                    new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
212                                    interfaces).getSQLException();
213         }
214     }
215     
216 } // End class LogicalConnection40
217
Popular Tags