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.ConnectionPoolDataSource ; 38 39 45 public class ConnectionPoolMCFImpl 46 extends ManagedConnectionFactoryImpl { 47 48 49 ConnectionPoolDataSource ds = null; 50 51 public ManagedConnection createManagedConnection(Subject subject, 52 ConnectionRequestInfo cxReq) 53 throws ResourceException { 54 55 PasswordCredential pc = Utility.getPasswordCredential(this, subject, cxReq, pw); 56 if(ds == null) { 57 try { 58 ds = (ConnectionPoolDataSource ) Utility.getDataSource(this, pc, trace); 59 } catch(Exception ex) { 60 throw new ResourceException (ex.getMessage()); 61 } 62 } 63 64 javax.sql.PooledConnection pConnection = null; 65 java.sql.Connection connection = null; 66 try { 67 if(cxReq != null) { 68 ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq; 69 pConnection = ds.getPooledConnection(cx.getUser(), cx.getPassword()); 70 } else if (pc != null){ 71 pConnection = ds.getPooledConnection(pc.getUserName(), new String (pc.getPassword())); 72 } else if (mcfData.getMCFData(MCFData.USER).length() > 0){ 73 pConnection = ds.getPooledConnection(mcfData.getMCFData(MCFData.USER), 74 mcfData.getMCFData(MCFData.PASSWORD)); 75 } else { 76 pConnection = ds.getPooledConnection(); 77 } 78 if (pConnection != null) { 79 connection = pConnection.getConnection(); 80 } 81 } 82 catch(SQLException sqle) 83 { 84 throw new ResourceAllocationException ("The connection could not be allocated: " + sqle.getMessage()); 85 } 86 return new ManagedConnectionImpl(this, pc, connection, pConnection, null, null); 87 } 88 89 91 public boolean equals(Object obj) { 92 if (obj instanceof ConnectionPoolMCFImpl) { 93 return mcfData.equals(((ConnectionPoolMCFImpl)obj).mcfData); 94 } 95 else { 96 return false; 97 } 98 } 99 100 public String getDatabaseName() 102 { 103 return mcfData.getMCFData(MCFData.DATABASENAME); 104 } 105 106 public void setDatabaseName(String val) 107 { 108 mcfData.setMCFData(MCFData.DATABASENAME, val); 109 } 110 111 public String getDescription() 112 { 113 return mcfData.getMCFData(MCFData.DESCRIPTION); 114 } 115 116 public void setDescription(String val) 117 { 118 mcfData.setMCFData(MCFData.DESCRIPTION, val); 119 } 120 121 public String getPortNumber() 122 { 123 return mcfData.getMCFData(MCFData.PORTNUMBER); 124 } 125 126 public void setPortNumber(String val) 127 { 128 mcfData.setMCFData(MCFData.PORTNUMBER, val); 129 } 130 131 public String getServerName() 132 { 133 return mcfData.getMCFData(MCFData.SERVERNAME); 134 } 135 136 public void setServerName(String val) 137 { 138 mcfData.setMCFData(MCFData.SERVERNAME, val); 139 } 140 141 } | Popular Tags |