KickJava   Java API By Example, From Geeks To Geeks.

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


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.spi.ConnectionManager;
29 import com.sun.gjc.util.SecurityUtils;
30 import javax.resource.spi.security.PasswordCredential JavaDoc;
31 import java.sql.DriverManager JavaDoc;
32 import com.sun.gjc.common.DataSourceSpec;
33 import com.sun.gjc.common.DataSourceObjectBuilder;
34 import java.sql.SQLException JavaDoc;
35 import java.sql.Connection JavaDoc;
36 import javax.sql.PooledConnection JavaDoc;
37
38 import com.sun.logging.*;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.logging.Level JavaDoc;
41
42 import java.util.Set JavaDoc;
43 import java.util.HashSet JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 /**
47  * <code>ManagedConnectionFactory</code> implementation for Generic JDBC Connector.
48  * This class is extended by the DataSource specific <code>ManagedConnection</code> factories
49  * and the <code>ManagedConnectionFactory</code> for the <code>DriverManager</code>.
50  *
51  * @version 1.0, 02/08/03
52  * @author Evani Sai Surya Kiran, Aditya Gore
53  */

54
55 public abstract class ManagedConnectionFactory implements javax.resource.spi.ManagedConnectionFactory JavaDoc,
56     javax.resource.spi.ValidatingManagedConnectionFactory JavaDoc, java.io.Serializable JavaDoc {
57     
58     protected DataSourceSpec spec = new DataSourceSpec();
59     protected transient DataSourceObjectBuilder dsObjBuilder;
60     
61     protected java.io.PrintWriter JavaDoc logWriter = null;
62     protected javax.resource.spi.ResourceAdapter JavaDoc ra = null;
63     
64     private static Logger JavaDoc _logger;
65     static {
66         _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER );
67     }
68     protected javax.resource.spi.LazyEnlistableConnectionManager JavaDoc cm_;
69     protected boolean isLazyCm_;
70     
71     /**
72      * Creates a Connection Factory instance. The <code>ConnectionManager</code> implementation
73      * of the resource adapter is used here.
74      *
75      * @return Generic JDBC Connector implementation of <code>javax.sql.DataSource</code>
76      */

77     public Object JavaDoc createConnectionFactory() {
78         if(logWriter != null) {
79             logWriter.println("In createConnectionFactory()");
80         }
81         com.sun.gjc.spi.DataSource cf = new com.sun.gjc.spi.DataSource(
82             (javax.resource.spi.ManagedConnectionFactory JavaDoc)this, null);
83         
84         return cf;
85     }
86     
87     /**
88      * Creates a Connection Factory instance. The <code>ConnectionManager</code> implementation
89      * of the application server is used here.
90      *
91      * @param cxManager <code>ConnectionManager</code> passed by the application server
92      * @return Generic JDBC Connector implementation of <code>javax.sql.DataSource</code>
93      */

94     public Object JavaDoc createConnectionFactory(javax.resource.spi.ConnectionManager JavaDoc cxManager) {
95         if(logWriter != null) {
96             logWriter.println("In createConnectionFactory(javax.resource.spi.ConnectionManager cxManager)");
97         }
98         com.sun.gjc.spi.DataSource cf = new com.sun.gjc.spi.DataSource(
99             (javax.resource.spi.ManagedConnectionFactory JavaDoc)this, cxManager);
100         
101         if ( cxManager instanceof javax.resource.spi.LazyEnlistableConnectionManager JavaDoc ) {
102             cm_ = (javax.resource.spi.LazyEnlistableConnectionManager JavaDoc)cxManager;
103             isLazyCm_ = true;
104         }
105         return cf;
106     }
107     
108     /**
109      * Creates a new physical connection to the underlying EIS resource
110      * manager.
111      *
112      * @param subject <code>Subject</code> instance passed by the application server
113      * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
114      * as a result of the invocation <code>getConnection(user, password)</code>
115      * on the <code>DataSource</code> object
116      * @return <code>ManagedConnection</code> object created
117      * @throws ResourceException if there is an error in instantiating the
118      * <code>DataSource</code> object used for the
119      * creation of the <code>ManagedConnection</code> object
120      * @throws SecurityException if there ino <code>PasswordCredential</code> object
121      * satisfying this request
122      * @throws ResourceAllocationException if there is an error in allocating the
123      * physical connection
124      */

125     public abstract javax.resource.spi.ManagedConnection JavaDoc createManagedConnection(javax.security.auth.Subject JavaDoc subject,
126         ConnectionRequestInfo cxRequestInfo) throws ResourceException JavaDoc;
127     
128     /**
129      * Check if this <code>ManagedConnectionFactory</code> is equal to
130      * another <code>ManagedConnectionFactory</code>.
131      *
132      * @param other <code>ManagedConnectionFactory</code> object for checking equality with
133      * @return true if the property sets of both the
134      * <code>ManagedConnectionFactory</code> objects are the same
135      * false otherwise
136      */

137     public abstract boolean equals(Object JavaDoc other);
138     
139     /**
140      * Get the log writer for this <code>ManagedConnectionFactory</code> instance.
141      *
142      * @return <code>PrintWriter</code> associated with this <code>ManagedConnectionFactory</code> instance
143      * @see <code>setLogWriter</code>
144      */

