KickJava   Java API By Example, From Geeks To Geeks.

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


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.spi.*;
27 import javax.resource.*;
28 import javax.security.auth.Subject JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import javax.transaction.xa.XAResource JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import javax.sql.PooledConnection JavaDoc;
35 import javax.sql.XAConnection JavaDoc;
36 import java.sql.SQLException JavaDoc;
37 import javax.resource.spi.security.PasswordCredential JavaDoc;
38 import com.sun.gjc.common.DataSourceObjectBuilder;
39 import com.sun.logging.*;
40 import java.util.logging.Logger JavaDoc;
41 import java.util.logging.Level JavaDoc;
42 import com.sun.enterprise.util.i18n.StringManager;
43
44 /**
45  * <code>ManagedConnection</code> implementation for Generic JDBC Connector.
46  *
47  * @version 1.0, 02/07/22
48  * @author Evani Sai Surya Kiran
49  */

50 public class ManagedConnection implements javax.resource.spi.ManagedConnection JavaDoc,
51     javax.resource.spi.LazyEnlistableManagedConnection JavaDoc,
52     javax.resource.spi.DissociatableManagedConnection JavaDoc
53
54 {
55
56     public static final int ISNOTAPOOLEDCONNECTION = 0;
57     public static final int ISPOOLEDCONNECTION = 1;
58     public static final int ISXACONNECTION = 2;
59
60     protected boolean isDestroyed = false;
61     protected boolean isUsable = true;
62     protected int connectionCount = 0;
63     
64     protected int connectionType = ISNOTAPOOLEDCONNECTION;
65     protected PooledConnection JavaDoc pc = null;
66     protected java.sql.Connection JavaDoc actualConnection = null;
67     protected Hashtable JavaDoc connectionHandles;
68     protected PrintWriter JavaDoc logWriter;
69     protected PasswordCredential JavaDoc passwdCredential;
70     protected javax.resource.spi.ManagedConnectionFactory JavaDoc mcf = null;
71     protected XAResource JavaDoc xar = null;
72
73     protected ConnectionHolder myLogicalConnection = null;
74     
75     //GJCINT
76
protected int isolationLevelWhenCleaned;
77     protected boolean isClean = false;
78
79     protected boolean transactionInProgress = false;
80
81     protected ConnectionEventListener listener = null;
82
83     protected ConnectionEvent ce = null;
84
85     private boolean defaultAutoCommitValue = true;
86     private boolean lastAutoCommitValue = defaultAutoCommitValue;
87
88     protected static Logger JavaDoc _logger;
89     static {
90         _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER );
91     }
92     
93     protected StringManager localStrings =
94         StringManager.getManager( DataSourceObjectBuilder.class );
95     /**
96      * Constructor for <code>ManagedConnection</code>. The pooledConn parameter is expected
97      * to be null and sqlConn parameter is the actual connection in case where
98      * the actual connection is got from a non pooled datasource object. The
99      * pooledConn parameter is expected to be non null and sqlConn parameter
100      * is expected to be null in the case where the datasource object is a
101      * connection pool datasource or an xa datasource.
102      *
103      * @param pooledConn <code>PooledConnection</code> object in case the
104      * physical connection is to be obtained from a pooled
105      * <code>DataSource</code>; null otherwise
106      * @param sqlConn <code>java.sql.Connection</code> object in case the physical
107      * connection is to be obtained from a non pooled <code>DataSource</code>;
108      * null otherwise
109      * @param passwdCred object conatining the
110      * user and password for allocating the connection
111      * @throws ResourceException if the <code>ManagedConnectionFactory</code> object
112      * that created this <code>ManagedConnection</code> object
113      * is not the same as returned by <code>PasswordCredential</code>
114      * object passed
115      */

