Created
June 11, 2014 13:56
-
-
Save pferraro/b760f8cb3ab06405f550 to your computer and use it in GitHub Desktop.
batching transformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Registers cache transformations for model changes introduced in 3.0.0 | |
*/ | |
private static void registerCacheTransformations200(final ResourceTransformationDescriptionBuilder cacheBuilder, CacheMode mode) { | |
AttributeConverter transactionModeConverter = new AttributeConverter() { | |
@Override | |
public void convertOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { | |
convert(attributeValue, operation); | |
} | |
@Override | |
public void convertResourceAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { | |
ModelNode cacheModel = context.readResourceFromRoot(address).getModel(); | |
convert(attributeValue, cacheModel); | |
} | |
private void convert(ModelNode attributeValue, ModelNode operation) { | |
if (attributeValue.isDefined() && TransactionMode.valueOf(attributeValue.asString()) == TransactionMode.BATCH) { | |
attributeValue.set(TransactionMode.NONE.name()); | |
try { | |
CacheResourceDefinition.BATCHING.validateAndSet(operation, new ModelNode(true)); | |
} catch (OperationFailedException e) { | |
throw new IllegalStateException(e); | |
} | |
} | |
} | |
}; | |
cacheBuilder.addChildResource(TransactionResourceDefinition.TRANSACTION_PATH).getAttributeBuilder() | |
.setValueConverter(transactionModeConverter, TransactionResourceDefinition.MODE) | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment