@groovy.transform.CompileStatic @org.codehaus.groovy.transform.GroovyASTTransformation(phase: CompilePhase.CANONICALIZATION) class TransactionalTransform extends AbstractDatastoreMethodDecoratingTransformation implements Ordered
This AST transform reads the Transactional annotation and transforms method calls by wrapping the body of the method in an execution of GrailsTransactionTemplate.
In other words given the following class:
class FooService {
@Transactional
void updateFoo() {
...
}
}
The resulting byte code produced will be (more or less):
class FooService { PlatformTransactionManager $transactionManager PlatformTransactionManager getTransactionManager() { $transactionManager } void updateFoo() { GrailsTransactionTemplate template = new GrailsTransactionTemplate(getTransactionManager()) template.execute { TransactionStatus status -> $tt_updateFoo(status) } } private void $tt_updateFoo(TransactionStatus status) { ... } }
The body of the method is moved to a new method prefixed with "$tt_" and which receives the arguments of the method and the TransactionStatus object
Modifiers | Name | Description |
---|---|---|
static java.lang.String |
GET_TRANSACTION_MANAGER_METHOD |
|
static org.codehaus.groovy.ast.ClassNode |
MY_TYPE |
|
static int |
POSITION |
The position of the transform in terms ordering |
static org.codehaus.groovy.ast.ClassNode |
READ_ONLY_TYPE |
|
static java.lang.String |
RENAMED_METHOD_PREFIX |
Fields inherited from class | Fields |
---|---|
class AbstractDatastoreMethodDecoratingTransformation |
FIELD_TARGET_DATASTORE, METHOD_GET_DATASTORE_FOR_CONNECTION, METHOD_GET_TARGET_DATASTORE |
class AbstractMethodDecoratingTransformation |
DECORATED_METHODS |
Constructor and description |
---|
TransactionalTransform
() |
Type Params | Return Type | Name and description |
---|---|---|
|
protected java.lang.Object |
applyTransactionalAttributeSettings(org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.expr.VariableExpression transactionAttributeVar, org.codehaus.groovy.ast.stmt.BlockStatement methodBody, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode) |
|
org.codehaus.groovy.ast.expr.MethodCallExpression |
buildDelegatingMethodCall(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode, org.codehaus.groovy.ast.expr.MethodCallExpression originalMethodCall, org.codehaus.groovy.ast.stmt.BlockStatement newMethodBody) |
|
protected void |
enhanceClassNode(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode declaringClassNode) |
|
static org.codehaus.groovy.ast.AnnotationNode |
findTransactionalAnnotation(org.codehaus.groovy.ast.MethodNode methodNode) Finds the transactional annotation for the given method node |
|
protected org.codehaus.groovy.ast.ClassNode |
getAnnotationType() |
|
protected java.lang.Object |
getAppliedMarker() |
|
int |
getOrder() |
|
protected java.lang.String |
getRenamedMethodPrefix() |
|
protected java.lang.String |
getTransactionTemplateMethodName() |
|
protected boolean |
hasExcludedAnnotation(org.codehaus.groovy.ast.MethodNode md) |
|
static boolean |
hasTransactionalAnnotation(org.codehaus.groovy.ast.AnnotatedNode md) Whether the given method has a transactional annotation |
|
protected boolean |
isValidAnnotation(org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.AnnotatedNode classNode) |
|
protected org.codehaus.groovy.ast.Parameter[] |
prepareNewMethodParameters(org.codehaus.groovy.ast.MethodNode methodNode, java.util.Map<java.lang.String, org.codehaus.groovy.ast.ClassNode> genericsSpec, org.codehaus.groovy.ast.ClassNode classNode) |
|
protected void |
weaveClassNode(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode classNode) |
|
protected org.codehaus.groovy.ast.MethodNode |
weaveNewMethod(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode, java.util.Map<java.lang.String, org.codehaus.groovy.ast.ClassNode> genericsSpec) |
|
protected void |
weaveSetTargetDatastoreBody(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode declaringClassNode, org.codehaus.groovy.ast.expr.Expression datastoreVar, org.codehaus.groovy.ast.stmt.BlockStatement setTargetDatastoreBody) |
|
protected void |
weaveTestSetupMethod(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode, java.util.Map<java.lang.String, org.codehaus.groovy.ast.ClassNode> genericsSpec) |
|
protected void |
weaveTransactionManagerAware(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.AnnotationNode annotationNode, org.codehaus.groovy.ast.ClassNode declaringClassNode) |
The position of the transform in terms ordering
Finds the transactional annotation for the given method node
methodNode
- The method nodeWhether the given method has a transactional annotation @return
md
- The method node