116     public ManagedConnection(PooledConnection JavaDoc pooledConn, java.sql.Connection JavaDoc sqlConn,
117         PasswordCredential JavaDoc passwdCred, javax.resource.spi.ManagedConnectionFactory JavaDoc mcf)
118         throws ResourceException
119     {
120         if(pooledConn == null && sqlConn == null) {
121             
122         String JavaDoc i18nMsg = localStrings.getString(
123             "jdbc.conn_obj_null");
124             throw new ResourceException( i18nMsg );
125         }
126
127     if (connectionType == ISNOTAPOOLEDCONNECTION ) {
128         actualConnection = sqlConn;
129     }
130
131         pc = pooledConn;
132         connectionHandles = new Hashtable JavaDoc();
133         passwdCredential = passwdCred;
134         this.mcf = mcf;
135         if(passwdCredential != null &&
136             this.mcf.equals(passwdCredential.getManagedConnectionFactory()) == false) {
137         
138         String JavaDoc i18nMsg = localStrings.getString(
139             "jdbc.mc_construct_err");
140         throw new ResourceException( i18nMsg );
141         }
142         logWriter = mcf.getLogWriter();
143     ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
144     }
145
146     /**
147      * Adds a connection event listener to the ManagedConnection instance.
148      *
149      * @param listener <code>ConnectionEventListener</code>
150      * @see <code>removeConnectionEventListener</code>
151      */

152     public void addConnectionEventListener(ConnectionEventListener listener) {
153     this.listener = listener;
154     }
155     
156     /**
157      * Used by the container to change the association of an application-level
158      * connection handle with a <code>ManagedConnection</code> instance.
159      *
160      * @param connection <code>ConnectionHolder</code> to be associated with
161      * this <code>ManagedConnection</code> instance
162      * @throws ResourceException if the physical connection is no more
163      * valid or the connection handle passed is null
164      */

165     public void associateConnection(Object JavaDoc connection) throws ResourceException {
166         if(logWriter != null) {
167             logWriter.println("In associateConnection");
168         }
169         checkIfValid();
170         if(connection == null) {
171         String JavaDoc i18nMsg = localStrings.getString(
172             "jdbc.conn_handle_null");
173             throw new ResourceException(i18nMsg);
174         }
175         ConnectionHolder ch = (ConnectionHolder) connection;
176         
177         com.sun.gjc.spi.ManagedConnection mc = (com.sun.gjc.spi.ManagedConnection)ch.getManagedConnection();
178     isClean = false;
179         
180         ch.associateConnection(actualConnection, this);
181         /**
182          * The expectation from the above method is that the connection holder
183          * replaces the actual sql connection it holds with the sql connection
184          * handle being passed in this method call. Also, it replaces the reference
185          * to the ManagedConnection instance with this ManagedConnection instance.
186          * Any previous statements and result sets also need to be removed.
187          */

188          
189         
190         ch.setActive(true);
191     incrementCount();
192
193         //mc will be null in case we are lazily associating
194
if ( mc != null ) {
195         mc.decrementCount();
196         }
197     }
198     
199     /**
200      * Application server calls this method to force any cleanup on the
201      * <code>ManagedConnection</code> instance. This method calls the invalidate
202      * method on all ConnectionHandles associated with this <code>ManagedConnection</code>.
203      *
204      * @throws ResourceException if the physical connection is no more valid
205      */

206     public void cleanup() throws ResourceException {
207         if(logWriter != null) {
208                 logWriter.println("In cleanup");
209         }
210         checkIfValid();
211         
212         /**
213          * may need to set the autocommit to true for the non-pooled case.
214          */

215         //GJCINT
216
//if (actualConnection != null) {
217
if (connectionType == ISNOTAPOOLEDCONNECTION ) {
218             try {
219                 isolationLevelWhenCleaned = actualConnection.getTransactionIsolation();
220             } catch(SQLException JavaDoc sqle) {
221             String JavaDoc i18nMsg = localStrings.getString(
222                 "jdbc.cannot_get_iso_lvl");
223             ResourceException re = new ResourceException( i18nMsg );
224             re.initCause( sqle );
225             throw re;
226             }
227         }
228         isClean = true;
229         
230     }
231     
232     /**
233      * This method removes all the connection handles from the table
234      * of connection handles and invalidates all of them so that any
235      * operation on those connection handles throws an exception.
236      *
237      * @throws ResourceException if there is a problem in retrieving
238      * the connection handles
239      */

240     protected void invalidateAllConnectionHandles() throws ResourceException {
241         Set JavaDoc handles = connectionHandles.keySet();
242         Iterator JavaDoc iter = handles.iterator();
243         try {
244             while(iter.hasNext()) {
245                 ConnectionHolder ch = (ConnectionHolder)iter.next();
246                 ch.invalidate();
247             }
248         } catch(java.util.NoSuchElementException JavaDoc nsee) {
249             throw new ResourceException("Could not find the connection handle: "+ nsee.getMessage());
250         }
251         connectionHandles.clear();
252     }
253     
254     /**
255      * Destroys the physical connection to the underlying resource manager.
256      *
257      * @throws ResourceException if there is an error in closing the physical connection
258      */

