Search in sources :

Example 1 with ResourceAllocationException

use of javax.resource.spi.ResourceAllocationException in project Payara by payara.

the class CPManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.ConnectionPoolDataSource dataSource = getDataSource();
    javax.sql.PooledConnection cpConn = null;
    ManagedConnectionImpl mc = 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
            */
        String user = getUser();
        if (user == null || isEqual(pc, user, 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);
        if (_logger.isLoggable(Level.FINE)) {
            _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;
    }
    try {
        mc = constructManagedConnection(cpConn, null, pc, this);
        mc.initializeConnectionType(ManagedConnectionImpl.ISPOOLEDCONNECTION);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (cpConn != null) {
                try {
                    cpConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : createManagedConnection" + cpConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 2 with ResourceAllocationException

use of javax.resource.spi.ResourceAllocationException in project Payara by payara.

the class DSManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.DataSource dataSource = getDataSource();
    java.sql.Connection dsConn = null;
    ManagedConnectionImpl mc = 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
            */
        String user = getUser();
        if (user == null || isEqual(pc, user, 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());
        if (_logger.isLoggable(Level.FINE)) {
            _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;
    }
    try {
        mc = constructManagedConnection(null, dsConn, pc, this);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (dsConn != null) {
                try {
                    dsConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : " + "createManagedConnection" + dsConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 3 with ResourceAllocationException

use of javax.resource.spi.ResourceAllocationException in project Payara by payara.

the class ManagedConnectionFactoryImpl method validateAndSetIsolation.

/**
 * Common operation performed by all the child MCFs before returning a created mc
 */
protected void validateAndSetIsolation(ManagedConnectionImpl mc) throws ResourceException {
    try {
        isValid(mc);
        setIsolation(mc);
    } catch (ResourceException e) {
        if (mc != null) {
            try {
                mc.destroy();
            } catch (ResourceException e1) {
                _logger.log(Level.WARNING, "jdbc.exc_destroy", e1);
            }
        }
        String msg = localStrings.getString("jdbc.exc_destroy", e.getMessage());
        ResourceAllocationException rae = new ResourceAllocationException(msg, e);
        throw rae;
    }
}
Also used : ResourceException(javax.resource.ResourceException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 4 with ResourceAllocationException

use of javax.resource.spi.ResourceAllocationException in project Payara by payara.

the class ConnectorXAResource method getResourceHandle.

private ResourceHandle getResourceHandle(boolean beginTxIfNeeded) throws PoolingException {
    try {
        ResourceHandle h = null;
        JavaEETransaction j2eetran = getCurrentTransaction();
        if (j2eetran == null) {
            // Only if some thing is wrong with tx manager.
            // Just return the local handle.
            h = localHandle_;
        } else {
            h = (ResourceHandle) j2eetran.getNonXAResource();
            // can be acquired. If the resource in question is not the one in transaction, fail
            if (!localHandle_.isShareable()) {
                if (h != localHandle_) {
                    throw new ResourceAllocationException("Cannot use more than one local-tx resource in unshareable scope");
                }
            }
        }
        if (beginTxIfNeeded && h.getResourceState().isUnenlisted()) {
            ManagedConnection mc = (ManagedConnection) h.getResource();
            // begin the local transaction if first time
            // this ManagedConnection is used in this JTA transaction
            mc.getLocalTransaction().begin();
        }
        return h;
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "poolmgr.system_exception", ex);
        throw new PoolingException(ex.toString(), ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 5 with ResourceAllocationException

use of javax.resource.spi.ResourceAllocationException in project Payara by payara.

the class XAManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential passwordCredential = getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.XADataSource dataSource = getDataSource();
    javax.sql.XAConnection xaConn = 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
            */
        String user = getUser();
        if (user == null || isEqual(passwordCredential, user, getPassword())) {
            xaConn = dataSource.getXAConnection();
        } else {
            xaConn = dataSource.getXAConnection(passwordCredential.getUserName(), new String(passwordCredential.getPassword()));
        }
    } catch (java.sql.SQLException sqle) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "jdbc.exc_create_xa_conn", sqle);
        }
        StringManager sm = StringManager.getManager(DataSourceObjectBuilder.class);
        String msg = sm.getString("jdbc.cannot_allocate_connection", sqle.getMessage());
        throw new ResourceAllocationException(msg, sqle);
    }
    ManagedConnectionImpl mc = null;
    try {
        mc = constructManagedConnection(xaConn, null, passwordCredential, this);
        mc.initializeConnectionType(ManagedConnectionImpl.ISXACONNECTION);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (xaConn != null) {
                try {
                    xaConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : createManagedConnection" + xaConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) SecurityUtils.getPasswordCredential(com.sun.gjc.util.SecurityUtils.getPasswordCredential) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Aggregations

ResourceAllocationException (javax.resource.spi.ResourceAllocationException)5 StringManager (com.sun.enterprise.util.i18n.StringManager)3 DataSourceObjectBuilder (com.sun.gjc.common.DataSourceObjectBuilder)3 SQLException (java.sql.SQLException)3 PasswordCredential (javax.resource.spi.security.PasswordCredential)3 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)1 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)1 SecurityUtils.getPasswordCredential (com.sun.gjc.util.SecurityUtils.getPasswordCredential)1 ResourceException (javax.resource.ResourceException)1 ManagedConnection (javax.resource.spi.ManagedConnection)1 SystemException (javax.transaction.SystemException)1 XAException (javax.transaction.xa.XAException)1