Search in sources :

Example 6 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolDeployer method actualDeployResource.

/**
 * Deploy the resource into the server's runtime naming context
 *
 * @param resource a resource object
 * @throws Exception thrown if fail
 */
public void actualDeployResource(Object resource, PoolInfo poolInfo) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(" JdbcConnectionPoolDeployer - actualDeployResource : " + poolInfo);
    }
    JdbcConnectionPool adminPool = (JdbcConnectionPool) resource;
    try {
        ConnectorConnectionPool connConnPool = createConnectorConnectionPool(adminPool, poolInfo);
        registerTransparentDynamicReconfigPool(poolInfo, adminPool);
        // now do internal book keeping
        runtime.createConnectorConnectionPool(connConnPool);
    } catch (Exception e) {
        Object[] params = new Object[] { poolInfo, e };
        _logger.log(Level.WARNING, "error.creating.jdbc.pool", params);
    }
}
Also used : ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) MissingResourceException(java.util.MissingResourceException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 7 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class DataSourceDefinitionDeployer method deployResource.

@Override
public void deployResource(Object resource) throws Exception {
    final DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) resource;
    String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), DSDPOOL);
    String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "DataSourceDefinitionDeployer.deployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
    }
    JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName);
    // deploy pool
    getDeployer(jdbcCp).deployResource(jdbcCp);
    // deploy resource
    JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName);
    getDeployer(jdbcResource).deployResource(jdbcResource);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) DataSourceDefinitionDescriptor(com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)

Example 8 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcRecoveryResourceHandler method loadXAResourcesAndItsConnections.

/**
 * {@inheritDoc}
 */
@Override
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
    // Done so as to initialize connectors-runtime before loading jdbc-resources. need a better way ?
    ConnectorRuntime crt = connectorRuntimeProvider.get();
    Collection<JdbcResource> jdbcResources = getAllJdbcResources();
    if (jdbcResources == null || jdbcResources.size() == 0) {
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("loadXAResourcesAndItsConnections : no resources");
        }
        return;
    }
    List<JdbcConnectionPool> jdbcPools = new ArrayList<JdbcConnectionPool>();
    for (Resource resource : jdbcResources) {
        JdbcResource jdbcResource = (JdbcResource) resource;
        if (getResourcesUtil().isEnabled(jdbcResource)) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
            JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
            if (pool != null && "javax.sql.XADataSource".equals(pool.getResType())) {
                jdbcPools.add(pool);
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: " + "adding : " + (jdbcResource.getPoolName()));
            }
        }
    }
    loadAllJdbcResources();
    // Read from the transaction-service , if the replacement of
    // Vendor XAResource class with our version required.
    // If yes, put the mapping in the xaresourcewrappers properties.
    Properties XAResourceWrappers = new Properties();
    XAResourceWrappers.put("oracle.jdbc.xa.client.OracleXADataSource", "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
    Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    txService = c.getExtensionByType(TransactionService.class);
    List<Property> properties = txService.getProperty();
    if (properties != null) {
        for (Property property : properties) {
            String name = property.getName();
            String value = property.getValue();
            if (name.equals("oracle-xa-recovery-workaround")) {
                if ("false".equals(value)) {
                    XAResourceWrappers.remove("oracle.jdbc.xa.client.OracleXADataSource");
                }
            } else if (name.equals("sybase-xa-recovery-workaround")) {
                if (value.equals("true")) {
                    XAResourceWrappers.put("com.sybase.jdbc2.jdbc.SybXADataSource", "com.sun.enterprise.transaction.jts.recovery.SybaseXAResource");
                }
            }
        }
    }
    for (JdbcConnectionPool jdbcConnectionPool : jdbcPools) {
        if (jdbcConnectionPool.getResType() == null || jdbcConnectionPool.getName() == null || !jdbcConnectionPool.getResType().equals("javax.sql.XADataSource")) {
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.finest("skipping pool : " + jdbcConnectionPool.getName());
            }
            continue;
        }
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest(" using pool : " + jdbcConnectionPool.getName());
        }
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnectionPool);
        try {
            String[] dbUserPassword = getdbUserPasswordOfJdbcConnectionPool(jdbcConnectionPool);
            String dbUser = dbUserPassword[0];
            String dbPassword = dbUserPassword[1];
            if (dbPassword == null) {
                dbPassword = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
                }
            }
            if (dbUser == null) {
                dbUser = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
                }
            }
            ManagedConnectionFactory fac = crt.obtainManagedConnectionFactory(poolInfo);
            Subject subject = new Subject();
            PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
            pc.setManagedConnectionFactory(fac);
            Principal prin = new ResourcePrincipal(dbUser, dbPassword);
            subject.getPrincipals().add(prin);
            subject.getPrivateCredentials().add(pc);
            ManagedConnection mc = fac.createManagedConnection(subject, null);
            connList.add(mc);
            try {
                XAResource xares = mc.getXAResource();
                if (xares != null) {
                    // See if a wrapper class for the vendor XADataSource is
                    // specified if yes, replace the XAResouce class of database
                    // vendor with our own version
                    String datasourceClassname = jdbcConnectionPool.getDatasourceClassname();
                    String wrapperclass = (String) XAResourceWrappers.get(datasourceClassname);
                    if (wrapperclass != null) {
                        // need to load wrapper class provided by "transactions" module.
                        // Using connector-class-loader so as to get access to "transaction" module.
                        XAResourceWrapper xaresWrapper = null;
                        xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).newInstance();
                        xaresWrapper.init(mc, subject);
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.finest("adding resource " + poolInfo + " -- " + xaresWrapper);
                        }
                        xaresList.add(xaresWrapper);
                    } else {
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.finest("adding resource " + poolInfo + " -- " + xares);
                        }
                        xaresList.add(xares);
                    }
                }
            } catch (ResourceException ex) {
                _logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
                }
            // ignored. Not at XA_TRANSACTION level
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
            }
        }
    }
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) PasswordCredential(javax.resource.spi.security.PasswordCredential) Properties(java.util.Properties) XAResourceWrapper(com.sun.enterprise.transaction.api.XAResourceWrapper) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) Property(org.jvnet.hk2.config.types.Property) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) TransactionService(com.sun.enterprise.transaction.config.TransactionService) XAResource(javax.transaction.xa.XAResource) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Subject(javax.security.auth.Subject) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) XAResource(javax.transaction.xa.XAResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime)