259     public void destroy() throws ResourceException{
260         if(logWriter != null) {
261             logWriter.println("In destroy");
262         }
263     //GJCINT
264
if(isDestroyed == true) {
265         return;
266     }
267
268         try {
269             if(connectionType == ISXACONNECTION || connectionType == ISPOOLEDCONNECTION) {
270                 pc.close();
271                 pc = null;
272                 actualConnection = null;
273             } else {
274                 actualConnection.close();
275                 actualConnection = null;
276             }
277         } catch(SQLException JavaDoc sqle) {
278             isDestroyed = true;
279             passwdCredential = null;
280             connectionHandles = null;
281         String JavaDoc i18nMsg = localStrings.getString(
282             "jdbc.error_in_destroy");
283         ResourceException re = new ResourceException(
284             i18nMsg + sqle.getMessage(), sqle );
285             throw re;
286         }
287         isDestroyed = true;
288         passwdCredential = null;
289         connectionHandles = null;
290     }
291     
292     /**
293      * Creates a new connection handle for the underlying physical
294      * connection represented by the <code>ManagedConnection</code> instance.
295      *
296      * @param subject <code>Subject</code> parameter needed for authentication
297      * @param cxReqInfo <code>ConnectionRequestInfo</code> carries the user
298      * and password required for getting this connection.
299      * @return Connection the connection handle <code>Object</code>
300      * @throws ResourceException if there is an error in allocating the
301      * physical connection from the pooled connection
302      * @throws SecurityException if there is a mismatch between the
303      * password credentials or reauthentication is requested
304      */

305     public Object JavaDoc getConnection(Subject JavaDoc sub, javax.resource.spi.ConnectionRequestInfo JavaDoc cxReqInfo)
306         throws ResourceException {
307         if(logWriter != null) {
308             logWriter.println("In getConnection");
309         }
310         checkIfValid();
311         /** Appserver any way doesnt bother about re-authentication today. So commenting this out now.
312         com.sun.gjc.spi.ConnectionRequestInfo cxRequestInfo = (com.sun.gjc.spi.ConnectionRequestInfo) cxReqInfo;
313         PasswordCredential passwdCred = SecurityUtils.getPasswordCredential(this.mcf, sub, cxRequestInfo);
314             
315         if(SecurityUtils.isPasswordCredentialEqual(this.passwdCredential, passwdCred) == false) {
316             throw new javax.resource.spi.SecurityException("Re-authentication not supported");
317         }
318         **/

319         
320         //GJCINT
321
getActualConnection();
322  
323         /**
324          * The following code in the if statement first checks if this ManagedConnection
325          * is clean or not. If it is, it resets the transaction isolation level to what
326          * it was when it was when this ManagedConnection was cleaned up depending on the
327          * ConnectionRequestInfo passed.
328          */

329         if(isClean) {
330             ((com.sun.gjc.spi.ManagedConnectionFactory)mcf).resetIsolation(this, isolationLevelWhenCleaned);
331         }
332         
333         resetAutoCommit();
334  
335         myLogicalConnection = new ConnectionHolder(actualConnection, this,
336             cxReqInfo);
337     incrementCount();
338     isClean=false;
339         
340         
341         myLogicalConnection.setActive(true);
342  
343         return myLogicalConnection;
344         
345     }
346
347      /**
348      * To reset AutoCommit of actual connection.
349      * If the last-auto-commit value is different from default-auto-commit value, reset will happen.
350      * If there is a transaction in progress (because of connection sharing), reset will not happen.
351      * @throws ResourceException
352      */

