1 23 24 package com.sun.gjc.spi; 25 26 import javax.resource.ResourceException ; 27 import javax.resource.spi.ConnectionRequestInfo ; 28 import javax.resource.spi.security.PasswordCredential ; 29 import com.sun.gjc.common.DataSourceObjectBuilder; 30 import com.sun.gjc.util.SecurityUtils; 31 import com.sun.logging.*; 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import com.sun.enterprise.util.i18n.StringManager; 35 import javax.resource.spi.ResourceAllocationException ; 36 37 43 44 public class DSManagedConnectionFactory extends ManagedConnectionFactory { 45 46 private transient javax.sql.DataSource dataSourceObj; 47 48 private static Logger _logger; 49 static { 50 _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER ); 51 } 52 53 70 public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, 71 ConnectionRequestInfo cxRequestInfo) throws ResourceException { 72 if(logWriter != null) { 73 logWriter.println("In createManagedConnection"); 74 } 75 PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo); 76 77 if(dataSourceObj == null) { 78 if(dsObjBuilder == null) { 79 dsObjBuilder = new DataSourceObjectBuilder(spec); 80 } 81 82 try { 83 dataSourceObj = (javax.sql.DataSource ) dsObjBuilder.constructDataSourceObject(); 84 } catch(ClassCastException cce) { 85 _logger.log(Level.SEVERE, "jdbc.exc_cce", cce); 86 throw new javax.resource.ResourceException (cce.getMessage()); 87 } 88 } 89 90 java.sql.Connection dsConn = null; 91 92 try { 93 98 99 if ( isEqual( pc, getUser(), getPassword() ) ) { 100 dsConn = dataSourceObj.getConnection(); 101 } else { 102 dsConn = dataSourceObj.getConnection(pc.getUserName(), 103 new String (pc.getPassword())); 104 } 105 } catch(java.sql.SQLException sqle) { 106 _logger.log(Level.FINE, "jdbc.exc_create_conn", sqle.getMessage()); 108 StringManager localStrings = 109 StringManager.getManager( DataSourceObjectBuilder.class ); 110 String msg = localStrings.getString( "jdbc.cannot_allocate_connection" 111 ,sqle.getMessage()); 112 ResourceAllocationException rae = new ResourceAllocationException ( msg ); 113 rae.initCause( sqle ); 114 throw rae; 115 } 116 117 com.sun.gjc.spi.ManagedConnection mc = constructManagedConnection( 118 null, dsConn, pc, this); 119 120 validateAndSetIsolation( mc ); 122 123 return mc; 124 } 125 126 135 public boolean equals(Object other) { 136 if(logWriter != null) { 137 logWriter.println("In equals"); 138 } 139 143 if(other instanceof com.sun.gjc.spi.DSManagedConnectionFactory) { 144 com.sun.gjc.spi.DSManagedConnectionFactory otherMCF = 145 (com.sun.gjc.spi.DSManagedConnectionFactory) other; 146 return this.spec.equals(otherMCF.spec); 147 } 148 return false; 149 } 150 } 151 | Popular Tags |