001: /*
002:
003: Derby - Class org.apache.derby.client.am.LogicalConnection40
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: import java.sql.Array;
025: import java.sql.Blob;
026: import java.sql.SQLClientInfoException;
027: import java.sql.Clob;
028: import java.sql.NClob;
029: import java.sql.SQLXML;
030: import java.sql.SQLException;
031: import java.sql.Struct;
032: import java.sql.Wrapper;
033: import java.util.Properties;
034:
035: import org.apache.derby.client.ClientPooledConnection;
036: import org.apache.derby.shared.common.reference.SQLState;
037: import java.util.Map;
038:
039: /**
040: * A simple delegation wrapper handle for a physical connection.
041: * This class only contains JDBC 4.0 specific methods.
042: *
043: * NOTE: All non-implemented JDBC 4.0 methods are located here, but when they
044: * are implemented, they should be moved to the superclass if possible.
045: */
046: public class LogicalConnection40 extends LogicalConnection {
047:
048: public LogicalConnection40(Connection physicalConnection,
049: ClientPooledConnection pooledConnection)
050: throws SqlException {
051: super (physicalConnection, pooledConnection);
052: }
053:
054: public Array createArrayOf(String typeName, Object[] elements)
055: throws SQLException {
056: checkForNullPhysicalConnection();
057: return physicalConnection_.createArrayOf(typeName, elements);
058: }
059:
060: public Blob createBlob() throws SQLException {
061: checkForNullPhysicalConnection();
062: return physicalConnection_.createBlob();
063: }
064:
065: public Clob createClob() throws SQLException {
066: checkForNullPhysicalConnection();
067: return physicalConnection_.createClob();
068: }
069:
070: public NClob createNClob() throws SQLException {
071: checkForNullPhysicalConnection();
072: return physicalConnection_.createNClob();
073: }
074:
075: public SQLXML createSQLXML() throws SQLException {
076: checkForNullPhysicalConnection();
077: return physicalConnection_.createSQLXML();
078: }
079:
080: public Struct createStruct(String typeName, Object[] attributes)
081: throws SQLException {
082: checkForNullPhysicalConnection();
083: return physicalConnection_.createStruct(typeName, attributes);
084: }
085:
086: /**
087: * <code>getClientInfo</code> forwards to
088: * <code>physicalConnection_</code>.
089: * <code>getClientInfo</code> always returns an empty
090: * <code>Properties</code> object since Derby doesn't support
091: * ClientInfoProperties.
092: *
093: * @return an empty <code>Properties</code> object
094: * @exception SQLException if an error occurs
095: */
096: public Properties getClientInfo() throws SQLException {
097: checkForNullPhysicalConnection();
098: return physicalConnection_.getClientInfo();
099: }
100:
101: /**
102: * <code>getClientInfo</code> forwards to
103: * <code>physicalConnection_</code>. Always returns a <code>null
104: * String</code> since Derby does not support
105: * ClientInfoProperties.
106: *
107: * @param name a property key to get <code>String</code>
108: * @return a property value <code>String</code>
109: * @exception SQLException if an error occurs
110: */
111: public String getClientInfo(String name) throws SQLException {
112: checkForNullPhysicalConnection();
113: return physicalConnection_.getClientInfo(name);
114: }
115:
116: /**
117: * Returns the type map for this connection.
118: *
119: * @return type map for this connection
120: * @exception SQLException if a database access error occurs
121: */
122: public Map<String, Class<?>> getTypeMap() throws SQLException {
123: checkForNullPhysicalConnection();
124: return ((java.sql.Connection) physicalConnection_).getTypeMap();
125: }
126:
127: /**
128: * Checks if the connection has not been closed and is still valid.
129: * The validity is checked by running a simple query against the
130: * database.
131: *
132: * @param timeout The time in seconds to wait for the database
133: * operation used to validate the connection to complete. If the
134: * timeout period expires before the operation completes, this
135: * method returns false. A value of 0 indicates a timeout is not
136: * applied to the database operation.
137: * @return true if the connection is valid, false otherwise
138: * @throws SQLException if the call on the physical connection throws an
139: * exception.
140: */
141: synchronized public boolean isValid(int timeout)
142: throws SQLException {
143: // Check if we have a underlying physical connection
144: if (physicalConnection_ == null) {
145: return false;
146: }
147: return physicalConnection_.isValid(timeout);
148: }
149:
150: public boolean isWrapperFor(Class<?> interfaces)
151: throws SQLException {
152: checkForNullPhysicalConnection();
153: return interfaces.isInstance(this );
154: }
155:
156: /**
157: * <code>setClientInfo</code> forwards to
158: * <code>physicalConnection_</code>.
159: *
160: * @param properties a <code>Properties</code> object with the
161: * properties to set
162: * @exception SQLClientInfoException if an error occurs
163: */
164: public void setClientInfo(Properties properties)
165: throws SQLClientInfoException {
166: try {
167: checkForNullPhysicalConnection();
168: } catch (SQLException se) {
169: throw new SQLClientInfoException(se.getMessage(), se
170: .getSQLState(),
171: (new FailedProperties40(properties))
172: .getProperties());
173: }
174: physicalConnection_.setClientInfo(properties);
175: }
176:
177: /**
178: * <code>setClientInfo</code> forwards to
179: * <code>physicalConnection_</code>.
180: *
181: * @param name a property key <code>String</code>
182: * @param value a property value <code>String</code>
183: * @exception SQLException if an error occurs
184: */
185: public void setClientInfo(String name, String value)
186: throws SQLClientInfoException {
187: try {
188: checkForNullPhysicalConnection();
189: } catch (SQLException se) {
190: throw new SQLClientInfoException(se.getMessage(), se
191: .getSQLState(), new FailedProperties40(
192: FailedProperties40.makeProperties(name, value))
193: .getProperties());
194: }
195: physicalConnection_.setClientInfo(name, value);
196: }
197:
198: public <T> T unwrap(Class<T> interfaces) throws SQLException {
199: checkForNullPhysicalConnection();
200: // Derby does not implement non-standard methods on JDBC objects
201: try {
202: return interfaces.cast(this );
203: } catch (ClassCastException cce) {
204: throw new SqlException(null, new ClientMessageId(
205: SQLState.UNABLE_TO_UNWRAP), interfaces)
206: .getSQLException();
207: }
208: }
209:
210: } // End class LogicalConnection40
|