353     private void resetAutoCommit() throws ResourceException {
354         if (defaultAutoCommitValue != getLastAutoCommitValue() && !(isTransactionInProgress())) {
355             try {
356                 actualConnection.setAutoCommit(defaultAutoCommitValue);
357             } catch (SQLException JavaDoc sqle) {
358                 String JavaDoc i18nMsg = localStrings.getString(
359                         "jdbc.error_during_setAutoCommit");
360                 throw new ResourceException(i18nMsg + sqle.getMessage(), sqle);
361             }
362             setLastAutoCommitValue(defaultAutoCommitValue);
363         }
364     }
365     
366     /**
367      * Returns an <code>LocalTransaction</code> instance. The <code>LocalTransaction</code> interface
368      * is used by the container to manage local transactions for a RM instance.
369      *
370      * @return <code>LocalTransaction</code> instance
371      * @throws ResourceException if the physical connection is not valid
372      */

373     public javax.resource.spi.LocalTransaction JavaDoc getLocalTransaction() throws ResourceException {
374         if(logWriter != null) {
375             logWriter.println("In getLocalTransaction");
376         }
377         checkIfValid();
378         return new com.sun.gjc.spi.LocalTransaction(this);
379     }
380      
381     /**
382      * Gets the log writer for this <code>ManagedConnection</code> instance.
383      *
384      * @return <code>PrintWriter</code> instance associated with this
385      * <code>ManagedConnection</code> instance
386      * @throws ResourceException if the physical connection is not valid
387      * @see <code>setLogWriter</code>
388      */

389     public PrintWriter JavaDoc getLogWriter() throws ResourceException {
390         if(logWriter != null) {
391                 logWriter.println("In getLogWriter");
392         }
393         checkIfValid();
394         
395         return logWriter;
396     }
397     
398     /**
399      * Gets the metadata information for this connection's underlying EIS
400      * resource manager instance.
401      *
402      * @return <code>ManagedConnectionMetaData</code> instance
403      * @throws ResourceException if the physical connection is not valid
404      */

405     public javax.resource.spi.ManagedConnectionMetaData JavaDoc getMetaData() throws ResourceException {
406         if(logWriter != null) {
407                 logWriter.println("In getMetaData");
408         }
409         checkIfValid();
410         
411         return new com.sun.gjc.spi.ManagedConnectionMetaData(this);
412     }
413     
414     /**
415      * Returns an <code>XAResource</code> instance.
416      *
417      * @return <code>XAResource</code> instance
418      * @throws ResourceException if the physical connection is not valid or
419      * there is an error in allocating the
420      * <code>XAResource</code> instance
421      * @throws NotSupportedException if underlying datasource is not an
422      * <code>XADataSource</code>
423      */

424     public XAResource JavaDoc getXAResource() throws ResourceException {
425         if(logWriter != null) {
426                 logWriter.println("In getXAResource");
427         }
428         checkIfValid();
429         
430         if(connectionType == ISXACONNECTION) {
431             try {
432                 if(xar == null) {
433             /**
434                      * Using the wrapper XAResource.
435                      */

436                     xar = new com.sun.gjc.spi.XAResourceImpl(((XAConnection JavaDoc)pc).getXAResource(), this);
437                 }
438                 return xar;
439             } catch(SQLException JavaDoc sqle) {
440                 throw new ResourceException(sqle.getMessage(), sqle);
441             }
442         } else {
443             throw new NotSupportedException("Cannot get an XAResource from a non XA connection");
444         }
445     }
446     
447     /**
448      * Removes an already registered connection event listener from the
449      * <code>ManagedConnection</code> instance.
450      *
451      * @param listener <code>ConnectionEventListener</code> to be removed
452      * @see <code>addConnectionEventListener</code>
453      */

454     public void removeConnectionEventListener(ConnectionEventListener listener) {
455     listener = null;
456     }
457
458     /**
459      * This method is called from XAResource wrapper object
460      * when its XAResource.start() has been called or from
461      * LocalTransaction object when its begin() method is called.
462      */

463     void transactionStarted() {
464     transactionInProgress = true;
465     }
466
467     /**
468      * This method is called from XAResource wrapper object
469      * when its XAResource.end() has been called or from
470      * LocalTransaction object when its end() method is called.
471      */

