001: /*
002:
003: Derby - Class org.apache.derby.jdbc.ClientConnectionPoolDataSource
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.jdbc;
023:
024: import java.sql.SQLException;
025: import javax.sql.ConnectionPoolDataSource;
026: import javax.sql.DataSource;
027: import javax.sql.PooledConnection;
028: import org.apache.derby.client.am.LogWriter;
029: import org.apache.derby.client.am.SqlException;
030:
031: /**
032: * ClientConnectionPoolDataSource is a factory for PooledConnection objects.
033: * An object that implements this interface
034: * will typically be registered with a naming service that is based on the
035: * Java Naming and Directory Interface (JNDI). Use
036: * ClientConnectionPoolDataSource if your application runs under
037: * JDBC3.0 or JDBC2.0, that is, on the following Java Virtual Machines:
038: * <p/>
039: * <UL>
040: * <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
041: * <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
042: * </UL>
043: */
044: public class ClientConnectionPoolDataSource extends ClientDataSource
045: implements ConnectionPoolDataSource {
046: private static final long serialVersionUID = -539234282156481377L;
047: public static final String className__ = "org.apache.derby.jdbc.ClientConnectionPoolDataSource";
048:
049: public ClientConnectionPoolDataSource() {
050: super ();
051: }
052:
053: // ---------------------------interface methods-------------------------------
054:
055: // Attempt to establish a physical database connection that can be used as a pooled connection.
056: public PooledConnection getPooledConnection() throws SQLException {
057: try {
058: LogWriter dncLogWriter = super
059: .computeDncLogWriterForNewConnection("_cpds");
060: if (dncLogWriter != null) {
061: dncLogWriter.traceEntry(this , "getPooledConnection");
062: }
063: PooledConnection pooledConnection = getPooledConnectionX(
064: dncLogWriter, this , getUser(), getPassword());
065: if (dncLogWriter != null) {
066: dncLogWriter.traceExit(this , "getPooledConnection",
067: pooledConnection);
068: }
069: return pooledConnection;
070: } catch (SqlException se) {
071: throw se.getSQLException();
072: }
073: }
074:
075: // Standard method that establishes the initial physical connection using CPDS properties.
076: public PooledConnection getPooledConnection(String user,
077: String password) throws SQLException {
078: try {
079: LogWriter dncLogWriter = super
080: .computeDncLogWriterForNewConnection("_cpds");
081: if (dncLogWriter != null) {
082: dncLogWriter.traceEntry(this , "getPooledConnection",
083: user, "<escaped>");
084: }
085: PooledConnection pooledConnection = getPooledConnectionX(
086: dncLogWriter, this , user, password);
087: if (dncLogWriter != null) {
088: dncLogWriter.traceExit(this , "getPooledConnection",
089: pooledConnection);
090: }
091: return pooledConnection;
092: } catch (SqlException se) {
093: throw se.getSQLException();
094: }
095: }
096:
097: // method that establishes the initial physical connection
098: // using DS properties instead of CPDS properties.
099: private PooledConnection getPooledConnectionX(
100: LogWriter dncLogWriter, ClientBaseDataSource ds,
101: String user, String password) throws SQLException {
102: return ClientDriver.getFactory().newClientPooledConnection(ds,
103: dncLogWriter, user, password);
104: }
105: }
|