KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > repository > JdbcConnectionPool


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.repository;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import com.sun.enterprise.util.Utility;
29
30 /**
31  * Resource info for Jdbc Connection Pool.
32  * IASRI #4626188
33  * @author Sridatta Viswanath
34  */

35 public class JdbcConnectionPool extends J2EEResourceBase implements Serializable JavaDoc {
36     
37     private String JavaDoc userName_;
38     private String JavaDoc password_;
39
40     private String JavaDoc datasourceClassname_;
41     private String JavaDoc steadyPoolSize_;
42     private String JavaDoc maxPoolSize_;
43     private String JavaDoc maxWaitTimeInMillis_;
44     // start IASRI 4667083
45
// adding poolResizeQuantity
46
private String JavaDoc poolResizeQuantity_;
47     // end IASRI 4667083
48
private String JavaDoc idleTimeoutInSeconds_;
49     private boolean isConnectionValidationRequired_;
50     private String JavaDoc connectionValidationMethod_;
51     private String JavaDoc validationTableName_;
52     private boolean failAllConnections_;
53
54     // start IASRI 4691114
55
private boolean perfMonitor = false;
56     //end IASRI 4691114
57

58     // start IASRI 6487826
59
// adding resType, transactionIsolationLevel, and isIsolationLevelGuaranteed
60
private String JavaDoc resType_;
61     private String JavaDoc transactionIsolationLevel_;
62     private boolean isIsolationLevelGuaranteed_;
63     // end IASRI 6487826
64

65     // start IASRI 4659935
66
private transient Object JavaDoc cachedVendorDataSource = null;
67     // end IASRI 4659935
68

69     public JdbcConnectionPool(String JavaDoc name) {
70         super(name);
71     }
72     
73     protected J2EEResource doClone(String JavaDoc name) {
74         JdbcConnectionPool clone = new JdbcConnectionPool(name);
75
76         clone.setUserName(getUserName());
77         clone.setPassword(getPassword());
78
79         clone.setDatasourceClassname(getDatasourceClassname());
80         clone.setMaxPoolSize(getMaxPoolSize());
81         clone.setMaxWaitTimeInMillis(getMaxWaitTimeInMillis());
82         clone.setPoolResizeQuantity(getPoolResizeQuantity());
83         clone.setIdleTimeoutInSeconds(getIdleTimeoutInSeconds());
84         clone.setIsConnectionValidationRequired(isIsConnectionValidationRequired());
85         clone.setConnectionValidationMethod(getConnectionValidationMethod());
86         clone.setValidationTableName(getValidationTableName());
87         clone.setFailAllConnections(isFailAllConnections());
88
89     // start IASRI 6487826
90
clone.setResType(getResType());
91         clone.setTransactionIsolationLevel(getTransactionIsolationLevel());
92         clone.setIsIsolationLevelGuaranteed(isIsolationLevelGuaranteed());
93     // end IASRI 6487826
94

95         return clone;
96     }
97     
98     public int getType() {
99         return J2EEResource.JDBC_CONNECTION_POOL;
100     }
101    
102     public String JavaDoc getUserName() {
103         return userName_;
104     }
105     
106     public void setUserName(String JavaDoc userName) {
107         userName_ = userName;
108     }
109     
110     public String JavaDoc getPassword() {
111         return password_;
112     }
113     
114     public void setPassword(String JavaDoc password) {
115         password_ = password;
116     }
117
118     public String JavaDoc getDatasourceClassname() {
119         return datasourceClassname_;
120     }
121     
122     public void setDatasourceClassname(String JavaDoc datasourceClassname) {
123         datasourceClassname_ = datasourceClassname;
124     }
125      
126     public String JavaDoc getSteadyPoolSize() {
127         return steadyPoolSize_;
128     }
129     
130     public void setSteadyPoolSize(String JavaDoc steadyPoolSize) {
131         steadyPoolSize_ = steadyPoolSize;
132     }
133
134     public String JavaDoc getMaxPoolSize() {
135         return maxPoolSize_;
136     }
137
138     public void setMaxPoolSize(String JavaDoc maxPoolSize) {
139         maxPoolSize_ = maxPoolSize;
140     }
141
142     public String JavaDoc getMaxWaitTimeInMillis() {
143         return maxWaitTimeInMillis_;
144     }
145     
146     public void setMaxWaitTimeInMillis(String JavaDoc maxWaitTimeInMillis) {
147         maxWaitTimeInMillis_ = maxWaitTimeInMillis;
148     }
149
150     // start IASRI 4667083
151
// adding poolResizeQuantity
152

153     public String JavaDoc getPoolResizeQuantity() {
154         return poolResizeQuantity_;
155     }
156     
157     public void setPoolResizeQuantity(String JavaDoc poolResizeQuantity) {
158         poolResizeQuantity_ = poolResizeQuantity;
159     }
160
161     // end IASRI 4667083
162

163     public String JavaDoc getIdleTimeoutInSeconds() {
164         return idleTimeoutInSeconds_;
165     }
166     
167     public void setIdleTimeoutInSeconds(String JavaDoc idleTimeoutInSeconds) {
168         idleTimeoutInSeconds_ = idleTimeoutInSeconds;
169     }
170     public boolean isIsConnectionValidationRequired() {
171         return isConnectionValidationRequired_;
172     }
173     
174     public void setIsConnectionValidationRequired(boolean isConnectionValidationRequired) {
175         isConnectionValidationRequired_ = isConnectionValidationRequired;
176     }
177     public String JavaDoc getConnectionValidationMethod() {
178         return connectionValidationMethod_;
179     }
180     
181     public void setConnectionValidationMethod(String JavaDoc connectionValidationMethod) {
182         connectionValidationMethod_ = connectionValidationMethod;
183     }
184     public String JavaDoc getValidationTableName() {
185         return validationTableName_;
186     }
187     
188     public void setValidationTableName(String JavaDoc validationTableName) {
189         validationTableName_ = validationTableName;
190     }
191     public boolean isFailAllConnections() {
192         return failAllConnections_;
193     }
194     
195     public void setFailAllConnections(boolean failAllConnections) {
196         failAllConnections_ = failAllConnections;
197     }
198     
199     // start IASRI 6487826
200

201     public String JavaDoc getResType() {
202         return resType_;
203     }
204     
205     public void setResType(String JavaDoc resType) {
206         resType_ = resType;
207     }
208
209     public String JavaDoc getTransactionIsolationLevel() {
210         return transactionIsolationLevel_;
211     }
212     
213     public void setTransactionIsolationLevel(String JavaDoc transactionIsolationLevel) {
214         transactionIsolationLevel_ = transactionIsolationLevel;
215     }
216
217     public boolean isIsolationLevelGuaranteed() {
218         return isIsolationLevelGuaranteed_;
219     }
220     
221     public void setIsIsolationLevelGuaranteed(boolean isIsolationLevelGuaranteed) {
222         isIsolationLevelGuaranteed_ = isIsolationLevelGuaranteed;
223     }
224     // end IASRI 6487826
225

226     public String JavaDoc toString() {
227         return "< JDBC Connection Pool : " + getName() + "... >";
228     }
229
230     // start IASRI 4659935
231

232     /**
233      * creates the Vendor DataSource associated with this pool
234      *
235      * @return vendor data source
236      */

237     public Object JavaDoc createDataSource() throws J2EEResourceException {
238     // We can synchronize on this w/o concern about performance
239
// because this is only called once per creation of a connection
240
synchronized(this) {
241         if (cachedVendorDataSource == null) {
242         try {
243             // start IASRI 4669877
244
// mods:
245
// - use the common class loader instead of system class loader
246
Class JavaDoc dataSourceClass = Utility.loadClass(getDatasourceClassname());
247             // end IASRI 4669877
248
cachedVendorDataSource = dataSourceClass.newInstance();
249             ResourceProperty next;
250             for(Iterator JavaDoc iter = getProperties().iterator(); iter.hasNext(); ) {
251             next = (ResourceProperty) iter.next();
252             Utility.invokeSetMethodCaseInsensitive(cachedVendorDataSource, next.getName(),
253                         next.getValue().toString());
254             }
255         } catch(Exception JavaDoc e) {
256             e.printStackTrace();
257             throw new J2EEResourceException(e);
258         }
259         }
260     }
261         return cachedVendorDataSource;
262     }
263
264     // end IASRI 4659935
265

266     /**
267      * Returns true if res-type is javax.sql.XADataSource and the data source class name
268      * implements javax.sql.XADataSource; else false.
269      *
270      * @return true if data source class name is XA
271      */

272     public boolean isXA() {
273
274         boolean tf = false;
275
276     // first check the res-type
277
if (this.resType_ == null) {
278         // default to non-xa
279
return false;
280     }
281
282         if (this.resType_.equals("javax.sql.XADataSource")
283             && this.datasourceClassname_ != null) {
284
285             try {
286                 // if data source class implements javax.sql.XADataSource
287
// interface this pool supports global transactions
288
// start IASRI 4713958
289
// use common classloader
290
// Class dsClass = Class.forName(this.datasourceClassname_);
291
Class JavaDoc dsClass = Utility.loadClass(getDatasourceClassname());
292                 // end IASRI 4713958
293
if (javax.sql.XADataSource JavaDoc.class.isAssignableFrom(dsClass)) {
294                     tf = true;
295                 }
296             } catch (ClassNotFoundException JavaDoc e) {
297                 // ignore; return false
298
}
299         }
300
301     return tf;
302     }
303
304     /**
305      * Returns true if res-type is javax.sql.ConnectionPoolDataSource
306      * and the data * source class name implements
307      * javax.sql.ConnectionPoolDataSource; else false.
308      *
309      * @return true if data source is ConnectionPoolDataSource
310      */

311     public boolean isCP() {
312
313         boolean tf = false;
314     // first check the res-type
315
if (this.resType_ == null) {
316         // default to non-cp
317
return false;
318     }
319
320         if (this.resType_.equals("javax.sql.ConnectionPoolDataSource")
321             && this.datasourceClassname_ != null) {
322
323             try {
324                 // if data source class implements javax.sql.ConnectionPoolDataSource
325
// use common classloader
326
// Class dsClass = Class.forName(this.datasourceClassname_);
327
Class JavaDoc dsClass = Utility.loadClass(getDatasourceClassname());
328                 // end IASRI 4713958
329
if (javax.sql.ConnectionPoolDataSource JavaDoc.class.isAssignableFrom(dsClass)) {
330                     tf = true;
331                 }
332             } catch (ClassNotFoundException JavaDoc e) {
333                 // ignore; return false
334
}
335         }
336
337     return tf;
338     }
339
340     /**
341      * This method overides super's to intercept and capture relevant properties.
342      */

343     public void addProperty(ResourceProperty property) {
344     //don't need to check for null here.
345

346     String JavaDoc propName = property.getName();
347
348     if (propName.equalsIgnoreCase("user")) {
349         setUserName((String JavaDoc)property.getValue());
350     } else if (propName.equalsIgnoreCase("password")) {
351         setPassword((String JavaDoc)property.getValue());
352     }
353
354     // start HACK for bug4695569
355
if (propName.equalsIgnoreCase("xa-driver-does-not-support-non-tx-operations")) {
356         if (((String JavaDoc)property.getValue()).equalsIgnoreCase("true")) {
357         this.noNonTxOps = true;
358         }
359         return;
360     }
361     // end HACK for bug4695569
362
// start IASRI 4691114
363
// check if this pool has enable internal performance monitoring
364
if (propName.equalsIgnoreCase("perf-monitor")) {
365         if (((String JavaDoc)property.getValue()).equalsIgnoreCase("true")) {
366         this.perfMonitor = true;
367         }
368         return;
369     }
370         // end IASRI 4691114
371

372
373     super.addProperty(property);
374     }
375
376     // start IASRI 4691114
377
// check if this pool has enable internal performance monitoring
378
public boolean isPerfMonitor() {
379         return perfMonitor;
380     }
381     //end IASRI 4691114
382

383     // start HACK for bug4695569
384
private boolean noNonTxOps = false;
385
386     public boolean getNoNonTxOps() {
387     return noNonTxOps;
388     }
389     // end HACK for bug4695569
390
}
391
Popular Tags