001: /*
002:
003: Derby - Class org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource40
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: package org.apache.derby.jdbc;
022:
023: import java.sql.SQLException;
024: import javax.sql.ConnectionPoolDataSource;
025: import javax.sql.DataSource;
026: import javax.sql.PooledConnection;
027:
028: import org.apache.derby.impl.jdbc.Util;
029: import org.apache.derby.iapi.reference.SQLState;
030:
031: /**
032: EmbeddedConnectionPoolDataSource40 is Derby's ConnectionPoolDataSource
033: implementation for the JDBC4.0 environment.
034:
035:
036: <P>A ConnectionPoolDataSource is a factory for PooledConnection
037: objects. An object that implements this interface will typically be
038: registered with a JNDI service.
039: <P>
040: EmbeddedConnectionPoolDataSource40 supports the JDBC 4.0 specification
041: for the J2SE 6.0 Java Virtual Machine environment. Use
042: EmbeddedConnectionPoolDataSource if your application runs in the
043: following environments:
044: <UL>
045: <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
046: <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
047: </UL>
048:
049: <P>EmbeddedConnectionPoolDataSource40 is serializable and referenceable.
050:
051: <P>See EmbeddedDataSource40 for DataSource properties.
052:
053: */
054: public class EmbeddedConnectionPoolDataSource40 extends
055: EmbeddedConnectionPoolDataSource implements
056: ConnectionPoolDataSource {
057:
058: /**
059: * Returns false unless <code>interfaces</code> is implemented
060: *
061: * @param interfaces a Class defining an interface.
062: * @return true if this implements the interface or
063: * directly or indirectly wraps an object
064: * that does.
065: * @throws java.sql.SQLException if an error occurs while determining
066: * whether this is a wrapper for an object
067: * with the given interface.
068: */
069: public boolean isWrapperFor(Class<?> interfaces)
070: throws SQLException {
071: return interfaces.isInstance(this );
072: }
073:
074: /**
075: * Returns <code>this</code> if this class implements the interface
076: *
077: * @param interfaces a Class defining an interface
078: * @return an object that implements the interface
079: * @throws java.sql.SQLExption if no object if found that implements the
080: * interface
081: */
082: public <T> T unwrap(java.lang.Class<T> interfaces)
083: throws SQLException {
084: //Derby does not implement non-standard methods on
085: //JDBC objects
086: //hence return this if this class implements the interface
087: //or throw an SQLException
088: try {
089: return interfaces.cast(this );
090: } catch (ClassCastException cce) {
091: throw Util.generateCsSQLException(
092: SQLState.UNABLE_TO_UNWRAP, interfaces);
093: }
094: }
095:
096: /**
097: * create and returns EmbedPooledConnection.
098: */
099: protected PooledConnection createPooledConnection(String user,
100: String password, boolean requestPassword)
101: throws SQLException {
102: return new EmbedPooledConnection40(this, user, password,
103: requestPassword);
104: }
105:
106: }
|