00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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 }