KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > jdbc > ClientConnectionPoolDataSource


1 /*
2
3    Derby - Class org.apache.derby.jdbc.ClientConnectionPoolDataSource
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.jdbc;
23
24 import java.sql.SQLException JavaDoc;
25 import javax.sql.ConnectionPoolDataSource JavaDoc;
26 import javax.sql.DataSource JavaDoc;
27 import javax.sql.PooledConnection JavaDoc;
28 import org.apache.derby.client.am.LogWriter;
29 import org.apache.derby.client.am.SqlException;
30
31 /**
32  * ClientConnectionPoolDataSource is a factory for PooledConnection objects.
33  * An object that implements this interface
34  * will typically be registered with a naming service that is based on the
35  * Java Naming and Directory Interface (JNDI). Use
36  * ClientConnectionPoolDataSource if your application runs under
37  * JDBC3.0 or JDBC2.0, that is, on the following Java Virtual Machines:
38  * <p/>
39  * <UL>
40  * <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
41  * <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
42  * </UL>
43  */

44 public class ClientConnectionPoolDataSource extends ClientDataSource
45                                            implements ConnectionPoolDataSource JavaDoc {
46     private static final long serialVersionUID = -539234282156481377L;
47     public static final String JavaDoc className__ = "org.apache.derby.jdbc.ClientConnectionPoolDataSource";
48
49     public ClientConnectionPoolDataSource() {
50         super();
51     }
52
53     // ---------------------------interface methods-------------------------------
54

55     // Attempt to establish a physical database connection that can be used as a pooled connection.
56
public PooledConnection JavaDoc getPooledConnection() throws SQLException JavaDoc {
57         try
58         {
59             LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
60             if (dncLogWriter != null) {
61                 dncLogWriter.traceEntry(this, "getPooledConnection");
62             }
63             PooledConnection JavaDoc pooledConnection = getPooledConnectionX(dncLogWriter, this, getUser(), getPassword());
64             if (dncLogWriter != null) {
65                 dncLogWriter.traceExit(this, "getPooledConnection", pooledConnection);
66             }
67             return pooledConnection;
68         }
69         catch ( SqlException se )
70         {
71             throw se.getSQLException();
72         }
73     }
74
75     // Standard method that establishes the initial physical connection using CPDS properties.
76
public PooledConnection JavaDoc getPooledConnection(String JavaDoc user, String JavaDoc password) throws SQLException JavaDoc {
77         try
78         {
79             LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
80             if (dncLogWriter != null) {
81                 dncLogWriter.traceEntry(this, "getPooledConnection", user, "<escaped>");
82             }
83             PooledConnection JavaDoc pooledConnection = getPooledConnectionX(dncLogWriter, this, user, password);
84             if (dncLogWriter != null) {
85                 dncLogWriter.traceExit(this, "getPooledConnection", pooledConnection);
86             }
87             return pooledConnection;
88         }
89         catch ( SqlException se )
90         {
91             throw se.getSQLException();
92         }
93     }
94
95     // method that establishes the initial physical connection
96
// using DS properties instead of CPDS properties.
97
private PooledConnection JavaDoc getPooledConnectionX(LogWriter dncLogWriter,
98                         ClientBaseDataSource ds, String JavaDoc user,
99                         String JavaDoc password) throws SQLException JavaDoc {
100             return ClientDriver.getFactory().newClientPooledConnection(ds,
101                     dncLogWriter, user, password);
102     }
103 }
104
Popular Tags