@Override public ModelNode getModelDescription(final Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); final ModelNode node = new ModelNode(); node.get(DESCRIPTION).set(bundle.getString("data-source.description")); node.get(HEAD_COMMENT_ALLOWED).set(true); node.get(TAIL_COMMENT_ALLOWED).set(true); for (AttributeDefinition propertyType : DATASOURCE_ATTRIBUTE) { node.get(ATTRIBUTES, propertyType.getName(), DESCRIPTION) .set(bundle.getString(propertyType.getName())); node.get(ATTRIBUTES, propertyType.getName(), TYPE).set(propertyType.getModelType()); node.get(ATTRIBUTES, propertyType.getName(), REQUIRED).set(propertyType.isRequired()); } for (String name : LocalAndXaDataSourcesJdbcMetrics.ATTRIBUTES) { node.get(ATTRIBUTES, name, DESCRIPTION).set(jdbcMetrics.getDescription(name)); ModelType modelType = ModelType.STRING; if (jdbcMetrics.getType(name) == int.class) { modelType = ModelType.INT; } if (jdbcMetrics.getType(name) == long.class) { modelType = ModelType.LONG; } node.get(ATTRIBUTES, name, TYPE).set(modelType); node.get(ATTRIBUTES, name, REQUIRED).set(false); } for (String name : PoolMetrics.ATTRIBUTES) { node.get(ATTRIBUTES, name, DESCRIPTION).set(poolMetrics.getDescription(name)); ModelType modelType = ModelType.STRING; if (poolMetrics.getType(name) == int.class) { modelType = ModelType.INT; } if (poolMetrics.getType(name) == long.class) { modelType = ModelType.LONG; } node.get(ATTRIBUTES, name, TYPE).set(modelType); node.get(ATTRIBUTES, name, REQUIRED).set(false); } return node; }
@Override public ModelNode getModelDescription(final Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); final ModelNode operation = new ModelNode(); operation.get(OPERATION_NAME).set(ADD); operation.get(DESCRIPTION).set(bundle.getString("xa-data-source.add")); for (AttributeDefinition propertyType : XA_DATASOURCE_ATTRIBUTE) { operation .get(REQUEST_PROPERTIES, propertyType.getName(), DESCRIPTION) .set(bundle.getString(propertyType.getName())); operation .get(REQUEST_PROPERTIES, propertyType.getName(), TYPE) .set(propertyType.getModelType()); operation .get(REQUEST_PROPERTIES, propertyType.getName(), REQUIRED) .set(propertyType.isRequired()); } return operation; }
public OperationResult execute( final OperationContext context, final ModelNode operation, final ResultHandler resultHandler) throws OperationFailedException { final ModelNode opAddr = operation.require(OP_ADDR); final String jndiName = PathAddress.pathAddress(opAddr).getLastElement().getValue(); // Compensating is add final ModelNode model = context.getSubModel(); final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr); if (model.has(CONNECTION_PROPERTIES)) { for (ModelNode property : model.get(CONNECTION_PROPERTIES).asList()) { compensating .get(CONNECTION_PROPERTIES, property.asProperty().getName()) .set(property.asString()); } } for (final AttributeDefinition attribute : getModelProperties()) { if (model.get(attribute.getName()).isDefined()) { compensating.get(attribute.getName()).set(model.get(attribute.getName())); } } if (context.getRuntimeContext() != null) { context .getRuntimeContext() .setRuntimeTask( new RuntimeTask() { public void execute(RuntimeTaskContext context) throws OperationFailedException { final ServiceRegistry registry = context.getServiceRegistry(); final ServiceName binderServiceName = ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName); final ServiceController<?> binderController = registry.getService(binderServiceName); if (binderController != null) { binderController.setMode(ServiceController.Mode.REMOVE); } final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(jndiName); final ServiceController<?> referenceFactoryController = registry.getService(referenceFactoryServiceName); if (referenceFactoryController != null) { referenceFactoryController.setMode(ServiceController.Mode.REMOVE); } final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName); final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName); if (dataSourceController != null) { dataSourceController.setMode(ServiceController.Mode.REMOVE); } resultHandler.handleResultComplete(); } }); } else { resultHandler.handleResultComplete(); } return new BasicOperationResult(compensating); }