145     public java.io.PrintWriter JavaDoc getLogWriter() {
146         return logWriter;
147     }
148     
149     /**
150      * Get the <code>ResourceAdapter</code> for this <code>ManagedConnectionFactory</code> instance.
151      *
152      * @return <code>ResourceAdapter</code> associated with this <code>ManagedConnectionFactory</code> instance
153      * @see <code>setResourceAdapter</code>
154      */

155     public javax.resource.spi.ResourceAdapter JavaDoc getResourceAdapter() {
156         if(logWriter != null) {
157             logWriter.println("In getResourceAdapter");
158         }
159         return ra;
160     }
161     
162     /**
163      * Returns the hash code for this <code>ManagedConnectionFactory</code>.
164      *
165      * @return hash code for this <code>ManagedConnectionFactory</code>
166      */

167     public int hashCode(){
168         if(logWriter != null) {
169                 logWriter.println("In hashCode");
170         }
171         return spec.hashCode();
172     }
173     
174     /**
175      * Returns a matched <code>ManagedConnection</code> from the candidate
176      * set of <code>ManagedConnection</code> objects.
177      *
178      * @param connectionSet <code>Set</code> of <code>ManagedConnection</code>
179      * objects passed by the application server
180      * @param subject passed by the application server
181      * for retrieving information required for matching
182      * @param cxRequestInfo <code>ConnectionRequestInfo</code> passed by the application server
183      * for retrieving information required for matching
184      * @return <code>ManagedConnection</code> that is the best match satisfying this request
185      * @throws ResourceException if there is an error accessing the <code>Subject</code>
186      * parameter or the <code>Set</code> of <code>ManagedConnection</code>
187      * objects passed by the application server
188      */

