KickJava   Java API By Example, From Geeks To Geeks.

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


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.gjc.spi.ManagedConnectionFactory;
34
35 import com.sun.logging.*;
36 import java.util.logging.Logger JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40 /**
41  * XA <code>ManagedConnectionFactory</code> implementation for Generic JDBC Connector.
42  *
43  * @version 1.0, 02/07/27
44  * @author Evani Sai Surya Kiran
45  */

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

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

101         if ( isEqual( pc, getUser(), getPassword() ) ) {
102             xaConn = xaDataSourceObj.getXAConnection();
103         } else {
104             xaConn = xaDataSourceObj.getXAConnection(pc.getUserName(),
105             new String JavaDoc(pc.getPassword()));
106         }
107
108
109         } catch(java.sql.SQLException JavaDoc sqle) {
110         //_logger.log(Level.WARNING, "jdbc.exc_create_xa_conn",sqle);
111
_logger.log(Level.FINE, "jdbc.exc_create_xa_conn",sqle);
112             StringManager sm = StringManager.getManager(
113                 DataSourceObjectBuilder.class );
114         String JavaDoc msg = sm.getString( "jdbc.cannot_allocate_connection", sqle.getMessage() );
115         ResourceAllocationException JavaDoc rae = new ResourceAllocationException JavaDoc(
116             msg, sqle );
117         throw rae;
118         }
119         
120         com.sun.gjc.spi.ManagedConnection mc = constructManagedConnection(
121             xaConn, null, pc, this );
122         
123     mc.initializeConnectionType( ManagedConnection.ISXACONNECTION);
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.XAManagedConnectionFactory) {
147             com.sun.gjc.spi.XAManagedConnectionFactory otherMCF =
148                 (com.sun.gjc.spi.XAManagedConnectionFactory) other;
149             return this.spec.equals(otherMCF.spec);
150         }
151         return false;
152     }
153     
154     
155     /**
156      * Sets the server name.
157      *
158      * @param serverName <code>String</code>
159      * @see <code>getServerName</code>
160      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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