ConnectionPoolMCFImpl.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Eric HARDESTY
00022  * --------------------------------------------------------------------------
00023  * $Id: ConnectionPoolMCFImpl.java,v 1.5 2004/12/14 16:13:51 ehardesty Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 package org.objectweb.jonas.jdbc;
00027 
00028 
00029 import java.sql.SQLException;
00030 
00031 import javax.resource.ResourceException;
00032 import javax.resource.spi.ConnectionRequestInfo;
00033 import javax.resource.spi.ManagedConnection;
00034 import javax.resource.spi.ResourceAllocationException;
00035 import javax.resource.spi.security.PasswordCredential;
00036 import javax.security.auth.Subject;
00037 import javax.sql.ConnectionPoolDataSource;
00038 
00045 public class ConnectionPoolMCFImpl
00046         extends ManagedConnectionFactoryImpl { 
00047 
00048     
00049     ConnectionPoolDataSource ds = null;
00050 
00051     public ManagedConnection createManagedConnection(Subject subject, 
00052                                                       ConnectionRequestInfo cxReq)
00053               throws ResourceException {
00054                   
00055       PasswordCredential pc = Utility.getPasswordCredential(this, subject, cxReq, pw);
00056       if(ds == null) {
00057           try {
00058               ds = (ConnectionPoolDataSource) Utility.getDataSource(this, pc, trace);
00059           } catch(Exception ex) {
00060               throw new ResourceException(ex.getMessage());
00061           }
00062       }
00063       
00064       javax.sql.PooledConnection pConnection = null;
00065       java.sql.Connection connection = null;
00066       try {
00067           if(cxReq != null) {
00068               ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq; 
00069               pConnection = ds.getPooledConnection(cx.getUser(), cx.getPassword());
00070           } else if (pc != null){
00071               pConnection = ds.getPooledConnection(pc.getUserName(), new String(pc.getPassword()));
00072           } else if (mcfData.getMCFData(MCFData.USER).length() > 0){
00073               pConnection = ds.getPooledConnection(mcfData.getMCFData(MCFData.USER), 
00074                                                    mcfData.getMCFData(MCFData.PASSWORD));
00075           } else {
00076               pConnection = ds.getPooledConnection(); 
00077           }
00078           if (pConnection != null) {
00079               connection = pConnection.getConnection();
00080           }
00081       }
00082       catch(SQLException sqle)
00083       {
00084           throw new ResourceAllocationException("The connection could not be allocated: " + sqle.getMessage());
00085       }
00086       return new ManagedConnectionImpl(this, pc, connection, pConnection, null, null);
00087     }
00088 
00089     /* Determine if the factories are equal
00090      */
00091     public boolean equals(Object obj) {
00092         if (obj instanceof ConnectionPoolMCFImpl) {
00093             return mcfData.equals(((ConnectionPoolMCFImpl)obj).mcfData);
00094         }
00095         else {
00096             return false;
00097         }
00098     }
00099 
00100     // JOnAS JDBC RA ConnectionPool config properties
00101     public String getDatabaseName()
00102     {
00103         return mcfData.getMCFData(MCFData.DATABASENAME);
00104     }
00105 
00106     public void setDatabaseName(String val)
00107     {
00108         mcfData.setMCFData(MCFData.DATABASENAME, val);
00109     }
00110 
00111     public String getDescription()
00112     {
00113         return mcfData.getMCFData(MCFData.DESCRIPTION);
00114     }
00115 
00116     public void setDescription(String val)
00117     {
00118         mcfData.setMCFData(MCFData.DESCRIPTION, val);
00119     }
00120 
00121     public String getPortNumber()
00122     {
00123         return mcfData.getMCFData(MCFData.PORTNUMBER);
00124     }
00125 
00126     public void setPortNumber(String val)
00127     {
00128         mcfData.setMCFData(MCFData.PORTNUMBER, val);
00129     }
00130 
00131     public String getServerName()
00132     {
00133         return mcfData.getMCFData(MCFData.SERVERNAME);
00134     }
00135 
00136     public void setServerName(String val)
00137     {
00138         mcfData.setMCFData(MCFData.SERVERNAME, val);
00139     }
00140 
00141 }

Generated on Tue Feb 15 15:05:16 2005 for JOnAS by  doxygen 1.3.9.1