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