@CompileStatic @GroovyASTTransformation(phase: CompilePhase.CANONICALIZATION) class TransactionalTransform extends AbstractDatastoreMethodDecoratingTransformation
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:
@Transactional
class MyService {
void saveBook(String title) {
new Book(title:title).save()
}
}
The transform will produce:
class MyService {
@Autowired
PlatformTransactionManager transactionManager
void saveBook(String title) {
transactionManager.execute { TransactionStatus status ->
new Book(title:title).save()
}
}
}
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
GET_TRANSACTION_MANAGER_METHOD |
|
static java.lang.String |
METHOD_EXECUTE |
|
static ClassNode |
MY_TYPE |
|
static java.lang.String |
PROPERTY_TRANSACTION_MANAGER |
|
static ClassNode |
READ_ONLY_TYPE |
|
static java.lang.String |
RENAMED_METHOD_PREFIX |
|
static java.lang.String |
SET_TRANSACTION_MANAGER |
| Fields inherited from class | Fields |
|---|---|
class AbstractDatastoreMethodDecoratingTransformation |
FIELD_TARGET_DATASTORE, METHOD_GET_DATASTORE_FOR_CONNECTION, METHOD_GET_TARGET_DATASTORE |
class AbstractMethodDecoratingTransformation |
DECORATED_METHODS |
| Properties inherited from class | Properties |
|---|---|
class AbstractGormASTTransformation |
compilationUnit |
| Constructor and description |
|---|
TransactionalTransform() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected java.lang.Object |
applyTransactionalAttributeSettings(AnnotationNode annotationNode, VariableExpression transactionAttributeVar, BlockStatement methodBody, ClassNode classNode, MethodNode methodNode) |
|
MethodCallExpression |
buildDelegatingMethodCall(SourceUnit sourceUnit, AnnotationNode annotationNode, ClassNode classNode, MethodNode methodNode, MethodCallExpression originalMethodCall, BlockStatement newMethodBody) |
|
protected void |
enhanceClassNode(SourceUnit source, AnnotationNode annotationNode, ClassNode declaringClassNode) |
|
static AnnotationNode |
findTransactionalAnnotation(MethodNode methodNode)Finds the transactional annotation for the given method node |
|
protected ClassNode |
getAnnotationType() |
|
protected java.lang.Object |
getAppliedMarker() |
|
protected java.lang.String |
getRenamedMethodPrefix() |
|
protected java.lang.String |
getTransactionTemplateMethodName() |
|
protected boolean |
hasLocalAnnotation(MethodNode amd, AnnotationNode classAnnotation) |
|
static boolean |
hasTransactionalAnnotation(AnnotatedNode node)Whether the given node carries an explicit transaction-related annotation. |
|
protected boolean |
isValidAnnotation(AnnotationNode annotationNode, AnnotatedNode classNode) |
|
protected Parameter[] |
prepareNewMethodParameters(MethodNode methodNode, java.util.Map<java.lang.String, ClassNode> genericsSpec, ClassNode classNode) |
|
int |
priority() |
|
protected void |
weaveSetTargetDatastoreBody(SourceUnit source, AnnotationNode annotationNode, ClassNode declaringClassNode, Expression datastoreVar, BlockStatement setTargetDatastoreBody) |
|
protected void |
weaveTestSetupMethod(SourceUnit sourceUnit, AnnotationNode annotationNode, ClassNode classNode, MethodNode methodNode, java.util.Map<java.lang.String, ClassNode> genericsSpec) |
|
protected void |
weaveTransactionManagerAware(SourceUnit source, AnnotationNode annotationNode, ClassNode declaringClassNode) |
Finds the transactional annotation for the given method node
methodNode - The method node Whether the given node carries an explicit transaction-related annotation. An explicit
@NotTransactional counts as such a decision: callers use this to decide whether to
impose a default transaction (read-only for reads, transactional for writes), and a method
the user marked @NotTransactional must not have a default transaction imposed on it.
node - The node