Search in sources :

Example 26 with JdbcResource

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

the class CreateJdbcResourceTest method testExecuteFailDuplicateResource.

/**
 * Test of execute method, of class CreateJdbcResource.
 * asadmin create-jdbc-resource --connectionpoolid DerbyPool --enabled=true
 *         --description "my resource" dupRes
 * asadmin create-jdbc-resource --connectionpoolid DerbyPool --enabled=true
 *         --description "my resource" dupRes
 */
@Test
public void testExecuteFailDuplicateResource() {
    // Set operand
    parameters.set("DEFAULT", "dupRes");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was created
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                isCreated = true;
                logger.fine("JdbcResource config bean dupRes is created.");
                continue;
            }
        }
    }
    assertTrue(isCreated);
    // Try to create a duplicate resource dupRes. Get a new instance of the command.
    CreateJdbcResource command2 = habitat.getService(CreateJdbcResource.class);
    cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
    // Check the exit code is FAILURE
    assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
    // Check that the 2nd resource was NOT created
    int numDupRes = 0;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                numDupRes = numDupRes + 1;
            }
        }
    }
    assertEquals(1, numDupRes);
    // Check the error message
    assertEquals("A JdbcResource by name dupRes already exists with resource-ref in target server.", context.getActionReport().getMessage());
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 27 with JdbcResource

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

the class ConcurrentModificationsTest method collectionTest.

@Test(expected = TransactionFailure.class)
public void collectionTest() throws TransactionFailure {
    ServiceLocator habitat = super.getHabitat();
    final Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    assertTrue(resources != null);
    ConfigSupport.apply(new SingleConfigCode<Resources>() {

        public Object run(Resources writeableResources) throws PropertyVetoException, TransactionFailure {
            assertTrue(writeableResources != null);
            JdbcResource newResource = writeableResources.createChild(JdbcResource.class);
            newResource.setJndiName("foo");
            newResource.setDescription("Random ");
            newResource.setPoolName("bar");
            newResource.setEnabled("true");
            writeableResources.getResources().add(newResource);
            // now let's check I have my copy...
            boolean found = false;
            for (Resource resource : writeableResources.getResources()) {
                if (resource instanceof JdbcResource) {
                    JdbcResource jdbc = (JdbcResource) resource;
                    if (jdbc.getJndiName().equals("foo")) {
                        found = true;
                        break;
                    }
                }
            }
            assertTrue(found);
            // now let's check that my readonly copy does not see it...
            boolean shouldNot = false;
            for (Resource resource : resources.getResources()) {
                if (resource instanceof JdbcResource) {
                    JdbcResource jdbc = (JdbcResource) resource;
                    if (jdbc.getJndiName().equals("foo")) {
                        shouldNot = true;
                        break;
                    }
                }
            }
            assertFalse(shouldNot);
            // now I am throwing a transaction failure since I don't care about saving it
            throw new TransactionFailure("Test passed", null);
        }
    }, resources);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain) Test(org.junit.Test)

Example 28 with JdbcResource

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

the class DataSourceDefinitionDeployer method undeployResource.

@Override
public void undeployResource(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(FINE)) {
        _logger.log(FINE, "DataSourceDefinitionDeployer.undeployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
    }
    // Undeploy resource
    JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName);
    getDeployer(jdbcResource).undeployResource(jdbcResource);
    // Undeploy pool
    JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName);
    getDeployer(jdbcCp).undeployResource(jdbcCp);
    desc.setDeployed(false);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) DataSourceDefinitionDescriptor(com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)

Example 29 with JdbcResource

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

the class JdbcResourceDeployer method undeployResource.

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

Example 30 with JdbcResource

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

the class JdbcResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
    JdbcResource jdbcRes = (JdbcResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(jdbcRes.getJndiName(), applicationName, moduleName);
    deleteResource(jdbcRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

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