KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > gjc > spi > CPManagedConnectionFactory


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
24 package com.sun.gjc.spi;
25
26 import javax.resource.ResourceException JavaDoc;
27 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
28 import com.sun.gjc.common.DataSourceSpec;
29 import com.sun.gjc.common.DataSourceObjectBuilder;
30 import com.sun.gjc.util.SecurityUtils;
31 import javax.resource.spi.security.PasswordCredential JavaDoc;
32 import javax.resource.spi.ResourceAllocationException JavaDoc;
33 import com.sun.logging.*;
34 import java.util.logging.Logger JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import com.sun.enterprise.util.i18n.StringManager;
37
38
39 /**
40  * Connection Pool <code>ManagedConnectionFactory</code> implementation for Generic JDBC Connector.
41  *
42  * @version 1.0, 02/07/30
43  * @author Evani Sai Surya Kiran
44  */

45
46 public class CPManagedConnectionFactory extends ManagedConnectionFactory {
47     
48     private transient javax.sql.ConnectionPoolDataSource JavaDoc cpDataSourceObj;
49
50     private static Logger JavaDoc _logger;
51     static {
52         _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
53     }
54
55     /**
56      * Creates a new physical connection to the underlying EIS resource
57      * manager.
58      *
59      * @param subject <code>Subject</code> instance passed by the application server
60      * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
61      * as a result of the invocation <code>getConnection(user, password)</code>
62      * on the <code>DataSource</code> object
63      * @return <code>ManagedConnection</code> object created
64      * @throws ResourceException if there is an error in instantiating the
65      * <code>DataSource</code> object used for the
66      * creation of the <code>ManagedConnection</code> object
67      * @throws SecurityException if there ino <code>PasswordCredential</code> object
68      * satisfying this request
69      * @throws ResourceAllocationException if there is an error in allocating the
70      * physical connection
71      */

72     public javax.resource.spi.ManagedConnection JavaDoc createManagedConnection(javax.security.auth.Subject JavaDoc subject,
73         ConnectionRequestInfo cxRequestInfo) throws ResourceException JavaDoc {
74         if(logWriter != null) {
75                 logWriter.println("In createManagedConnection");
76         }
77         PasswordCredential JavaDoc pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
78         
79         if(cpDataSourceObj == null) {
80             if(dsObjBuilder == null) {
81                 dsObjBuilder = new DataSourceObjectBuilder(spec);
82             }
83         
84             try {
85                 cpDataSourceObj = (javax.sql.ConnectionPoolDataSource JavaDoc) dsObjBuilder.constructDataSourceObject();
86             } catch(ClassCastException JavaDoc cce) {
87             _logger.log(Level.SEVERE, "jdbc.exc_create_ds",cce);
88                 throw new javax.resource.ResourceException JavaDoc(cce.getMessage(), cce);
89             }
90         }
91             
92         javax.sql.PooledConnection JavaDoc cpConn = null;
93         
94         try {
95         /* For the case where the user/passwd of the connection pool is
96          * equal to the PasswordCredential for the connection request
97          * get a connection from this pool directly.
98          * for all other conditions go create a new connection
99          */

100         if ( isEqual( pc, getUser(), getPassword() ) ) {
101             cpConn = cpDataSourceObj.getPooledConnection();
102         } else {
103             cpConn = cpDataSourceObj.getPooledConnection(pc.getUserName(),
104             new String JavaDoc(pc.getPassword()));
105         }
106
107         } catch(java.sql.SQLException JavaDoc sqle) {
108         //_logger.log(Level.SEVERE, "jdbc.exc_create_ds_conn",sqle);
109
_logger.log(Level.FINE, "jdbc.exc_create_ds_conn",sqle);
110             StringManager sm =
111                 StringManager.getManager( DataSourceObjectBuilder.class);
112         String JavaDoc msg = sm.getString( "jdbc.cannot_allocate_connection", sqle.getMessage() );
113         ResourceAllocationException JavaDoc rae = new ResourceAllocationException JavaDoc(
114             msg, sqle );
115         throw rae;
116         }
117         
118
119         com.sun.gjc.spi.ManagedConnection mc = constructManagedConnection(
120             cpConn, null, pc, this );
121
122     mc.initializeConnectionType( ManagedConnection.ISPOOLEDCONNECTION );
123
124         //GJCINT
125
validateAndSetIsolation( mc );
126         return mc;
127     }
128     
129     /**
130      * Check if this <code>ManagedConnectionFactory</code> is equal to
131      * another <code>ManagedConnectionFactory</code>.
132      *
133      * @param other <code>ManagedConnectionFactory</code> object for checking equality with
134      * @return true if the property sets of both the
135      * <code>ManagedConnectionFactory</code> objects are the same
136      * false otherwise
137      */

138     public boolean equals(Object JavaDoc other) {
139         if(logWriter != null) {
140                 logWriter.println("In equals");
141         }
142         /**
143          * The check below means that two ManagedConnectionFactory objects are equal
144          * if and only if their properties are the same.
145          */

146         if(other instanceof com.sun.gjc.spi.CPManagedConnectionFactory) {
147             com.sun.gjc.spi.CPManagedConnectionFactory otherMCF =
148                 (com.sun.gjc.spi.CPManagedConnectionFactory) other;
149             return this.spec.equals(otherMCF.spec);
150         }
151         return false;
152     }
153     
154     /**
155      * Sets the server name.
156      *
157      * @param serverName <code>String</code>
158      * @see <code>getServerName</code>
159      */

160     public void setserverName(String JavaDoc serverName) {
161         spec.setDetail(DataSourceSpec.SERVERNAME, serverName);
162     }
163     
164     /**
165      * Gets the server name.
166      *
167      * @return serverName
168      * @see <code>setServerName</code>
169      */

170     public String JavaDoc getserverName() {
171         return spec.getDetail(DataSourceSpec.SERVERNAME);
172     }
173     
174     /**
175      * Sets the server name.
176      *
177      * @param serverName <code>String</code>
178      * @see <code>getServerName</code>
179      */

180     public void setServerName(String JavaDoc serverName) {
181         spec.setDetail(DataSourceSpec.SERVERNAME, serverName);
182     }
183     
184     /**
185      * Gets the server name.
186      *
187      * @return serverName
188      * @see <code>setServerName</code>
189      */

190     public String JavaDoc getServerName() {
191         return spec.getDetail(DataSourceSpec.SERVERNAME);
192     }
193     
194     /**
195      * Sets the port number.
196      *
197      * @param portNumber <code>String</code>
198      * @see <code>getPortNumber</code>
199      */

200     public void setportNumber(String JavaDoc portNumber) {
201         spec.setDetail(DataSourceSpec.PORTNUMBER, portNumber);
202     }
203     
204     /**
205      * Gets the port number.
206      *
207      * @return portNumber
208      * @see <code>setPortNumber</code>
209      */

210     public String JavaDoc getportNumber() {
211         return spec.getDetail(DataSourceSpec.PORTNUMBER);
212     }
213     
214     /**
215      * Sets the port number.
216      *
217      * @param portNumber <code>String</code>
218      * @see <code>getPortNumber</code>
219      */

220     public void setPortNumber(String JavaDoc portNumber) {
221         spec.setDetail(DataSourceSpec.PORTNUMBER, portNumber);
222     }
223     
224     /**
225      * Gets the port number.
226      *
227      * @return portNumber
228      * @see <code>setPortNumber</code>
229      */

230     public String JavaDoc getPortNumber() {
231         return spec.getDetail(DataSourceSpec.PORTNUMBER);
232     }
233     
234     /**
235      * Sets the database name.
236      *
237      * @param databaseName <code>String</code>
238      * @see <code>getDatabaseName</code>
239      */

240     public void setdatabaseName(String JavaDoc databaseName) {
241         spec.setDetail(DataSourceSpec.DATABASENAME, databaseName);
242     }
243     
244     /**
245      * Gets the database name.
246      *
247      * @return databaseName
248      * @see <code>setDatabaseName</code>
249      */

250     public String JavaDoc getdatabaseName() {
251         return spec.getDetail(DataSourceSpec.DATABASENAME);
252     }
253     
254     /**
255      * Sets the database name.
256      *
257      * @param databaseName <code>String</code>
258      * @see <code>getDatabaseName</code>
259      */

260     public void setDatabaseName(String JavaDoc databaseName) {
261         spec.setDetail(DataSourceSpec.DATABASENAME, databaseName);
262     }
263     
264     /**
265      * Gets the database name.
266      *
267      * @return databaseName
268      * @see <code>setDatabaseName</code>
269      */

270     public String JavaDoc getDatabaseName() {
271         return spec.getDetail(DataSourceSpec.DATABASENAME);
272     }
273     
274     /**
275      * Sets the data source name.
276      *
277      * @param dsn <code>String</code>
278      * @see <code>getDataSourceName</code>
279      */

280     public void setdataSourceName(String JavaDoc dsn) {
281         spec.setDetail(DataSourceSpec.DATASOURCENAME, dsn);
282     }
283     
284     /**
285      * Gets the data source name.
286      *
287      * @return dsn
288      * @see <code>setDataSourceName</code>
289      */

290     public String JavaDoc getdataSourceName() {
291         return spec.getDetail(DataSourceSpec.DATASOURCENAME);
292     }
293     
294     /**
295      * Sets the data source name.
296      *
297      * @param dsn <code>String</code>
298      * @see <code>getDataSourceName</code>
299      */

300     public void setDataSourceName(String JavaDoc dsn) {
301         spec.setDetail(DataSourceSpec.DATASOURCENAME, dsn);
302     }
303     
304     /**
305      * Gets the data source name.
306      *
307      * @return dsn
308      * @see <code>setDataSourceName</code>
309      */

310     public String JavaDoc getDataSourceName() {
311         return spec.getDetail(DataSourceSpec.DATASOURCENAME);
312     }
313     
314     /**
315      * Sets the description.
316      *
317      * @param desc <code>String</code>
318      * @see <code>getDescription</code>
319      */

320     public void setdescription(String JavaDoc desc) {
321         spec.setDetail(DataSourceSpec.DESCRIPTION, desc);
322     }
323     
324     /**
325      * Gets the description.
326      *
327      * @return desc
328      * @see <code>setDescription</code>
329      */

330     public String JavaDoc getdescription() {
331         return spec.getDetail(DataSourceSpec.DESCRIPTION);
332     }
333     
334     /**
335      * Sets the description.
336      *
337      * @param desc <code>String</code>
338      * @see <code>getDescription</code>
339      */

340     public void setDescription(String JavaDoc desc) {
341         spec.setDetail(DataSourceSpec.DESCRIPTION, desc);
342     }
343     
344     /**
345      * Gets the description.
346      *
347      * @return desc
348      * @see <code>setDescription</code>
349      */

350     public String JavaDoc getDescription() {
351         return spec.getDetail(DataSourceSpec.DESCRIPTION);
352     }
353     
354     /**
355      * Sets the network protocol.
356      *
357      * @param nwProtocol <code>String</code>
358      * @see <code>getNetworkProtocol</code>
359      */

360     public void setnetworkProtocol(String JavaDoc nwProtocol) {
361         spec.setDetail(DataSourceSpec.NETWORKPROTOCOL, nwProtocol);
362     }
363     
364     /**
365      * Gets the network protocol.
366      *
367      * @return nwProtocol
368      * @see <code>setNetworkProtocol</code>
369      */

370     public String JavaDoc getnetworkProtocol() {
371         return spec.getDetail(DataSourceSpec.NETWORKPROTOCOL);
372     }
373     
374     /**
375      * Sets the network protocol.
376      *
377      * @param nwProtocol <code>String</code>
378      * @see <code>getNetworkProtocol</code>
379      */

380     public void setNetworkProtocol(String JavaDoc nwProtocol) {
381         spec.setDetail(DataSourceSpec.NETWORKPROTOCOL, nwProtocol);
382     }
383     
384     /**
385      * Gets the network protocol.
386      *
387      * @return nwProtocol
388      * @see <code>setNetworkProtocol</code>
389      */

390     public String JavaDoc getNetworkProtocol() {
391         return spec.getDetail(DataSourceSpec.NETWORKPROTOCOL);
392     }
393     
394     /**
395      * Sets the role name.
396      *
397      * @param roleName <code>String</code>
398      * @see <code>getRoleName</code>
399      */

400     public void setroleName(String JavaDoc roleName) {
401         spec.setDetail(DataSourceSpec.ROLENAME, roleName);
402     }
403     
404     /**
405      * Gets the role name.
406      *
407      * @return roleName
408      * @see <code>setRoleName</code>
409      */

410     public String JavaDoc getroleName() {
411         return spec.getDetail(DataSourceSpec.ROLENAME);
412     }
413     
414     /**
415      * Sets the role name.
416      *
417      * @param roleName <code>String</code>
418      * @see <code>getRoleName</code>
419      */

420     public void setRoleName(String JavaDoc roleName) {
421         spec.setDetail(DataSourceSpec.ROLENAME, roleName);
422     }
423     
424     /**
425      * Gets the role name.
426      *
427      * @return roleName
428      * @see <code>setRoleName</code>
429      */

430     public String JavaDoc getRoleName() {
431         return spec.getDetail(DataSourceSpec.ROLENAME);
432     }
433     
434     /**
435      * Sets the max statements.
436      *
437      * @param maxStmts <code>String</code>
438      * @see <code>getMaxStatements</code>
439      */

440     public void setmaxStatements(String JavaDoc maxStmts) {
441         spec.setDetail(DataSourceSpec.MAXSTATEMENTS, maxStmts);
442     }
443     
444      /**
445      * Gets the max statements.
446      *
447      * @return maxStmts
448      * @see <code>setMaxStatements</code>
449      */

450     public String JavaDoc getmaxStatements() {
451         return spec.getDetail(DataSourceSpec.MAXSTATEMENTS);
452     }
453     
454     /**
455      * Sets the max statements.
456      *
457      * @param maxStmts <code>String</code>
458      * @see <code>getMaxStatements</code>
459      */

460     public void setMaxStatements(String JavaDoc maxStmts) {
461         spec.setDetail(DataSourceSpec.MAXSTATEMENTS, maxStmts);
462     }
463     
464      /**
465      * Gets the max statements.
466      *
467      * @return maxStmts
468      * @see <code>setMaxStatements</code>
469      */

470     public String JavaDoc getMaxStatements() {
471         return spec.getDetail(DataSourceSpec.MAXSTATEMENTS);
472     }
473     
474     /**
475      * Sets the initial pool size.
476      *
477      * @param initPoolSz <code>String</code>
478      * @see <code>getInitialPoolSize</code>
479      */

480     public void setinitialPoolSize(String JavaDoc initPoolSz) {
481         spec.setDetail(DataSourceSpec.INITIALPOOLSIZE, initPoolSz);
482     }
483     
484     /**
485      * Gets the initial pool size.
486      *
487      * @return initPoolSz
488      * @see <code>setInitialPoolSize</code>
489      */

490     public String JavaDoc getinitialPoolSize() {
491         return spec.getDetail(DataSourceSpec.INITIALPOOLSIZE);
492     }
493     
494     /**
495      * Sets the initial pool size.
496      *
497      * @param initPoolSz <code>String</code>
498      * @see <code>getInitialPoolSize</code>
499      */

500     public void setInitialPoolSize(String JavaDoc initPoolSz) {
501         spec.setDetail(DataSourceSpec.INITIALPOOLSIZE, initPoolSz);
502     }
503     
504     /**
505      * Gets the initial pool size.
506      *
507      * @return initPoolSz
508      * @see <code>setInitialPoolSize</code>
509      */

510     public String JavaDoc getInitialPoolSize() {
511         return spec.getDetail(DataSourceSpec.INITIALPOOLSIZE);
512     }
513     
514     /**
515      * Sets the minimum pool size.
516      *
517      * @param minPoolSz <code>String</code>
518      * @see <code>getMinPoolSize</code>
519      */

520     public void setminPoolSize(String JavaDoc minPoolSz) {
521         spec.setDetail(DataSourceSpec.MINPOOLSIZE, minPoolSz);
522     }
523     
524     /**
525      * Gets the minimum pool size.
526      *
527      * @return minPoolSz
528      * @see <code>setMinPoolSize</code>
529      */

530     public String JavaDoc getminPoolSize() {
531         return spec.getDetail(DataSourceSpec.MINPOOLSIZE);
532     }
533     
534     /**
535      * Sets the minimum pool size.
536      *
537      * @param minPoolSz <code>String</code>
538      * @see <code>getMinPoolSize</code>
539      */

540     public void setMinPoolSize(String JavaDoc minPoolSz) {
541         spec.setDetail(DataSourceSpec.MINPOOLSIZE, minPoolSz);
542     }
543     
544     /**
545      * Gets the minimum pool size.
546      *
547      * @return minPoolSz
548      * @see <code>setMinPoolSize</code>
549      */

550     public String JavaDoc getMinPoolSize() {
551         return spec.getDetail(DataSourceSpec.MINPOOLSIZE);
552     }
553     
554     /**
555      * Sets the maximum pool size.
556      *
557      * @param maxPoolSz <code>String</code>
558      * @see <code>getMaxPoolSize</code>
559      */

560     public void setmaxPoolSize(String JavaDoc maxPoolSz) {
561         spec.setDetail(DataSourceSpec.MAXPOOLSIZE, maxPoolSz);
562     }
563     
564     /**
565      * Gets the maximum pool size.
566      *
567      * @return maxPoolSz
568      * @see <code>setMaxPoolSize</code>
569      */

570     public String JavaDoc getmaxPoolSize() {
571         return spec.getDetail(DataSourceSpec.MAXPOOLSIZE);
572     }
573     
574     /**
575      * Sets the maximum pool size.
576      *
577      * @param maxPoolSz <code>String</code>
578      * @see <code>getMaxPoolSize</code>
579      */

580     public void setMaxPoolSize(String JavaDoc maxPoolSz) {
581         spec.setDetail(DataSourceSpec.MAXPOOLSIZE, maxPoolSz);
582     }
583     
584     /**
585      * Gets the maximum pool size.
586      *
587      * @return maxPoolSz
588      * @see <code>setMaxPoolSize</code>
589      */

590     public String JavaDoc getMaxPoolSize() {
591         return spec.getDetail(DataSourceSpec.MAXPOOLSIZE);
592     }
593     
594     /**
595      * Sets the maximum idle time.
596      *
597      * @param maxIdleTime String
598      * @see <code>getMaxIdleTime</code>
599      */

600     public void setmaxIdleTime(String JavaDoc maxIdleTime) {
601         spec.setDetail(DataSourceSpec.MAXIDLETIME, maxIdleTime);
602     }
603     
604     /**
605      * Gets the maximum idle time.
606      *
607      * @return maxIdleTime
608      * @see <code>setMaxIdleTime</code>
609      */

610     public String JavaDoc getmaxIdleTime() {
611         return spec.getDetail(DataSourceSpec.MAXIDLETIME);
612     }
613     
614     /**
615      * Sets the maximum idle time.
616      *
617      * @param maxIdleTime String
618      * @see <code>getMaxIdleTime</code>
619      */

620     public void setMaxIdleTime(String JavaDoc maxIdleTime) {
621         spec.setDetail(DataSourceSpec.MAXIDLETIME, maxIdleTime);
622     }
623     
624     /**
625      * Gets the maximum idle time.
626      *
627      * @return maxIdleTime
628      * @see <code>setMaxIdleTime</code>
629      */

630     public String JavaDoc getMaxIdleTime() {
631         return spec.getDetail(DataSourceSpec.MAXIDLETIME);
632     }
633     
634     /**
635      * Sets the property cycle.
636      *
637      * @param propCycle <code>String</code>
638      * @see <code>getPropertyCycle</code>
639      */

640     public void setpropertyCycle(String JavaDoc propCycle) {
641         spec.setDetail(DataSourceSpec.PROPERTYCYCLE, propCycle);
642     }
643     
644     /**
645      * Gets the property cycle.
646      *
647      * @return propCycle
648      * @see <code>setPropertyCycle</code>
649      */

650     public String JavaDoc getpropertyCycle() {
651         return spec.getDetail(DataSourceSpec.PROPERTYCYCLE);
652     }
653     
654     /**
655      * Sets the property cycle.
656      *
657      * @param propCycle <code>String</code>
658      * @see <code>getPropertyCycle</code>
659      */

660     public void setPropertyCycle(String JavaDoc propCycle) {
661         spec.setDetail(DataSourceSpec.PROPERTYCYCLE, propCycle);
662     }
663     
664     /**
665      * Gets the property cycle.
666      *
667      * @return propCycle
668      * @see <code>setPropertyCycle</code>
669      */

670     public String JavaDoc getPropertyCycle() {
671         return spec.getDetail(DataSourceSpec.PROPERTYCYCLE);
672     }
673 }
674
Popular Tags