Example 9 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcResourcesUtil method getJdbcConnectionPoolOfResource.

public JdbcConnectionPool getJdbcConnectionPoolOfResource(ResourceInfo resourceInfo) {
    JdbcResource resource = null;
    JdbcConnectionPool pool = null;
    Resources resources = getResources(resourceInfo);
    if (resources != null) {
        resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, resourceInfo.getName());
        if (resource != null) {
            pool = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, resource.getPoolName());
        }
    }
    return pool;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 10 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcPoolMonitoringExtension method registerConnectionPool.

/**
 * Register the jdbc connection pool Stats Provider object to the
 * monitoring framework under the specific application name monitoring
 * sub tree.
 *
 * @param appName
 * @return
 */
@Override
public ConnectionPoolAppProbeProvider registerConnectionPool(PoolInfo poolInfo, String appName) {
    ConnectionPoolAppProbeProvider probeAppProvider = null;
    ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
    if (pool instanceof JdbcConnectionPool) {
        probeAppProvider = new JdbcConnPoolAppProbeProvider();
        JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider = new JdbcConnPoolAppStatsProvider(poolInfo, appName);
        StatsProviderManager.register("jdbc-connection-pool", PluginPoint.SERVER, "resources/" + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName()) + "/" + appName, jdbcPoolAppStatsProvider);
        jdbcPoolAppStatsProviders.add(jdbcPoolAppStatsProvider);
    }
    return probeAppProvider;
}
Also used : JdbcConnPoolAppStatsProvider(org.glassfish.jdbc.pool.monitor.JdbcConnPoolAppStatsProvider) ConnectionPoolAppProbeProvider(com.sun.enterprise.resource.pool.monitor.ConnectionPoolAppProbeProvider) JdbcConnPoolAppProbeProvider(org.glassfish.jdbc.pool.monitor.JdbcConnPoolAppProbeProvider) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool)

Aggregations

JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)32 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)10 JdbcResource (org.glassfish.jdbc.config.JdbcResource)7 Test (org.junit.Test)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ActionReport (org.glassfish.api.ActionReport)3 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)2 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 ArrayList (java.util.ArrayList)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 DataSource (javax.sql.DataSource)2 XADataSource (javax.sql.XADataSource)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 Property (org.jvnet.hk2.config.types.Property)2