472     void transactionCompleted() {
473         try {
474             transactionInProgress = false;
475             if (connectionType == ISPOOLEDCONNECTION || connectionType == ISXACONNECTION) {
476                 try {
477                     isolationLevelWhenCleaned = actualConnection.getTransactionIsolation();
478                 } catch (SQLException JavaDoc sqle) {
479                     //check what to do in this case!!
480
_logger.log(Level.WARNING, "jdbc.notgot_tx_isolvl");
481                 }
482
483                 if (connectionCount <= 0) {
484                     try {
485                         actualConnection.close();
486                         actualConnection = null;
487                     } catch (SQLException JavaDoc sqle) {
488                         actualConnection = null;
489                     }
490                 }
491             }
492         } catch (java.lang.NullPointerException JavaDoc e) {
493             _logger.log(Level.FINE, "jdbc.duplicateTxCompleted");
494         }
495         isClean = true;
496     }
497
498     /**
499      * Checks if a this ManagedConnection is involved in a transaction
500      * or not.
501      */

502     public boolean isTransactionInProgress() {
503     return transactionInProgress;
504     }
505     
506     /**
507      * Sets the log writer for this <code>ManagedConnection</code> instance.
508      *
509      * @param out <code>PrintWriter</code> to be associated with this
510      * <code>ManagedConnection</code> instance
511      * @throws ResourceException if the physical connection is not valid
512      * @see <code>getLogWriter</code>
513      */

514     public void setLogWriter(PrintWriter JavaDoc out) throws ResourceException {
515         checkIfValid();
516         logWriter = out;
517     }
518     
519     /**
520      * This method determines the type of the connection being held
521      * in this <code>ManagedConnection</code>.
522      *
523      * @param pooledConn <code>PooledConnection</code>
524      * @return connection type
525      */

526     protected int getConnectionType(PooledConnection JavaDoc pooledConn) {
527         if(pooledConn == null) {
528             return ISNOTAPOOLEDCONNECTION;
529         } else if(pooledConn instanceof XAConnection JavaDoc) {
530             return ISXACONNECTION;
531         } else {
532             return ISPOOLEDCONNECTION;
533         }
534     }
535     
536     /**
537      * Returns the <code>ManagedConnectionFactory</code> instance that
538      * created this <code>ManagedConnection</code> instance.
539      *
540      * @return <code>ManagedConnectionFactory</code> instance that created this
541      * <code>ManagedConnection</code> instance
542      */

543     ManagedConnectionFactory getManagedConnectionFactory() {
544         return (com.sun.gjc.spi.ManagedConnectionFactory)mcf;
545     }
546     
547     /**
548      * Returns the actual sql connection for this <code>ManagedConnection</code>.
549      *
550      * @return the physical <code>java.sql.Connection</code>
551      */

552     //GJCINT
553
java.sql.Connection JavaDoc getActualConnection() throws ResourceException {
554         //GJCINT
555
if(connectionType == ISXACONNECTION || connectionType == ISPOOLEDCONNECTION) {
556             try {
557                 if(actualConnection == null) {
558                     actualConnection = pc.getConnection();
559                 
560             //re-initialize lastAutoCommitValue such that resetAutoCommit() wont
561
// affect autoCommit of actualConnection
562
setLastAutoCommitValue(defaultAutoCommitValue);
563         }
564         
565             } catch(SQLException JavaDoc sqle) {
566                 throw new ResourceException(sqle.getMessage(), sqle);
567             }
568         }
569         return actualConnection;
570     }
571     
572     /**
573      * Returns the <code>PasswordCredential</code> object associated with this <code>ManagedConnection</code>.
574      *
575      * @return <code>PasswordCredential</code> associated with this
576      * <code>ManagedConnection</code> instance
577      */

578     PasswordCredential JavaDoc getPasswordCredential() {
579         return passwdCredential;
580     }
581     
582     /**
583      * Checks if this <code>ManagedConnection</code> is valid or not and throws an
584      * exception if it is not valid. A <code>ManagedConnection</code> is not valid if
585      * destroy has not been called and no physical connection error has
586      * occurred rendering the physical connection unusable.
587      *
588      * @throws ResourceException if <code>destroy</code> has been called on this
589      * <code>ManagedConnection</code> instance or if a
590      * physical connection error occurred rendering it unusable
591      */

