FileDocCategorySizeDatePackage
DSManagedConnectionFactory.javaAPI DocGlassfish v2 API7416Fri May 04 22:36:04 BST 2007com.sun.gjc.spi

DSManagedConnectionFactory

public class DSManagedConnectionFactory extends ManagedConnectionFactory
Data Source ManagedConnectionFactory implementation for Generic JDBC Connector.
author
Evani Sai Surya Kiran
version
1.0, 02/07/30

Fields Summary
private transient DataSource
dataSourceObj
private static Logger
_logger
Constructors Summary
Methods Summary
public javax.resource.spi.ManagedConnectioncreateManagedConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
Creates a new physical connection to the underlying EIS resource manager.

param
subject Subject instance passed by the application server
param
cxRequestInfo ConnectionRequestInfo which may be created as a result of the invocation getConnection(user, password) on the DataSource object
return
ManagedConnection object created
throws
ResourceException if there is an error in instantiating the DataSource object used for the creation of the ManagedConnection object
throws
SecurityException if there ino PasswordCredential object satisfying this request
throws
ResourceAllocationException if there is an error in allocating the physical connection

        _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
    
        if (logWriter != null) {
            logWriter.println("In createManagedConnection");
        }
        PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);

        javax.sql.DataSource dataSource = getDataSource();

        java.sql.Connection dsConn = null;

        try {
            /* For the case where the user/passwd of the connection pool is
            * equal to the PasswordCredential for the connection request
            * get a connection from this pool directly.
            * for all other conditions go create a new connection
            */

            if (isEqual(pc, getUser(), getPassword())) {
                dsConn = dataSource.getConnection();
            } else {
                dsConn = dataSource.getConnection(pc.getUserName(),
                        new String(pc.getPassword()));
            }
        } catch (java.sql.SQLException sqle) {
            //_logger.log(Level.WARNING, "jdbc.exc_create_conn", sqle.getMessage());
            _logger.log(Level.FINE, "jdbc.exc_create_conn", sqle.getMessage());
            StringManager localStrings =
                    StringManager.getManager(DataSourceObjectBuilder.class);
            String msg = localStrings.getString("jdbc.cannot_allocate_connection"
                    , sqle.getMessage());
            ResourceAllocationException rae = new ResourceAllocationException(msg);
            rae.initCause(sqle);
            throw rae;
        }

        com.sun.gjc.spi.ManagedConnection mc = constructManagedConnection(
                null, dsConn, pc, this);

        //GJCINT
        validateAndSetIsolation(mc);

        return mc;
    
public booleanequals(java.lang.Object other)
Check if this ManagedConnectionFactory is equal to another ManagedConnectionFactory.

param
other ManagedConnectionFactory object for checking equality with
return
true if the property sets of both the ManagedConnectionFactory objects are the same false otherwise

        if (logWriter != null) {
            logWriter.println("In equals");
        }
        /**
         * The check below means that two ManagedConnectionFactory objects are equal
         * if and only if their properties are the same.
         */
        if (other instanceof com.sun.gjc.spi.DSManagedConnectionFactory) {
            com.sun.gjc.spi.DSManagedConnectionFactory otherMCF =
                    (com.sun.gjc.spi.DSManagedConnectionFactory) other;
            return this.spec.equals(otherMCF.spec);
        }
        return false;
    
public javax.sql.DataSourcegetDataSource()
Returns the underlying datasource

return
DataSource of jdbc vendor
throws
ResourceException

        if (dataSourceObj == null) {
            try {
                dataSourceObj = (javax.sql.DataSource) super.getDataSource();
            } catch (ClassCastException cce) {
                _logger.log(Level.SEVERE, "jdbc.exc_cce", cce);
                throw new ResourceException(cce.getMessage());
            }
        }
        return dataSourceObj;