Map<String, OperationTransformer> writeAttributeTransformers = new HashMap<>();
Map<String, OperationTransformer> undefineAttributeTransformers = new HashMap<>();
if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
// Convert BATCH -> NONE, and include write-attribute:name=batching
OperationTransformer addTransformer = new OperationTransformer() {
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
if (operation.hasDefined(MODE.getName())) {
ModelNode mode = operation.get(MODE.getName());
if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
mode.set(TransactionMode.NONE.name());
ModelNode writeBatchingOperation = OperationFactory.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.BATCHING.getName(), new ModelNode(true));
return new TransformedOperation(OperationFactory.createCompositeOperation(writeBatchingOperation, operation), OperationResultTransformer.ORIGINAL_RESULT);
}
}
return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
};
addOperationTransformers.add(addTransformer);
// Additionally include undefine-attribute:name=batching
OperationTransformer removeTransformer = new OperationTransformer() {
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
ModelNode undefineBatchingOperation = OperationFactory.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.BATCHING.getName());
return new TransformedOperation(OperationFactory.createCompositeOperation(undefineBatchingOperation, operation), OperationResultTransformer.ORIGINAL_RESULT);
}
};
removeOperationTransformers.add(removeTransformer);
// If read-attribute:name=batching is true, return BATCH, otherwise use result from read-attribute:name=mode
OperationTransformer readAttributeTransformer = new OperationTransformer() {
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
ModelNode readBatchingOperation = OperationFactory.createReadAttributeOperation(cacheAddress(address), CacheResourceDefinition.BATCHING.getName());
OperationResultTransformer resultTransformer = new OperationResultTransformer() {
@Override
public ModelNode transformResult(ModelNode result) {
ModelNode readBatchingResult = result.get(0);
return readBatchingResult.asBoolean() ? new ModelNode(TransactionMode.BATCH.name()) : result.get(1);
}
};
return new TransformedOperation(OperationFactory.createCompositeOperation(readBatchingOperation, operation), resultTransformer);
}
};
readAttributeTransformers.put(MODE.getName(), readAttributeTransformer);
// Convert BATCH -> NONE, and include write-attribute:name=batching
OperationTransformer writeAttributeTransformer = new OperationTransformer() {
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
ModelNode mode = operation.hasDefined(ModelDescriptionConstants.VALUE) ? operation.get(ModelDescriptionConstants.VALUE) : null;
boolean batching = (mode != null) && (mode.getType() == ModelType.STRING) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false;
if (batching) {