1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jencks.interceptor;
18
19 import org.aopalliance.intercept.MethodInterceptor;
20 import org.aopalliance.intercept.MethodInvocation;
21 import org.apache.geronimo.transaction.DefaultInstanceContext;
22 import org.apache.geronimo.transaction.InstanceContext;
23 import org.apache.geronimo.transaction.TrackedConnectionAssociator;
24
25 import java.util.HashSet;
26 import java.util.Set;
27
28 /***
29 * This servlet filter is used to enter in a transactional context
30 * automtically at every servlet call and exit of it when the response
31 * is sent back to the client.
32 *
33 * @author Thierry Templier
34 * @see TrackedConnectionAssociator#enter(InstanceContext)
35 * @see TrackedConnectionAssociator#exit(InstanceContext)
36 * @see InstanceContext
37 * @see DefaultInstanceContext
38 */
39 public class TransactionContextInterceptor implements MethodInterceptor {
40
41 private TrackedConnectionAssociator associator;
42
43 /***
44 * This is the central method of the filter which allows the
45 * request to enter in a transactionnal context and exit when
46 * the request is sent back to the client.
47 *
48 * @see #enterContext(Set, Set)
49 * @see #exitContext(InstanceContext)
50 */
51 public Object invoke(MethodInvocation invocation) throws Throwable {
52 Set unshareableResources = new HashSet();
53 Set applicationManagedSecurityResources = new HashSet();
54 InstanceContext context = associator.enter(
55 new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
56 Object returnValue = invocation.proceed();
57 associator.exit(context);
58 return returnValue;
59 }
60
61 /***
62 * Set the TrackedConnectionAssociator instance to allow the bean
63 * to enter and exit a transactional context.
64 */
65 public void setAssociator(TrackedConnectionAssociator associator) {
66 this.associator = associator;
67 }
68
69 }