1 26 package org.objectweb.jonas.jdbc; 27 28 29 import java.sql.SQLException ; 30 31 import javax.resource.ResourceException ; 32 import javax.resource.spi.ConnectionRequestInfo ; 33 import javax.resource.spi.ManagedConnection ; 34 import javax.resource.spi.ResourceAllocationException ; 35 import javax.resource.spi.security.PasswordCredential ; 36 import javax.security.auth.Subject ; 37 import javax.sql.XADataSource ; 38 39 public class XAMCFImpl 40 extends ManagedConnectionFactoryImpl { 41 42 XADataSource ds = null; 43 44 public ManagedConnection createManagedConnection(Subject subject, 45 ConnectionRequestInfo cxReq) 46 throws ResourceException { 47 48 PasswordCredential pc = Utility.getPasswordCredential(this, subject, cxReq, pw); 49 if(ds == null) { 50 try { 51 ds = (XADataSource ) Utility.getDataSource(this, pc, trace); 52 } catch(Exception ex) { 53 throw new ResourceException (ex.getMessage()); 54 } 55 } 56 javax.sql.XAConnection xaConnection = null; 57 java.sql.Connection connection = null; 58 try { 59 if(cxReq != null) { 60 ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq; 61 xaConnection = ds.getXAConnection(cx.getUser(), cx.getPassword()); 62 } else if (pc != null){ 63 xaConnection = ds.getXAConnection(pc.getUserName(), new String (pc.getPassword())); 64 } else if (mcfData.getMCFData(MCFData.USER).length() > 0){ 65 xaConnection = ds.getXAConnection(mcfData.getMCFData(MCFData.USER), 66 mcfData.getMCFData(MCFData.PASSWORD)); 67 } else { 68 xaConnection = ds.getXAConnection(); 69 } 70 if (xaConnection != null) { 71 connection = xaConnection.getConnection(); 72 } 73 } 74 catch(SQLException sqle) 75 { 76 throw new ResourceAllocationException ("The connection could not be allocated: " + sqle.getMessage()); 77 } 78 return new ManagedConnectionImpl(this, pc, connection, null, xaConnection, null); 79 } 80 81 83 public boolean equals(Object obj) { 84 if (obj instanceof XAMCFImpl) { 85 return mcfData.equals(((XAMCFImpl)obj).mcfData); 86 } 87 else { 88 return false; 89 } 90 } 91 92 public String getDatabaseName() 94 { 95 return mcfData.getMCFData(MCFData.DATABASENAME); 96 } 97 98 public void setDatabaseName(String val) 99 { 100 mcfData.setMCFData(MCFData.DATABASENAME, val); 101 } 102 103 public String getDescription() 104 { 105 return mcfData.getMCFData(MCFData.DESCRIPTION); 106 } 107 108 public void setDescription(String val) 109 { 110 mcfData.setMCFData(MCFData.DESCRIPTION, val); 111 } 112 113 public String getPortNumber() 114 { 115 return mcfData.getMCFData(MCFData.PORTNUMBER); 116 } 117 118 public void setPortNumber(String val) 119 { 120 mcfData.setMCFData(MCFData.PORTNUMBER, val); 121 } 122 123 public String getServerName() 124 { 125 return mcfData.getMCFData(MCFData.SERVERNAME); 126 } 127 128 public void setServerName(String val) 129 { 130 mcfData.setMCFData(MCFData.SERVERNAME, val); 131 } 132 133 } | Popular Tags |