Search in sources :

Example 31 with JdbcResource

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

the class JdbcResourcesUtil method isJdbcPoolReferredInServerInstance.

/**
 * Determines if a JDBC connection pool is referred in a
 * server-instance via resource-refs
 * @param poolInfo pool-name
 * @return boolean true if pool is referred in this server instance as well enabled, false
 * otherwise
 */
public boolean isJdbcPoolReferredInServerInstance(PoolInfo poolInfo) {
    Collection<JdbcResource> jdbcResources = getRuntime().getResources(poolInfo).getResources(JdbcResource.class);
    for (JdbcResource resource : jdbcResources) {
        ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
        // Have to check isReferenced here!
        if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) && ResourcesUtil.createInstance().isReferenced(resourceInfo) && ResourcesUtil.createInstance().isEnabled(resource)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("pool " + poolInfo + "resource " + resourceInfo + " referred " + ResourcesUtil.createInstance().isReferenced(resourceInfo));
                _logger.fine("JDBC resource " + resource.getJndiName() + "refers " + poolInfo + "in this server instance and is enabled");
            }
            return true;
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("No JDBC resource refers [ " + poolInfo + " ] in this server instance");
    }
    return false;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 32 with JdbcResource

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

the class JdbcRecoveryResourceHandler method getAllJdbcResources.

private Collection<JdbcResource> getAllJdbcResources() {
    Collection<JdbcResource> allResources = new ArrayList<JdbcResource>();
    Collection<JdbcResource> jdbcResources = domain.getResources().getResources(JdbcResource.class);
    allResources.addAll(jdbcResources);
    for (Application app : applications.getApplications()) {
        if (ResourcesUtil.createInstance().isEnabled(app)) {
            Resources appScopedResources = app.getResources();
            if (appScopedResources != null && appScopedResources.getResources() != null) {
                allResources.addAll(appScopedResources.getResources(JdbcResource.class));
            }
            List<Module> modules = app.getModule();
            if (modules != null) {
                for (Module module : modules) {
                    Resources msr = module.getResources();
                    if (msr != null && msr.getResources() != null) {
                        allResources.addAll(msr.getResources(JdbcResource.class));
                    }
                }
            }
        }
    }
    return allResources;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) ArrayList(java.util.ArrayList) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application)

Example 33 with JdbcResource

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

the class JdbcRuntimeExtension method getDeferredResourceConfig.

@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
    String resourceAdapterName;
    DeferredResourceConfig resConfig = null;
    // TODO V3 (not to hold specific resource types)
    if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
        JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
        JdbcResource jdbcResource = (JdbcResource) resource;
        resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
        resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
        Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
        resConfig.setResourcesToLoad(resourcesToload);
    } else {
        throw new ConnectorRuntimeException("unsupported resource type : " + resource);
    }
    return resConfig;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) JdbcResource(org.glassfish.jdbc.config.JdbcResource) DeferredResourceConfig(com.sun.enterprise.connectors.DeferredResourceConfig) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 34 with JdbcResource

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

the class JdbcRuntimeExtension method getPoolNameFromResourceJndiName.

/**
 * Gets the Pool name that this JDBC resource points to. In case of a PMF resource
 * gets the pool name of the pool pointed to by jdbc resource being pointed to by
 * the PMF resource
 *
 * @param resourceInfo the jndi name of the resource being used to get Connection from
 *                 This resource can either be a pmf resource or a jdbc resource
 * @return poolName of the pool that this resource directly/indirectly points to
 */
@Override
public PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
    PoolInfo poolInfo = null;
    JdbcResource jdbcResource = null;
    String jndiName = resourceInfo.getName();
    ResourceInfo actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo), JdbcResource.class, actualResourceInfo.getName());
    if (jdbcResource == null) {
        String suffix = ConnectorsUtil.getValidSuffix(jndiName);
        if (suffix != null) {
            jndiName = jndiName.substring(0, jndiName.lastIndexOf(suffix));
            actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
        }
    }
    jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo), JdbcResource.class, actualResourceInfo.getName());
    if (jdbcResource != null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("jdbcRes is ---: " + jdbcResource.getJndiName());
            logger.fine("poolName is ---: " + jdbcResource.getPoolName());
        }
    }
    if (jdbcResource != null) {
        poolInfo = new PoolInfo(jdbcResource.getPoolName(), actualResourceInfo.getApplicationName(), actualResourceInfo.getModuleName());
    }
    return poolInfo;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 35 with JdbcResource

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

the class ReferenceConstrainTest method doChangeToValidPool.

// @Ignore
@Test
public void doChangeToValidPool() throws TransactionFailure {
    Domain domain = habitat.getService(Domain.class);
    // Find JdbcResource to chenge its values
    Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
    JdbcResource jdbc = null;
    while (iterator.hasNext()) {
        JdbcResource res = iterator.next();
        if ("__TimerPool".equals(res.getPoolName())) {
            jdbc = res;
            break;
        }
    }
    assertNotNull(jdbc);
    ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("pool-name", "DerbyPool");
    changes.put(poolConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
    } catch (TransactionFailure tf) {
        fail();
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) ConfigBean(org.jvnet.hk2.config.ConfigBean) Domain(com.sun.enterprise.config.serverbeans.Domain) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(org.glassfish.jdbcruntime.config.ConfigApiTest) Test(org.junit.Test)

Aggregations

JdbcResource (org.glassfish.jdbc.config.JdbcResource)35 Test (org.junit.Test)12 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)9 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)7 Resource (com.sun.enterprise.config.serverbeans.Resource)6 Resources (com.sun.enterprise.config.serverbeans.Resources)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Domain (com.sun.enterprise.config.serverbeans.Domain)4 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)4 PropertyVetoException (java.beans.PropertyVetoException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 XAResource (javax.transaction.xa.XAResource)2 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)1