Search in sources :

Example 6 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy in project Payara by payara.

the class ListJdbcResources method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Collection<JdbcResource> jdbcResources = domain.getResources().getResources(JdbcResource.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (JdbcResource jdbcResource : jdbcResources) {
            String jndiName = jdbcResource.getJndiName();
            if (bindableResourcesHelper.resourceExists(jndiName, target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(jndiName);
                Map<String, String> resourceNameMap = new HashMap<String, String>();
                String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
                if (logicalName != null) {
                    resourceNameMap.put("logical-jndi-name", logicalName);
                }
                resourceNameMap.put("name", jndiName);
                resourcesList.add(resourceNameMap);
            }
        }
        Properties extraProperties = new Properties();
        extraProperties.put("jdbcResources", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.jdbc.resources.failed", "List JDBC resources failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) ActionReport(org.glassfish.api.ActionReport)

Aggregations

ActionReport (org.glassfish.api.ActionReport)6 DefaultResourceProxy (org.glassfish.api.naming.DefaultResourceProxy)6 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ContextService (org.glassfish.concurrent.config.ContextService)1 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)1 ManagedScheduledExecutorService (org.glassfish.concurrent.config.ManagedScheduledExecutorService)1 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)1 DefaultContextService (org.glassfish.concurrent.runtime.deployer.DefaultContextService)1 DefaultManagedExecutorService (org.glassfish.concurrent.runtime.deployer.DefaultManagedExecutorService)1 DefaultManagedScheduledExecutorService (org.glassfish.concurrent.runtime.deployer.DefaultManagedScheduledExecutorService)1 DefaultManagedThreadFactory (org.glassfish.concurrent.runtime.deployer.DefaultManagedThreadFactory)1 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)1 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)1 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)1 JdbcResource (org.glassfish.jdbc.config.JdbcResource)1