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.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
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
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 }