189     public javax.resource.spi.ManagedConnection JavaDoc matchManagedConnections(java.util.Set JavaDoc connectionSet,
190         javax.security.auth.Subject JavaDoc subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException JavaDoc {
191         if(logWriter != null) {
192             logWriter.println("In matchManagedConnections");
193         }
194         
195         if(connectionSet == null) {
196             return null;
197         }
198         
199         PasswordCredential JavaDoc pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
200         
201         java.util.Iterator JavaDoc iter = connectionSet.iterator();
202         com.sun.gjc.spi.ManagedConnection mc = null;
203         while(iter.hasNext()) {
204             try {
205                 mc = (com.sun.gjc.spi.ManagedConnection) iter.next();
206             } catch(java.util.NoSuchElementException JavaDoc nsee) {
207             _logger.log(Level.SEVERE, "jdbc.exc_iter");
208                 throw new ResourceException JavaDoc(nsee.getMessage());
209             }
210             if(pc == null && this.equals(mc.getManagedConnectionFactory())) {
211         return mc;
212             } else if(SecurityUtils.isPasswordCredentialEqual(pc, mc.getPasswordCredential()) == true) {
213         return mc;
214             }
215         }
216         return null;
217     }
218     
219    /**
220      * This method returns a set of invalid <code>ManagedConnection</code>
221      * objects chosen from a specified set of <code>ManagedConnection</code>
222      * objects.
223      *
224      * @param connectionSet a set of <code>ManagedConnection</code> objects
225      * that need to be validated.
226      *
227      * @return a set of invalid <code>ManagedConnection</code> objects.
228      *
229      * @throws ResourceException generic exception.
230      */

231     public Set JavaDoc getInvalidConnections(Set JavaDoc connectionSet) throws ResourceException JavaDoc {
232         Iterator JavaDoc iter = connectionSet.iterator();
233         Set JavaDoc invalid = new HashSet JavaDoc();
234         while( iter.hasNext() ) {
235             ManagedConnection mc = (ManagedConnection) iter.next();
236             try {
237                 isValid( mc );
238             } catch( ResourceException JavaDoc re ) {
239                 invalid.add( mc );
240                 mc.connectionErrorOccurred( re, null );
241         
242             }
243         }
244     return invalid;
245     }
246                                   
247     //GJCINT
248
/**
249      * Checks if a <code>ManagedConnection</code> is to be validated or not
250      * and validates it or returns.
251      *
252      * @param mc <code>ManagedConnection</code> to be validated
253      * @throws ResourceException if the connection is not valid or
254      * if validation method is not proper
255      */

256     void isValid(com.sun.gjc.spi.ManagedConnection mc) throws ResourceException JavaDoc {
257
258         if(mc.isTransactionInProgress()) {
259         return;
260         }
261     
262     String JavaDoc conVal = spec.getDetail( DataSourceSpec.CONNECTIONVALIDATIONREQUIRED );
263     
264         boolean connectionValidationRequired =
265             ( conVal == null ) ? false : (new Boolean JavaDoc(conVal.toLowerCase())).booleanValue();
266         if( connectionValidationRequired == false || mc == null) {
267             return;
268         }
269         
270         
271         String JavaDoc validationMethod = spec.getDetail(DataSourceSpec.VALIDATIONMETHOD).toLowerCase();
272         
273         mc.checkIfValid();
274         /**
275          * The above call checks if the actual physical connection
276          * is usable or not.
277          */

278         java.sql.Connection JavaDoc con = mc.getActualConnection();
279         
280         if(validationMethod.equals("auto-commit") == true) {
281             isValidByAutoCommit(con);
282         } else if(validationMethod.equalsIgnoreCase("meta-data") == true) {
283             isValidByMetaData(con);
284         } else if(validationMethod.equalsIgnoreCase("table") == true) {
285             isValidByTableQuery(con, spec.getDetail(DataSourceSpec.VALIDATIONTABLENAME));
286         } else {
287             throw new ResourceException JavaDoc("The validation method is not proper");
288         }
289     }
290     
291     /**
292      * Checks if a <code>java.sql.Connection</code> is valid or not
293      * by checking its auto commit property.
294      *
295      * @param con <code>java.sql.Connection</code> to be validated
296      * @throws ResourceException if the connection is not valid
297      */

298     protected void isValidByAutoCommit(java.sql.Connection JavaDoc con) throws ResourceException JavaDoc {
299         if(con == null) {
300             throw new ResourceException JavaDoc("The connection is not valid as "
301                 + "the connection is null");
302         }
303         
304         try {
305            // Notice that using something like
306
// dbCon.setAutoCommit(dbCon.getAutoCommit()) will cause problems with
307
// some drivers like sybase
308
// We do not validate connections that are already enlisted
309
//in a transaction
310
// We cycle autocommit to true and false to by-pass drivers that
311
// might cache the call to set autocomitt
312
// Also notice that some XA data sources will throw and exception if
313
// you try to call setAutoCommit, for them this method is not recommended
314

315            boolean ac = con.getAutoCommit();
316            if (ac) {
317                 con.setAutoCommit(false);
318            } else {
319                 con.rollback(); // prevents uncompleted transaction exceptions
320
con.setAutoCommit(true);
321            }
322         
323        con.setAutoCommit(ac);
324
325         } catch(Exception JavaDoc sqle) {
326         _logger.log(Level.SEVERE, "jdbc.exc_autocommit");
327             throw new ResourceException JavaDoc(sqle.getMessage());
328         }
329     }
330     
331     /**
332      * Checks if a <code>java.sql.Connection</code> is valid or not
333      * by checking its meta data.
334      *
335      * @param con <code>java.sql.Connection</code> to be validated
336      * @throws ResourceException if the connection is not valid
337      */

338     protected void isValidByMetaData(java.sql.Connection JavaDoc con) throws ResourceException JavaDoc {
339         if(con == null) {
340             throw new ResourceException JavaDoc("The connection is not valid as "
341                 + "the connection is null");
342         }
343         
344         try {
345             java.sql.DatabaseMetaData JavaDoc dmd = con.getMetaData();
346         } catch(Exception JavaDoc sqle) {
347         _logger.log(Level.SEVERE, "jdbc.exc_md");
348             throw new ResourceException JavaDoc("The connection is not valid as "
349                 + "getting the meta data failed: " + sqle.getMessage());
350         }
351     }
352     
353     /**
354      * Checks if a <code>java.sql.Connection</code> is valid or not
355      * by querying a table.
356      *
357      * @param con <code>java.sql.Connection</code> to be validated
358      * @param tableName table which should be queried
359      * @throws ResourceException if the connection is not valid
360      */

361     protected void isValidByTableQuery(java.sql.Connection JavaDoc con,
362         String JavaDoc tableName) throws ResourceException JavaDoc {
363         if(con == null) {
364             throw new ResourceException JavaDoc("The connection is not valid as "
365                 + "the connection is null");
366         }
367     
368         java.sql.Statement JavaDoc stmt = null;
369     java.sql.ResultSet JavaDoc rs = null;
370         try {
371             stmt = con.createStatement();
372             rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
373         } catch(Exception JavaDoc sqle) {
374         _logger.log(Level.SEVERE, "jdbc.exc_execute");
375             throw new ResourceException JavaDoc("The connection is not valid as "
376                 + "querying the table " + tableName + " failed: " + sqle.getMessage());
377         } finally {
378         try {
379             if (rs != null ) {
380                 rs.close();
381             }
382         } catch (Exception JavaDoc e1) {}
383     
384             try {
385             if (stmt != null ) {
386                 stmt.close();
387             }
388         } catch (Exception JavaDoc e2) {}
389     }
390     }
391     
392     /**
393      * Sets the isolation level specified in the <code>ConnectionRequestInfo</code>
394      * for the <code>ManagedConnection</code> passed.
395      *
396      * @param mc <code>ManagedConnection</code>
397      * @throws ResourceException if the isolation property is invalid
398      * or if the isolation cannot be set over the connection
399      */

400     protected void setIsolation(com.sun.gjc.spi.ManagedConnection mc) throws ResourceException JavaDoc {
401         
402         java.sql.Connection JavaDoc con = mc.getActualConnection();
403         if(con == null) {
404             return;
405         }
406         
407         String JavaDoc tranIsolation = spec.getDetail(DataSourceSpec.TRANSACTIONISOLATION);
408         if(tranIsolation != null && tranIsolation.equals("") == false) {
409             int tranIsolationInt = getTransactionIsolationInt(tranIsolation);
410             try {
411                 con.setTransactionIsolation(tranIsolationInt);
412             } catch(java.sql.SQLException JavaDoc sqle) {
413             _logger.log(Level.SEVERE, "jdbc.exc_tx_level");
414                 throw new ResourceException JavaDoc("The transaction isolation could "
415                     + "not be set: " + sqle.getMessage());
416             }
417         }
418     }
419     
420     /**
421      * Resets the isolation level for the <code>ManagedConnection</code> passed.
422      * If the transaction level is to be guaranteed to be the same as the one
423      * present when this <code>ManagedConnection</code> was created, as specified
424      * by the <code>ConnectionRequestInfo</code> passed, it sets the transaction
425      * isolation level from the <code>ConnectionRequestInfo</code> passed. Else,
426      * it sets it to the transaction isolation passed.
427      *
428      * @param mc <code>ManagedConnection</code>
429      * @param tranIsol int
430      * @throws ResourceException if the isolation property is invalid
431      * or if the isolation cannot be set over the connection
432      */

433     void resetIsolation(com.sun.gjc.spi.ManagedConnection mc, int tranIsol) throws ResourceException JavaDoc {
434         
435         java.sql.Connection JavaDoc con = mc.getActualConnection();
436         if(con == null) {
437             return;
438         }
439         
440         String JavaDoc tranIsolation = spec.getDetail(DataSourceSpec.TRANSACTIONISOLATION);
441         if(tranIsolation != null && tranIsolation.equals("") == false) {
442             String JavaDoc guaranteeIsolationLevel = spec.getDetail(DataSourceSpec.GUARANTEEISOLATIONLEVEL);
443             
444             if(guaranteeIsolationLevel != null && guaranteeIsolationLevel.equals("") == false) {
445                 boolean guarantee = (new Boolean JavaDoc(guaranteeIsolationLevel.toLowerCase())).booleanValue();
446                 
447                 if(guarantee) {
448                     int tranIsolationInt = getTransactionIsolationInt(tranIsolation);
449                     try {
450                         if(tranIsolationInt != con.getTransactionIsolation()) {
451                             con.setTransactionIsolation(tranIsolationInt);
452                         }
453                     } catch(java.sql.SQLException JavaDoc sqle) {
454                     _logger.log(Level.SEVERE, "jdbc.exc_tx_level");
455                         throw new ResourceException JavaDoc("The isolation level could not be set: "
456                             + sqle.getMessage());
457                     }
458                 } else {
459                     try {
460                         if(tranIsol != con.getTransactionIsolation()) {
461                             con.setTransactionIsolation(tranIsol);
462                         }
463                     } catch(java.sql.SQLException JavaDoc sqle) {
464                     _logger.log(Level.SEVERE, "jdbc.exc_tx_level");
465                         throw new ResourceException JavaDoc("The isolation level could not be set: "
466                             + sqle.getMessage());
467                     }
468                 }
469             }
470         }
471     }
472     
473     /**
474      * Gets the integer equivalent of the string specifying
475      * the transaction isolation.
476      *
477      * @param tranIsolation string specifying the isolation level
478      * @return tranIsolationInt the <code>java.sql.Connection</code> constant
479      * for the string specifying the isolation.
480      */

481     private int getTransactionIsolationInt(String JavaDoc tranIsolation) throws ResourceException JavaDoc {
482         if(tranIsolation.equalsIgnoreCase("read-uncommitted")) {
483             return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
484         } else if(tranIsolation.equalsIgnoreCase("read-committed")) {
485             return java.sql.Connection.TRANSACTION_READ_COMMITTED;
486         } else if(tranIsolation.equalsIgnoreCase("repeatable-read")) {
487             return java.sql.Connection.TRANSACTION_REPEATABLE_READ;
488         } else if(tranIsolation.equalsIgnoreCase("serializable")) {
489             return java.sql.Connection.TRANSACTION_SERIALIZABLE;
490         } else {
491             throw new ResourceException JavaDoc("Invalid transaction isolation; the transaction "
492                 + "isolation level can be empty or any of the following: "
493                     + "read-uncommitted, read-committed, repeatable-read, serializable");
494         }
495     }
496     
497     /**
498      * Common operation performed by all the child MCFs before returning a created mc
499      */

500     protected void validateAndSetIsolation( ManagedConnection mc )
501             throws ResourceException JavaDoc
502     {
503        isValid( mc );
504        setIsolation( mc );
505     }
506     
507     /**
508      * Set the log writer for this <code>ManagedConnectionFactory</code> instance.
509      *
510      * @param out <code>PrintWriter</code> passed by the application server
511      * @see <code>getLogWriter</code>
512      */

513     public void setLogWriter(java.io.PrintWriter JavaDoc out) {
514         logWriter = out;
515     }
516     
517     /**
518      * Set the associated <code>ResourceAdapter</code> JavaBean.
519      *
520      * @param ra <code>ResourceAdapter</code> associated with this
521      * <code>ManagedConnectionFactory</code> instance
522      * @see <code>getResourceAdapter</code>
523      */

524     public void setResourceAdapter(javax.resource.spi.ResourceAdapter JavaDoc ra) {
525         this.ra = ra;
526     }
527     
528     /**
529      * Sets the user name
530      *
531      * @param user <code>String</code>
532      */

533     public void setUser(String JavaDoc user) {
534         spec.setDetail(DataSourceSpec.USERNAME, user);
535     }
536     
537     /**
538      * Gets the user name
539      *
540      * @return user
541      */

542     public String JavaDoc getUser() {
543         return spec.getDetail(DataSourceSpec.USERNAME);
544     }
545     
546     /**
547      * Sets the user name
548      *
549      * @param user <code>String</code>
550      */

551     public void setuser(String JavaDoc user) {
552         spec.setDetail(DataSourceSpec.USERNAME, user);
553     }
554     
555     /**
556      * Gets the user name
557      *
558      * @return user
559      */

560     public String JavaDoc getuser() {
561         return spec.getDetail(DataSourceSpec.USERNAME);
562     }
563     
564     /**
565      * Sets the password
566      *
567      * @param passwd <code>String</code>
568      */

569     public void setPassword(String JavaDoc passwd) {
570         spec.setDetail(DataSourceSpec.PASSWORD, passwd);
571     }
572     
573     /**
574      * Gets the password
575      *
576      * @return passwd
577      */

578     public String JavaDoc getPassword() {
579         return spec.getDetail(DataSourceSpec.PASSWORD);
580     }
581     
582     /**
583      * Sets the password
584      *
585      * @param passwd <code>String</code>
586      */

587     public void setpassword(String JavaDoc passwd) {
588         spec.setDetail(DataSourceSpec.PASSWORD, passwd);
589     }
590     
591     /**
592      * Gets the password
593      *
594      * @return passwd
595      */

596     public String JavaDoc getpassword() {
597         return spec.getDetail(DataSourceSpec.PASSWORD);
598     }
599     
600     /**
601      * Sets the class name of the data source
602      *
603      * @param className <code>String</code>
604      */

605     public void setClassName(String JavaDoc className) {
606         spec.setDetail(DataSourceSpec.CLASSNAME, className);
607     }
608     
609     /**
610      * Gets the class name of the data source
611      *
612      * @return className
613      */

614     public String JavaDoc getClassName() {
615         return spec.getDetail(DataSourceSpec.CLASSNAME);
616     }
617     
618     /**
619      * Sets the class name of the data source
620      *
621      * @param className <code>String</code>
622      */

623     public void setclassName(String JavaDoc className) {
624         spec.setDetail(DataSourceSpec.CLASSNAME, className);
625     }
626     
627     /**
628      * Gets the class name of the data source
629      *
630      * @return className
631      */

632     public String JavaDoc getclassName() {
633         return spec.getDetail(DataSourceSpec.CLASSNAME);
634     }
635     
636     /**
637      * Sets if connection validation is required or not
638      *
639      * @param conVldReq <code>String</code>
640      */

641     public void setConnectionValidationRequired(String JavaDoc conVldReq) {
642         spec.setDetail(DataSourceSpec.CONNECTIONVALIDATIONREQUIRED, conVldReq);
643     }
644     
645     /**
646      * Returns if connection validation is required or not
647      *
648      * @return connection validation requirement
649      */

650     public String JavaDoc getConnectionValidationRequired() {
651         return spec.getDetail(DataSourceSpec.CONNECTIONVALIDATIONREQUIRED);
652     }
653     
654     /**
655      * Sets if connection validation is required or not
656      *
657      * @param conVldReq <code>String</code>
658      */

659     public void setconnectionValidationRequired(String JavaDoc conVldReq) {
660         spec.setDetail(DataSourceSpec.CONNECTIONVALIDATIONREQUIRED, conVldReq);
661     }
662     
663     /**
664      * Returns if connection validation is required or not
665      *
666      * @return connection validation requirement
667      */

668     public String JavaDoc getconnectionValidationRequired() {
669         return spec.getDetail(DataSourceSpec.CONNECTIONVALIDATIONREQUIRED);
670     }
671     
672     /**
673      * Sets the validation method required
674      *
675      * @param validationMethod <code>String</code>
676      */

677     public void setValidationMethod(String JavaDoc validationMethod) {
678             spec.setDetail(DataSourceSpec.VALIDATIONMETHOD, validationMethod);
679     }
680     
681     /**
682      * Returns the connection validation method type
683      *
684      * @return validation method
685      */

686     public String JavaDoc getValidationMethod() {
687         return spec.getDetail(DataSourceSpec.VALIDATIONMETHOD);
688     }
689     
690     /**
691      * Sets the validation method required
692      *
693      * @param validationMethod <code>String</code>
694      */

695     public void setvalidationMethod(String JavaDoc validationMethod) {
696             spec.setDetail(DataSourceSpec.VALIDATIONMETHOD, validationMethod);
697     }
698     
699     /**
700      * Returns the connection validation method type
701      *
702      * @return validation method
703      */

704     public String JavaDoc getvalidationMethod() {
705         return spec.getDetail(DataSourceSpec.VALIDATIONMETHOD);
706     }
707     
708     /**
709      * Sets the table checked for during validation
710      *
711      * @param table <code>String</code>
712      */

713     public void setValidationTableName(String JavaDoc table) {
714         spec.setDetail(DataSourceSpec.VALIDATIONTABLENAME, table);
715     }
716     
717     /**
718      * Returns the table checked for during validation
719      *
720      * @return table
721      */

722     public String JavaDoc getValidationTableName() {
723         return spec.getDetail(DataSourceSpec.VALIDATIONTABLENAME);
724     }
725     
726     /**
727      * Sets the table checked for during validation
728      *
729      * @param table <code>String</code>
730      */

731     public void setvalidationTableName(String JavaDoc table) {
732         spec.setDetail(DataSourceSpec.VALIDATIONTABLENAME, table);
733     }
734     
735     /**
736      * Returns the table checked for during validation
737      *
738      * @return table
739      */

740     public String JavaDoc getvalidationTableName() {
741         return spec.getDetail(DataSourceSpec.VALIDATIONTABLENAME);
742     }
743     
744     /**
745      * Sets the transaction isolation level
746      *
747      * @param trnIsolation <code>String</code>
748      */

749     public void setTransactionIsolation(String JavaDoc trnIsolation) {
750         spec.setDetail(DataSourceSpec.TRANSACTIONISOLATION, trnIsolation);
751     }
752     
753     /**
754      * Returns the transaction isolation level
755      *
756      * @return transaction isolation level
757      */

758     public String JavaDoc getTransactionIsolation() {
759         return spec.getDetail(DataSourceSpec.TRANSACTIONISOLATION);
760     }
761     
762     /**
763      * Sets the transaction isolation level
764      *
765      * @param trnIsolation <code>String</code>
766      */

767     public void settransactionIsolation(String JavaDoc trnIsolation) {
768         spec.setDetail(DataSourceSpec.TRANSACTIONISOLATION, trnIsolation);
769     }
770     
771     /**
772      * Returns the transaction isolation level
773      *
774      * @return transaction isolation level
775      */

776     public String JavaDoc gettransactionIsolation() {
777         return spec.getDetail(DataSourceSpec.TRANSACTIONISOLATION);
778     }
779     
780     /**
781      * Sets if the transaction isolation level is to be guaranteed
782      *
783      * @param guaranteeIsolation <code>String</code>
784      */

785     public void setGuaranteeIsolationLevel(String JavaDoc guaranteeIsolation) {
786         spec.setDetail(DataSourceSpec.GUARANTEEISOLATIONLEVEL, guaranteeIsolation);
787     }
788     
789     /**
790      * Returns the transaction isolation level
791      *
792      * @return isolation level guarantee
793      */

794     public String JavaDoc getGuaranteeIsolationLevel() {
795         return spec.getDetail(DataSourceSpec.GUARANTEEISOLATIONLEVEL);
796     }
797     
798     /**
799      * Sets if the transaction isolation level is to be guaranteed
800      *
801      * @param guaranteeIsolation <code>String</code>
802      */

803     public void setguaranteeIsolationLevel(String JavaDoc guaranteeIsolation) {
804         spec.setDetail(DataSourceSpec.GUARANTEEISOLATIONLEVEL, guaranteeIsolation);
805     }
806     
807     /**
808      * Returns the transaction isolation level
809      *
810      * @return isolation level guarantee
811      */

812     public String JavaDoc getguaranteeIsolationLevel() {
813         return spec.getDetail(DataSourceSpec.GUARANTEEISOLATIONLEVEL);
814     }
815     
816     protected boolean isEqual( PasswordCredential JavaDoc pc, String JavaDoc user,
817         String JavaDoc password) {
818         
819     //if equal get direct connection else
820
//get connection with user and password.
821

822     String JavaDoc thisUser = (pc == null) ? null : pc.getUserName();
823     char[] passwordArray = (pc == null) ? null : pc.getPassword();
824     String JavaDoc thisPassword = (passwordArray == null) ? null : new String JavaDoc(passwordArray);
825
826     return (isStringEqual(thisUser, user) && isStringEqual(thisPassword, password));
827
828     }
829
830     private boolean isStringEqual(String JavaDoc str1, String JavaDoc str2) {
831     return str1 == null ? str2 == null : str1.equals( str2 );
832     }
833
834     
835     /**
836      * Sets the server name.
837      *
838      * @param serverName <code>String</code>
839      * @see <code>getServerName</code>
840      */

841     public void setserverName(String JavaDoc serverName) {
842         spec.setDetail(DataSourceSpec.SERVERNAME, serverName);
843     }
844     
845     /**
846      * Gets the server name.
847      *
848      * @return serverName
849      * @see <code>setServerName</code>
850      */

851     public String JavaDoc getserverName() {
852         return spec.getDetail(DataSourceSpec.SERVERNAME);
853     }
854     
855     /**
856      * Sets the server name.
857      *
858      * @param serverName <code>String</code>
859      * @see <code>getServerName</code>
860      */

861     public void setServerName(String JavaDoc serverName) {
862         spec.setDetail(DataSourceSpec.SERVERNAME, serverName);
863     }
864     
865     /**
866      * Gets the server name.
867      *
868      * @return serverName
869      * @see <code>setServerName</code>
870      */

871     public String JavaDoc getServerName() {
872         return spec.getDetail(DataSourceSpec.SERVERNAME);
873     }
874     
875     /**
876      * Sets the port number.
877      *
878      * @param portNumber <code>String</code>
879      * @see <code>getPortNumber</code>
880      */

881     public void setportNumber(String JavaDoc portNumber) {
882         spec.setDetail(DataSourceSpec.PORTNUMBER, portNumber);
883     }
884     
885     /**
886      * Gets the port number.
887      *
888      * @return portNumber
889      * @see <code>setPortNumber</code>
890      */

891     public String JavaDoc getportNumber() {
892         return spec.getDetail(DataSourceSpec.PORTNUMBER);
893     }
894     
895     /**
896      * Sets the port number.
897      *
898      * @param portNumber <code>String</code>
899      * @see <code>getPortNumber</code>
900      */

901     public void setPortNumber(String JavaDoc portNumber) {
902         spec.setDetail(DataSourceSpec.PORTNUMBER, portNumber);
903     }
904     
905     /**
906      * Gets the port number.
907      *
908      * @return portNumber
909      * @see <code>setPortNumber</code>
910      */

911     public String JavaDoc getPortNumber() {
912         return spec.getDetail(DataSourceSpec.PORTNUMBER);
913     }
914     
915     /**
916      * Sets the database name.
917      *
918      * @param databaseName <code>String</code>
919      * @see <code>getDatabaseName</code>
920      */

921     public void setdatabaseName(String JavaDoc databaseName) {
922         spec.setDetail(DataSourceSpec.DATABASENAME, databaseName);
923     }
924     
925     /**
926      * Gets the database name.
927      *
928      * @return databaseName
929      * @see <code>setDatabaseName</code>
930      */

931     public String JavaDoc getdatabaseName() {
932         return spec.getDetail(DataSourceSpec.DATABASENAME);
933     }
934     
935     /**
936      * Sets the database name.
937      *
938      * @param databaseName <code>String</code>
939      * @see <code>getDatabaseName</code>
940      */

941     public void setDatabaseName(String JavaDoc databaseName) {
942         spec.setDetail(DataSourceSpec.DATABASENAME, databaseName);
943     }
944     
945     /**
946      * Gets the database name.
947      *
948      * @return databaseName
949      * @see <code>setDatabaseName</code>
950      */

951     public String JavaDoc getDatabaseName() {
952         return spec.getDetail(DataSourceSpec.DATABASENAME);
953     }
954     
955     /**
956      * Sets the data source name.
957      *
958      * @param dsn <code>String</code>
959      * @see <code>getDataSourceName</code>
960      */

961     public void setdataSourceName(String JavaDoc dsn) {
962         spec.setDetail(DataSourceSpec.DATASOURCENAME, dsn);
963     }
964     
965     /**
966      * Gets the data source name.
967      *
968      * @return dsn
969      * @see <code>setDataSourceName</code>
970      */

971     public String JavaDoc getdataSourceName() {
972         return spec.getDetail(DataSourceSpec.DATASOURCENAME);
973     }
974     
975     /**
976      * Sets the data source name.
977      *
978      * @param dsn <code>String</code>
979      * @see <code>getDataSourceName</code>
980      */

981     public void setDataSourceName(String JavaDoc dsn) {
982         spec.setDetail(DataSourceSpec.DATASOURCENAME, dsn);
983     }
984     
985     /**
986      * Gets the data source name.
987      *
988      * @return dsn
989      * @see <code>setDataSourceName</code>
990      */

991     public String JavaDoc getDataSourceName() {
992         return spec.getDetail(DataSourceSpec.DATASOURCENAME);
993     }
994     
995     /**
996      * Sets the description.
997      *
998      * @param desc <code>String</code>
999      * @see <code>getDescription</code>
1000     */

1001    public void setdescription(String JavaDoc desc) {
1002        spec.setDetail(DataSourceSpec.DESCRIPTION, desc);
1003    }
1004    
1005    /**
1006     * Gets the description.
1007     *
1008     * @return desc
1009     * @see <code>setDescription</code>
1010     */

1011    public String JavaDoc getdescription() {
1012        return spec.getDetail(DataSourceSpec.DESCRIPTION);
1013    }
1014    
1015    /**
1016     * Sets the description.
1017     *
1018     * @param desc <code>String</code>
1019     * @see <code>getDescription</code>
1020     */

1021    public void setDescription(String JavaDoc desc) {
1022        spec.setDetail(DataSourceSpec.DESCRIPTION, desc);
1023    }
1024    
1025    /**
1026     * Gets the description.
1027     *
1028     * @return desc
1029     * @see <code>setDescription</code>
1030     */

1031    public String JavaDoc getDescription() {
1032        return spec.getDetail(DataSourceSpec.DESCRIPTION);
1033    }
1034    
1035    /**
1036     * Sets the network protocol.
1037     *
1038     * @param nwProtocol <code>String</code>
1039     * @see <code>getNetworkProtocol</code>
1040     */

1041    public void setnetworkProtocol(String JavaDoc nwProtocol) {
1042        spec.setDetail(DataSourceSpec.NETWORKPROTOCOL, nwProtocol);
1043    }
1044    
1045    /**
1046     * Gets the network protocol.
1047     *
1048     * @return nwProtocol
1049     * @see <code>setNetworkProtocol</code>
1050     */

1051    public String JavaDoc getnetworkProtocol() {
1052        return spec.getDetail(DataSourceSpec.NETWORKPROTOCOL);
1053    }
1054    
1055    /**
1056     * Sets the network protocol.
1057     *
1058     * @param nwProtocol <code>String</code>
1059     * @see <code>getNetworkProtocol</code>
1060     */

1061    public void setNetworkProtocol(String JavaDoc nwProtocol) {
1062        spec.setDetail(DataSourceSpec.NETWORKPROTOCOL, nwProtocol);
1063    }
1064    
1065    /**
1066     * Gets the network protocol.
1067     *
1068     * @return nwProtocol
1069     * @see <code>setNetworkProtocol</code>
1070     */

1071    public String JavaDoc getNetworkProtocol() {
1072        return spec.getDetail(DataSourceSpec.NETWORKPROTOCOL);
1073    }
1074    
1075    /**
1076     * Sets the role name.
1077     *
1078     * @param roleName <code>String</code>
1079     * @see <code>getRoleName</code>
1080     */

1081    public void setroleName(String JavaDoc roleName) {
1082        spec.setDetail(DataSourceSpec.ROLENAME, roleName);
1083    }
1084    
1085    /**
1086     * Gets the role name.
1087     *
1088     * @return roleName
1089     * @see <code>setRoleName</code>
1090     */

1091    public String JavaDoc getroleName() {
1092        return spec.getDetail(DataSourceSpec.ROLENAME);
1093    }
1094    
1095    /**
1096     * Sets the role name.
1097     *
1098     * @param roleName <code>String</code>
1099     * @see <code>getRoleName</code>
1100     */

1101    public void setRoleName(String JavaDoc roleName) {
1102        spec.setDetail(DataSourceSpec.ROLENAME, roleName);
1103    }
1104    
1105    /**
1106     * Gets the role name.
1107     *
1108     * @return roleName
1109     * @see <code>setRoleName</code>
1110     */

1111    public String JavaDoc getRoleName() {
1112        return spec.getDetail(DataSourceSpec.ROLENAME);
1113    }
1114
1115    
1116    /**
1117     * Sets the login timeout.
1118     *
1119     * @param loginTimeOut <code>String</code>
1120     * @see <code>getLoginTimeOut</code>
1121     */

1122    public void setloginTimeOut(String JavaDoc loginTimeOut) {
1123        spec.setDetail(DataSourceSpec.LOGINTIMEOUT, loginTimeOut);
1124    }
1125    
1126    /**
1127     * Gets the login timeout.
1128     *
1129     * @return loginTimeout
1130     * @see <code>setLoginTimeOut</code>
1131     */

1132    public String JavaDoc getloginTimeOut() {
1133        return spec.getDetail(DataSourceSpec.LOGINTIMEOUT);
1134    }
1135    
1136    /**
1137     * Sets the login timeout.
1138     *
1139     * @param loginTimeOut <code>String</code>
1140     * @see <code>getLoginTimeOut</code>
1141     */

1142    public void setLoginTimeOut(String JavaDoc loginTimeOut) {
1143        spec.setDetail(DataSourceSpec.LOGINTIMEOUT, loginTimeOut);
1144    }
1145    
1146    /**
1147     * Gets the login timeout.
1148     *
1149     * @return loginTimeout
1150     * @see <code>setLoginTimeOut</code>
1151     */

1152    public String JavaDoc getLoginTimeOut() {
1153        return spec.getDetail(DataSourceSpec.LOGINTIMEOUT);
1154    }
1155    
1156    /**
1157     * Sets the delimiter.
1158     *
1159     * @param delim <code>String</code>
1160     * @see <code>getDelimiter</code>
1161     */

1162    public void setdelimiter(String JavaDoc delim) {
1163        spec.setDetail(DataSourceSpec.DELIMITER, delim);
1164    }
1165    
1166    /**
1167     * Gets the delimiter.
1168     *
1169     * @return delim
1170     * @see <code>setDelimiter</code>
1171     */

1172    public String JavaDoc getdelimiter() {
1173        return spec.getDetail(DataSourceSpec.DELIMITER);
1174    }
1175    
1176    /**
1177     * Sets the delimiter.
1178     *
1179     * @param delim <code>String</code>
1180     * @see <code>getDelimiter</code>
1181     */

1182    public void setDelimiter(String JavaDoc delim) {
1183        spec.setDetail(DataSourceSpec.DELIMITER, delim);
1184    }
1185    
1186    /**
1187     * Gets the delimiter.
1188     *
1189     * @return delim
1190     * @see <code>setDelimiter</code>
1191     */

1192    public String JavaDoc getDelimiter() {
1193        return spec.getDetail(DataSourceSpec.DELIMITER);
1194    }
1195    
1196    /**
1197     * Sets the driver specific properties.
1198     *
1199     * @param driverProps <code>String</code>
1200     * @see <code>getDriverProperties</code>
1201     */

1202    public void setdriverProperties(String JavaDoc driverProps) {
1203        spec.setDetail(DataSourceSpec.DRIVERPROPERTIES, driverProps);
1204    }
1205    
1206    /**
1207     * Gets the driver specific properties.
1208     *
1209     * @return driverProps
1210     * @see <code>setDriverProperties</code>
1211     */

1212    public String JavaDoc getdriverProperties() {
1213        return spec.getDetail(DataSourceSpec.DRIVERPROPERTIES);
1214    }
1215    
1216    /**
1217     * Sets the driver specific properties.
1218     *
1219     * @param driverProps <code>String</code>
1220     * @see <code>getDriverProperties</code>
1221     */

1222    public void setDriverProperties(String JavaDoc driverProps) {
1223        spec.setDetail(DataSourceSpec.DRIVERPROPERTIES, driverProps);
1224    }
1225    
1226    /**
1227     * Gets the driver specific properties.
1228     *
1229     * @return driverProps
1230     * @see <code>setDriverProperties</code>
1231     */

1232    public String JavaDoc getDriverProperties() {
1233        return spec.getDetail(DataSourceSpec.DRIVERPROPERTIES);
1234    }
1235
1236    protected ManagedConnection constructManagedConnection(PooledConnection JavaDoc pc,
1237        Connection JavaDoc sqlCon, PasswordCredential JavaDoc passCred,
1238        ManagedConnectionFactory mcf ) throws ResourceException JavaDoc
1239    {
1240        
1241        com.sun.gjc.spi.ManagedConnection mc =
1242            new com.sun.gjc.spi.ManagedConnection( pc, sqlCon, passCred, mcf );
1243        
1244        return mc;
1245
1246    }
1247
1248}
1249
Popular Tags