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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations