Search in sources :

Example 6 with JdbcResource

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

the class PersistenceManagerFactoryResourceMigrator method postConstruct.

public void postConstruct() {
    Collection<PersistenceManagerFactoryResource> pmfResources = resources.getResources(PersistenceManagerFactoryResource.class);
    for (final PersistenceManagerFactoryResource pmfResource : pmfResources) {
        String jdbcResourceName = pmfResource.getJdbcResourceJndiName();
        final JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jdbcResourceName);
        try {
            ConfigSupport.apply(new SingleConfigCode<Resources>() {

                public Object run(Resources resources) throws PropertyVetoException, TransactionFailure {
                    // delete the persitence-manager-factory resource
                    resources.getResources().remove(pmfResource);
                    // create a jdbc resource which points to same connection pool and has same jndi name as pmf resource.
                    JdbcResource newResource = resources.createChild(JdbcResource.class);
                    newResource.setJndiName(pmfResource.getJndiName());
                    newResource.setDescription("Created to migrate persistence-manager-factory-resource from V2 domain");
                    newResource.setPoolName(jdbcResource.getPoolName());
                    newResource.setEnabled("true");
                    resources.getResources().add(newResource);
                    return newResource;
                }
            }, resources);
        } catch (TransactionFailure tf) {
            Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading persistence-manager-factory-resource", tf);
            throw new RuntimeException(tf);
        }
    }
// end of iteration
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) PersistenceManagerFactoryResource(org.glassfish.connectors.config.PersistenceManagerFactoryResource) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 7 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource 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 JdbcResource

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

the class JdbcResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    // deployResource is not synchronized as there is only one caller
    // ResourceProxy which is synchronized
    JdbcResource jdbcRes = (JdbcResource) resource;
    String jndiName = jdbcRes.getJndiName();
    String poolName = jdbcRes.getPoolName();
    PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
    ResourceInfo resourceInfo = new ResourceInfo(jndiName, applicationName, moduleName);
    runtime.createConnectorResource(resourceInfo, poolInfo, null);
    // In-case the resource is explicitly created with a suffix (__nontx or __PM), no need to create one
    if (ConnectorsUtil.getValidSuffix(jndiName) == null) {
        ResourceInfo pmResourceInfo = new ResourceInfo(ConnectorsUtil.getPMJndiName(jndiName), resourceInfo.getApplicationName(), resourceInfo.getModuleName());
        runtime.createConnectorResource(pmResourceInfo, poolInfo, null);
    }
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("deployed resource " + jndiName);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 9 with JdbcResource

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

the class JdbcResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
@Override
public void deployResource(Object resource) throws Exception {
    JdbcResource jdbcRes = (JdbcResource) resource;
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcRes);
    deployResource(jdbcRes, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 10 with JdbcResource

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

the class JdbcResourcesUtil method getResourcesOfPool.

public static Collection<BindableResource> getResourcesOfPool(Resources resources, String connectionPoolName) {
    Set<BindableResource> resourcesReferringPool = new HashSet<BindableResource>();
    ResourcePool pool = (ResourcePool) getResourceByName(resources, ResourcePool.class, connectionPoolName);
    if (pool != null) {
        Collection<BindableResource> bindableResources = resources.getResources(BindableResource.class);
        for (BindableResource resource : bindableResources) {
            if (JdbcResource.class.isAssignableFrom(resource.getClass())) {
                if ((((JdbcResource) resource).getPoolName()).equals(connectionPoolName)) {
                    resourcesReferringPool.add(resource);
                }
            }
        }
    }
    return resourcesReferringPool;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) HashSet(java.util.HashSet)

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