DataSourceMCFImpl.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: DataSourceMCFImpl.java,v 1.4 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.DataSource;
00038 
00039 import org.objectweb.util.monolog.api.BasicLevel;
00040 
00041 public class DataSourceMCFImpl
00042         extends ManagedConnectionFactoryImpl { 
00043 
00044     DataSource ds = null;
00045 
00046     public ManagedConnection createManagedConnection(Subject subject, 
00047                                                       ConnectionRequestInfo cxReq)
00048               throws ResourceException {
00049                   
00050       PasswordCredential pc = Utility.getPasswordCredential(this, subject, cxReq, pw);
00051       if(ds == null) {
00052           try {
00053               ds = (DataSource) Utility.getDataSource(this, pc, trace);
00054           } catch(Exception ex) {
00055               throw new ResourceException(ex.getMessage());
00056           }
00057       }
00058       java.sql.Connection connection = null;
00059       try {
00060           if(cxReq != null) {
00061               ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq; 
00062               connection = ds.getConnection(cx.getUser(), cx.getPassword());
00063           } else if (pc != null){
00064               connection = ds.getConnection(pc.getUserName(), new String(pc.getPassword()));
00065           } else if (mcfData.getMCFData(MCFData.USER).length() > 0){
00066               connection = ds.getConnection(mcfData.getMCFData(MCFData.USER), 
00067                                             mcfData.getMCFData(MCFData.PASSWORD));
00068           } else {
00069               connection = ds.getConnection();
00070           }
00071           trace.log(BasicLevel.DEBUG, "Connection object returned is "+connection);      
00072       }
00073       catch(SQLException sqle)
00074       {
00075           throw new ResourceAllocationException("The connection could not be allocated: " + sqle.getMessage());
00076       }
00077       return new ManagedConnectionImpl(this, pc, connection, null, null, null);
00078     }
00079 
00080     /* Determine if the factories are equal
00081      */
00082     public boolean equals(Object obj) {
00083         if (obj instanceof DataSourceMCFImpl) {
00084             return mcfData.equals(((DataSourceMCFImpl)obj).mcfData);
00085         }
00086         else {
00087             return false;
00088         }
00089     }
00090 
00091     // JOnAS JDBC RA DataSource config properties
00092     public String getDatabaseName()
00093     {
00094         return mcfData.getMCFData(MCFData.DATABASENAME);
00095     }
00096 
00097     public void setDatabaseName(String val)
00098     {
00099         mcfData.setMCFData(MCFData.DATABASENAME, val);
00100     }
00101 
00102     public String getDescription()
00103     {
00104         return mcfData.getMCFData(MCFData.DESCRIPTION);
00105     }
00106 
00107     public void setDescription(String val)
00108     {
00109         mcfData.setMCFData(MCFData.DESCRIPTION, val);
00110     }
00111 
00112     public String getPortNumber()
00113     {
00114         return mcfData.getMCFData(MCFData.PORTNUMBER);
00115     }
00116 
00117     public void setPortNumber(String val)
00118     {
00119         mcfData.setMCFData(MCFData.PORTNUMBER, val);
00120     }
00121 
00122     public String getServerName()
00123     {
00124         return mcfData.getMCFData(MCFData.SERVERNAME);
00125     }
00126 
00127     public void setServerName(String val)
00128     {
00129         mcfData.setMCFData(MCFData.SERVERNAME, val);
00130     }
00131 
00132 }

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