Search in sources :

Example 1 with DataSource

use of org.jboss.jca.core.api.management.DataSource in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<DataSource>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDI_NAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getDataSources() != null) {
            repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).forEach(ds -> ds.setEnlistmentTrace(boolValue));
            handbackHolder.setHandback(repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).collect(Collectors.toList()));
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) OperationContext(org.jboss.as.controller.OperationContext) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) ConnectorLogger(org.jboss.as.connector.logging.ConnectorLogger) ConnectorServices(org.jboss.as.connector.util.ConnectorServices) ModelNode(org.jboss.dmr.ModelNode) Collectors(java.util.stream.Collectors) DataSource(org.jboss.jca.core.api.management.DataSource) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ConnectorLogger (org.jboss.as.connector.logging.ConnectorLogger)1 ConnectorServices (org.jboss.as.connector.util.ConnectorServices)1 AbstractWriteAttributeHandler (org.jboss.as.controller.AbstractWriteAttributeHandler)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 ModelNode (org.jboss.dmr.ModelNode)1 DataSource (org.jboss.jca.core.api.management.DataSource)1 ManagementRepository (org.jboss.jca.core.api.management.ManagementRepository)1 ServiceController (org.jboss.msc.service.ServiceController)1