context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) {
final String dataSourceName = newValue.resolve().asString();
final ServiceRegistry registry = context.getServiceRegistry(true);
ServiceController<?> sc = registry.getRequiredService(JPAService.SERVICE_NAME);
JPAService jpaService = JPAService.class.cast(sc.getValue());
String currentDataSourceName = JPAService.getDefaultDataSourceName();
jpaService.setDefaultDataSourceName(dataSourceName);
if (context.completeStep() == OperationContext.ResultAction.ROLLBACK) {
jpaService.setDefaultDataSourceName(currentDataSourceName);
}
}
}, OperationContext.Stage.RUNTIME);
}
return false;