use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class CreateJdbcResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
// Delete the created resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
// and removal runs at the same time.
for (Resource resource : param.getResources()) {
if (resource instanceof JdbcResource) {
JdbcResource jr = (JdbcResource) resource;
if (jr.getJndiName().equals("jdbc/foo") || jr.getJndiName().equals("dupRes") || jr.getJndiName().equals("jdbc/sun") || jr.getJndiName().equals("jdbc/alldefaults") || jr.getJndiName().equals("jdbc/junk")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteSuccessListNoBob.
/**
* Test of execute method, of class ListJdbcResource.
* delete-jdbc-resource bob
* list-jdbc-resources
*/
@Test
public void testExecuteSuccessListNoBob() {
// Create JDBC Resource bob
assertTrue(resources != null);
// Get an instance of the CreateJdbcResource command
createCommand = habitat.getService(CreateJdbcResource.class);
assertTrue(createCommand != null);
parameters.add("connectionpoolid", "DerbyPool");
parameters.add("DEFAULT", "bob2");
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Delete JDBC Resource bob
// assertTrue(resources!=null);
// Get an instance of the CreateJdbcResource command
deleteCommand = habitat.getService(DeleteJdbcResource.class);
assertTrue(deleteCommand != null);
parameters = new ParameterMap();
parameters.add("DEFAULT", "bob2");
cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// List JDBC Resources and check if bob is in the list
// Get an instance of the ListJdbcResources command
listCommand = habitat.getService(ListJdbcResources.class);
parameters = new ParameterMap();
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
int numResources = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof JdbcResource) {
numResources = numResources + 1;
}
}
assertEquals(numResources, list.size());
List<String> listStr = new java.util.ArrayList();
for (MessagePart mp : list) {
listStr.add(mp.getMessage());
}
assertFalse(listStr.contains("bob2"));
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class ConnectionPoolHealthCheck method doCheck.
@Override
public HealthCheckResult doCheck() {
HealthCheckResult result = new HealthCheckResult();
Collection<JdbcResource> allJdbcResources = getAllJdbcResources();
for (JdbcResource resource : allJdbcResources) {
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(resource);
JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
PoolInfo poolInfo = ResourceUtil.getPoolInfo(pool);
if (getOptions().getPoolName() != null) {
if (getOptions().getPoolName().equals(poolInfo.getName())) {
evaluatePoolUsage(result, poolInfo);
}
} else {
evaluatePoolUsage(result, poolInfo);
}
}
return result;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class JDBCResourceManager method createResource.
private JdbcResource createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
JdbcResource newResource = createConfigBean(param, properties);
param.getResources().add(newResource);
return newResource;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class JDBCResourceManager method createConfigBean.
private JdbcResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
JdbcResource jdbcResource = param.createChild(JdbcResource.class);
jdbcResource.setJndiName(jndiName);
if (description != null) {
jdbcResource.setDescription(description);
}
jdbcResource.setPoolName(poolName);
jdbcResource.setEnabled(enabled);
if (properties != null) {
for (Map.Entry e : properties.entrySet()) {
Property prop = jdbcResource.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
jdbcResource.getProperty().add(prop);
}
}
return jdbcResource;
}
Aggregations