592     //GJCINT
593
void checkIfValid() throws ResourceException {
594         if(isDestroyed == true || isUsable == false) {
595
596         String JavaDoc i18nMsg = localStrings.getString(
597             "jdbc.mc_not_usable");
598             throw new ResourceException( i18nMsg );
599         }
600     }
601     
602     /**
603      * This method is called by the <code>ConnectionHolder</code> when its close method is
604      * called. This <code>ManagedConnection</code> instance invalidates the connection handle
605      * and sends a CONNECTION_CLOSED event to all the registered event listeners.
606      *
607      * @param e Exception that may have occured while closing the connection handle
608      * @param connHolderObject <code>ConnectionHolder</code> that has been closed
609      * @throws SQLException in case closing the sql connection got out of
610      * <code>getConnection</code> on the underlying
611      * <code>PooledConnection</code> throws an exception
612      */

613     void connectionClosed(Exception JavaDoc e, ConnectionHolder connHolderObject) throws SQLException JavaDoc {
614         connHolderObject.invalidate();
615         
616         decrementCount();
617         ce.setConnectionHandle(connHolderObject);
618         listener.connectionClosed(ce);
619     
620     }
621     
622     /**
623      * This method is called by the <code>ConnectionHolder</code> when it detects a connecion
624      * related error.
625      *
626      * @param e Exception that has occurred during an operation on the physical connection
627      * @param connHolderObject <code>ConnectionHolder</code> that detected the physical
628      * connection error
629      */

630     void connectionErrorOccurred(Exception JavaDoc e,
631             com.sun.gjc.spi.ConnectionHolder connHolderObject) {
632         
633          ConnectionEventListener cel = this.listener;
634          ConnectionEvent ce = null;
635          ce = e == null ? new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED)
636                     : new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
637          if (connHolderObject != null) {
638              ce.setConnectionHandle(connHolderObject);
639          }
640
641          cel.connectionErrorOccurred(ce);
642          isUsable = false;
643     }
644     
645     
646     
647     /**
648      * This method is called by the <code>XAResource</code> object when its start method
649      * has been invoked.
650      *
651      */

652     void XAStartOccurred() {
653         try {
654             actualConnection.setAutoCommit(false);
655         } catch(Exception JavaDoc e) {
656             e.printStackTrace();
657             connectionErrorOccurred(e, null);
658         }
659     }
660     
661     /**
662      * This method is called by the <code>XAResource</code> object when its end method
663      * has been invoked.
664      *
665      */

666     void XAEndOccurred() {
667         try {
668             actualConnection.setAutoCommit(true);
669         } catch(Exception JavaDoc e) {
670             e.printStackTrace();
671             connectionErrorOccurred(e, null);
672         }
673     }
674     
675     /**
676      * This method is called by a Connection Handle to check if it is
677      * the active Connection Handle. If it is not the active Connection
678      * Handle, this method throws an SQLException. Else, it
679      * returns setting the active Connection Handle to the calling
680      * Connection Handle object to this object if the active Connection
681      * Handle is null.
682      *
683      * @param ch <code>ConnectionHolder</code> that requests this
684      * <code>ManagedConnection</code> instance whether
685      * it can be active or not
686      * @throws SQLException in case the physical is not valid or
687      * there is already an active connection handle
688      */

689      
690     void checkIfActive(ConnectionHolder ch) throws SQLException JavaDoc {
691         if(isDestroyed == true || isUsable == false) {
692
693         String JavaDoc i18nMsg = localStrings.getString(
694             "jdbc.conn_not_usable");
695             throw new SQLException JavaDoc( i18nMsg );
696         }
697     }
698
699     /**
700      * sets the connection type of this connection. This method is called
701      * by the MCF while creating this ManagedConnection. Saves us a costly
702      * instanceof operation in the getConnectionType
703      */

704     public void initializeConnectionType( int _connectionType ) {
705         connectionType = _connectionType;
706     }
707
708     public void incrementCount() {
709         connectionCount++;
710     }
711
712     public void decrementCount() {
713         connectionCount--;
714     }
715
716     public void dissociateConnections() {
717         myLogicalConnection.setManagedConnection(
718                 (com.sun.gjc.spi.ManagedConnection)null );
719     }
720     public boolean getLastAutoCommitValue() {
721         return lastAutoCommitValue;
722     }
723
724     /**
725      * To keep track of last auto commit value.
726      * Helps to reset the auto-commit-value while giving new connection-handle.
727      * @param lastAutoCommitValue
728      */

729     public void setLastAutoCommitValue(boolean lastAutoCommitValue) {
730         this.lastAutoCommitValue = lastAutoCommitValue;
731     }
732 }
733
Popular Tags