|
1 |
| -/* |
2 |
| - * Copyright 2002-2007 the original author or authors. |
3 |
| - * |
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - * you may not use this file except in compliance with the License. |
6 |
| - * You may obtain a copy of the License at |
7 |
| - * |
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| - * |
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - * See the License for the specific language governing permissions and |
14 |
| - * limitations under the License. |
15 |
| - */ |
16 |
| - |
17 |
| -package org.springframework.transaction.aspectj; |
18 |
| - |
19 |
| -import java.lang.reflect.Method; |
20 |
| - |
21 |
| -import org.aspectj.lang.annotation.SuppressAjWarnings; |
22 |
| -import org.aspectj.lang.reflect.MethodSignature; |
23 |
| -import org.springframework.transaction.interceptor.TransactionAspectSupport; |
24 |
| -import org.springframework.transaction.interceptor.TransactionAttributeSource; |
25 |
| - |
26 |
| -/** |
27 |
| - * Abstract superaspect for AspectJ transaction aspects. Concrete |
28 |
| - * subaspects will implement the <code>transactionalMethodExecution()</code> |
29 |
| - * pointcut using a strategy such as Java 5 annotations. |
30 |
| - * |
31 |
| - * <p>Suitable for use inside or outside the Spring IoC container. |
32 |
| - * Set the "transactionManager" property appropriately, allowing |
33 |
| - * use of any transaction implementation supported by Spring. |
34 |
| - * |
35 |
| - * <p><b>NB:</b> If a method implements an interface that is itself |
36 |
| - * transactionally annotated, the relevant Spring transaction attribute |
37 |
| - * will <i>not</i> be resolved. This behavior will vary from that of Spring AOP |
38 |
| - * if proxying an interface (but not when proxying a class). We recommend that |
39 |
| - * transaction annotations should be added to classes, rather than business |
40 |
| - * interfaces, as they are an implementation detail rather than a contract |
41 |
| - * specification validation. |
42 |
| - * |
43 |
| - * @author Rod Johnson |
44 |
| - * @author Ramnivas Laddad |
45 |
| - * @since 2.0 |
46 |
| - */ |
47 |
| -public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport { |
48 |
| - |
49 |
| - /** |
50 |
| - * Construct object using the given transaction metadata retrieval strategy. |
51 |
| - * @param tas TransactionAttributeSource implementation, retrieving Spring |
52 |
| - * transaction metadata for each joinpoint. Write the subclass to pass in null |
53 |
| - * if it's intended to be configured by Setter Injection. |
54 |
| - */ |
55 |
| - protected AbstractTransactionAspect(TransactionAttributeSource tas) { |
56 |
| - setTransactionAttributeSource(tas); |
57 |
| - } |
58 |
| - |
59 |
| - @SuppressAjWarnings("adviceDidNotMatch") |
60 |
| - before(Object txObject) : transactionalMethodExecution(txObject) { |
61 |
| - MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature(); |
62 |
| - Method method = methodSignature.getMethod(); |
63 |
| - TransactionInfo txInfo = createTransactionIfNecessary(method, txObject.getClass()); |
64 |
| - } |
65 |
| - |
66 |
| - @SuppressAjWarnings("adviceDidNotMatch") |
67 |
| - after(Object txObject) throwing(Throwable t) : transactionalMethodExecution(txObject) { |
68 |
| - try { |
69 |
| - completeTransactionAfterThrowing(TransactionAspectSupport.currentTransactionInfo(), t); |
70 |
| - } |
71 |
| - catch (Throwable t2) { |
72 |
| - logger.error("Failed to close transaction after throwing in a transactional method", t2); |
73 |
| - } |
74 |
| - } |
75 |
| - |
76 |
| - @SuppressAjWarnings("adviceDidNotMatch") |
77 |
| - after(Object txObject) returning() : transactionalMethodExecution(txObject) { |
78 |
| - commitTransactionAfterReturning(TransactionAspectSupport.currentTransactionInfo()); |
79 |
| - } |
80 |
| - |
81 |
| - @SuppressAjWarnings("adviceDidNotMatch") |
82 |
| - after(Object txObject) : transactionalMethodExecution(txObject) { |
83 |
| - cleanupTransactionInfo(TransactionAspectSupport.currentTransactionInfo()); |
84 |
| - } |
85 |
| - |
86 |
| - /** |
87 |
| - * Concrete subaspects must implement this pointcut, to identify |
88 |
| - * transactional methods. For each selected joinpoint, TransactionMetadata |
89 |
| - * will be retrieved using Spring's TransactionAttributeSource interface. |
90 |
| - */ |
91 |
| - protected abstract pointcut transactionalMethodExecution(Object txObject); |
92 |
| - |
93 |
| -} |
| 1 | +/* |
| 2 | + * Copyright 2002-2010 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.transaction.aspectj; |
| 18 | + |
| 19 | +import java.lang.reflect.Method; |
| 20 | + |
| 21 | +import org.aspectj.lang.annotation.SuppressAjWarnings; |
| 22 | +import org.aspectj.lang.reflect.MethodSignature; |
| 23 | +import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| 24 | +import org.springframework.transaction.interceptor.TransactionAttributeSource; |
| 25 | + |
| 26 | +/** |
| 27 | + * Abstract superaspect for AspectJ transaction aspects. Concrete |
| 28 | + * subaspects will implement the <code>transactionalMethodExecution()</code> |
| 29 | + * pointcut using a strategy such as Java 5 annotations. |
| 30 | + * |
| 31 | + * <p>Suitable for use inside or outside the Spring IoC container. |
| 32 | + * Set the "transactionManager" property appropriately, allowing |
| 33 | + * use of any transaction implementation supported by Spring. |
| 34 | + * |
| 35 | + * <p><b>NB:</b> If a method implements an interface that is itself |
| 36 | + * transactionally annotated, the relevant Spring transaction attribute |
| 37 | + * will <i>not</i> be resolved. This behavior will vary from that of Spring AOP |
| 38 | + * if proxying an interface (but not when proxying a class). We recommend that |
| 39 | + * transaction annotations should be added to classes, rather than business |
| 40 | + * interfaces, as they are an implementation detail rather than a contract |
| 41 | + * specification validation. |
| 42 | + * |
| 43 | + * @author Rod Johnson |
| 44 | + * @author Ramnivas Laddad |
| 45 | + * @since 2.0 |
| 46 | + */ |
| 47 | +public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport { |
| 48 | + |
| 49 | + /** |
| 50 | + * Construct object using the given transaction metadata retrieval strategy. |
| 51 | + * @param tas TransactionAttributeSource implementation, retrieving Spring |
| 52 | + * transaction metadata for each joinpoint. Write the subclass to pass in null |
| 53 | + * if it's intended to be configured by Setter Injection. |
| 54 | + */ |
| 55 | + protected AbstractTransactionAspect(TransactionAttributeSource tas) { |
| 56 | + setTransactionAttributeSource(tas); |
| 57 | + } |
| 58 | + |
| 59 | + @SuppressAjWarnings("adviceDidNotMatch") |
| 60 | + before(Object txObject) : transactionalMethodExecution(txObject) { |
| 61 | + MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature(); |
| 62 | + Method method = methodSignature.getMethod(); |
| 63 | + TransactionInfo txInfo = createTransactionIfNecessary(method, txObject.getClass()); |
| 64 | + } |
| 65 | + |
| 66 | + @SuppressAjWarnings("adviceDidNotMatch") |
| 67 | + after(Object txObject) throwing(Throwable t) : transactionalMethodExecution(txObject) { |
| 68 | + try { |
| 69 | + completeTransactionAfterThrowing(TransactionAspectSupport.currentTransactionInfo(), t); |
| 70 | + } |
| 71 | + catch (Throwable t2) { |
| 72 | + logger.error("Failed to close transaction after throwing in a transactional method", t2); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @SuppressAjWarnings("adviceDidNotMatch") |
| 77 | + after(Object txObject) returning() : transactionalMethodExecution(txObject) { |
| 78 | + commitTransactionAfterReturning(TransactionAspectSupport.currentTransactionInfo()); |
| 79 | + } |
| 80 | + |
| 81 | + @SuppressAjWarnings("adviceDidNotMatch") |
| 82 | + after(Object txObject) : transactionalMethodExecution(txObject) { |
| 83 | + cleanupTransactionInfo(TransactionAspectSupport.currentTransactionInfo()); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Concrete subaspects must implement this pointcut, to identify |
| 88 | + * transactional methods. For each selected joinpoint, TransactionMetadata |
| 89 | + * will be retrieved using Spring's TransactionAttributeSource interface. |
| 90 | + */ |
| 91 | + protected abstract pointcut transactionalMethodExecution(Object txObject); |
| 92 | + |
| 93 | +} |
0 commit comments