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