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

CPManagedConnectionFactory

public class CPManagedConnectionFactory extends ManagedConnectionFactory
Connection Pool ManagedConnectionFactory implementation for Generic JDBC Connector.
author
Evani Sai Surya Kiran
version
1.0, 02/07/30

Fields Summary
private transient ConnectionPoolDataSource
cpDataSourceObj
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

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

        javax.sql.ConnectionPoolDataSource dataSource = getDataSource();

        javax.sql.PooledConnection cpConn = 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())) {
                cpConn = dataSource.getPooledConnection();
            } else {
                cpConn = dataSource.getPooledConnection(pc.getUserName(),
                        new String(pc.getPassword()));
            }

        } catch (java.sql.SQLException sqle) {
            //_logger.log(Level.SEVERE, "jdbc.exc_create_ds_conn",sqle);
            _logger.log(Level.FINE, "jdbc.exc_create_ds_conn", sqle);
            StringManager sm =
                    StringManager.getManager(DataSourceObjectBuilder.class);
            String msg = sm.getString("jdbc.cannot_allocate_connection", sqle.getMessage());
            ResourceAllocationException rae = new ResourceAllocationException(
                    msg, sqle);
            throw rae;
        }


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

        mc.initializeConnectionType(ManagedConnection.ISPOOLEDCONNECTION);

        //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.CPManagedConnectionFactory) {
            com.sun.gjc.spi.CPManagedConnectionFactory otherMCF =
                    (com.sun.gjc.spi.CPManagedConnectionFactory) other;
            return this.spec.equals(otherMCF.spec);
        }
        return false;
    
public javax.sql.ConnectionPoolDataSourcegetDataSource()
Returns the underlying datasource

return
DataSource of jdbc vendor
throws
ResourceException

        _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
    
        if (cpDataSourceObj == null) {
            try {
                cpDataSourceObj = (javax.sql.ConnectionPoolDataSource) super.getDataSource();
            } catch (ClassCastException cce) {
                _logger.log(Level.SEVERE, "jdbc.exc_cce_CP", cce);
                throw new ResourceException(cce.getMessage());
            }
        }
        return cpDataSourceObj;
    
public java.lang.StringgetInitialPoolSize()
Gets the initial pool size.

return
initPoolSz
see
setInitialPoolSize

        return spec.getDetail(DataSourceSpec.INITIALPOOLSIZE);
    
public java.lang.StringgetMaxIdleTime()
Gets the maximum idle time.

return
maxIdleTime
see
setMaxIdleTime

        return spec.getDetail(DataSourceSpec.MAXIDLETIME);
    
public java.lang.StringgetMaxPoolSize()
Gets the maximum pool size.

return
maxPoolSz
see
setMaxPoolSize

        return spec.getDetail(DataSourceSpec.MAXPOOLSIZE);
    
public java.lang.StringgetMaxStatements()
Gets the max statements.

return
maxStmts
see
setMaxStatements

        return spec.getDetail(DataSourceSpec.MAXSTATEMENTS);
    
public java.lang.StringgetMinPoolSize()
Gets the minimum pool size.

return
minPoolSz
see
setMinPoolSize

        return spec.getDetail(DataSourceSpec.MINPOOLSIZE);
    
public java.lang.StringgetPropertyCycle()
Gets the property cycle.

return
propCycle
see
setPropertyCycle

        return spec.getDetail(DataSourceSpec.PROPERTYCYCLE);
    
public voidsetInitialPoolSize(java.lang.String initPoolSz)
Sets the initial pool size.

param
initPoolSz String
see
getInitialPoolSize

        spec.setDetail(DataSourceSpec.INITIALPOOLSIZE, initPoolSz);
    
public voidsetMaxIdleTime(java.lang.String maxIdleTime)
Sets the maximum idle time.

param
maxIdleTime String
see
getMaxIdleTime

        spec.setDetail(DataSourceSpec.MAXIDLETIME, maxIdleTime);
    
public voidsetMaxPoolSize(java.lang.String maxPoolSz)
Sets the maximum pool size.

param
maxPoolSz String
see
getMaxPoolSize

        spec.setDetail(DataSourceSpec.MAXPOOLSIZE, maxPoolSz);
    
public voidsetMaxStatements(java.lang.String maxStmts)
Sets the max statements.

param
maxStmts String
see
getMaxStatements

        spec.setDetail(DataSourceSpec.MAXSTATEMENTS, maxStmts);
    
public voidsetMinPoolSize(java.lang.String minPoolSz)
Sets the minimum pool size.

param
minPoolSz String
see
getMinPoolSize

        spec.setDetail(DataSourceSpec.MINPOOLSIZE, minPoolSz);
    
public voidsetPropertyCycle(java.lang.String propCycle)
Sets the property cycle.

param
propCycle String
see
getPropertyCycle

        spec.setDetail(DataSourceSpec.PROPERTYCYCLE, propCycle);