KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.gjc.spi.ManagedConnection;
27 import java.sql.SQLException JavaDoc;
28 import javax.resource.ResourceException JavaDoc;
29
30 import com.sun.logging.*;
31 import java.util.logging.Logger JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 /**
34  * <code>ManagedConnectionMetaData</code> implementation for Generic JDBC Connector.
35  *
36  * @version 1.0, 02/08/03
37  * @author Evani Sai Surya Kiran
38  */

39 public class ManagedConnectionMetaData implements javax.resource.spi.ManagedConnectionMetaData JavaDoc {
40
41     private java.sql.DatabaseMetaData JavaDoc dmd = null;
42     private ManagedConnection mc;
43
44     private static Logger JavaDoc _logger;
45     static {
46         _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER );
47     }
48     private boolean debug = false;
49     /**
50      * Constructor for <code>ManagedConnectionMetaData</code>
51      *
52      * @param mc <code>ManagedConnection</code>
53      * @throws <code>ResourceException</code> if getting the DatabaseMetaData object fails
54      */

55     public ManagedConnectionMetaData(ManagedConnection mc) throws ResourceException JavaDoc {
56         try {
57             this.mc = mc;
58             dmd = mc.getActualConnection().getMetaData();
59         } catch(SQLException JavaDoc sqle) {
60         _logger.log(Level.SEVERE, "jdbc.exc_md");
61             throw new ResourceException JavaDoc(sqle.getMessage());
62         }
63     }
64     
65     /**
66      * Returns product name of the underlying EIS instance connected
67      * through the ManagedConnection.
68      *
69      * @return Product name of the EIS instance
70      * @throws <code>ResourceException</code>
71      */

72     public String JavaDoc getEISProductName() throws ResourceException JavaDoc {
73         try {
74             return dmd.getDatabaseProductName();
75         } catch(SQLException JavaDoc sqle) {
76         _logger.log(Level.SEVERE, "jdbc.exc_eis_prodname", sqle);
77             throw new ResourceException JavaDoc(sqle.getMessage());
78         }
79     }
80     
81     /**
82      * Returns product version of the underlying EIS instance connected
83      * through the ManagedConnection.
84      *
85      * @return Product version of the EIS instance
86      * @throws <code>ResourceException</code>
87      */

88     public String JavaDoc getEISProductVersion() throws ResourceException JavaDoc {
89         try {
90             return dmd.getDatabaseProductVersion();
91         } catch(SQLException JavaDoc sqle) {
92         _logger.log(Level.SEVERE, "jdbc.exc_eis_prodvers", sqle);
93             throw new ResourceException JavaDoc(sqle.getMessage(), sqle.getMessage());
94         }
95     }
96     
97     /**
98      * Returns maximum limit on number of active concurrent connections
99      * that an EIS instance can support across client processes.
100      *
101      * @return Maximum limit for number of active concurrent connections
102      * @throws <code>ResourceException</code>
103      */

104     public int getMaxConnections() throws ResourceException JavaDoc {
105         try {
106             return dmd.getMaxConnections();
107         } catch(SQLException JavaDoc sqle) {
108         _logger.log(Level.SEVERE, "jdbc.exc_eis_maxconn");
109             throw new ResourceException JavaDoc(sqle.getMessage());
110         }
111     }
112     
113     /**
114      * Returns name of the user associated with the ManagedConnection instance. The name
115      * corresponds to the resource principal under whose whose security context, a connection
116      * to the EIS instance has been established.
117      *
118      * @return name of the user
119      * @throws <code>ResourceException</code>
120      */

121     public String JavaDoc getUserName() throws ResourceException JavaDoc {
122         javax.resource.spi.security.PasswordCredential JavaDoc pc = mc.getPasswordCredential();
123         if(pc != null) {
124             return pc.getUserName();
125         }
126         
127         return mc.getManagedConnectionFactory().getUser();
128     }
129 }
130
Popular Tags