KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcspring > TransactionManagerProtocol


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tcspring;
5
6 import com.tc.aspectwerkz.joinpoint.StaticJoinPoint;
7 import com.tc.object.bytecode.Manager;
8 import com.tc.object.bytecode.ManagerUtil;
9
10 /**
11  * Hooks into all subclasses of org.springframework.transaction.PlatformTransactionManager interface.
12  * <p>
13  * Interepts the start, commit, rollback TX methods.
14  * <p>
15  * It currently hijacks anything but NOT derivatives of the AbstractPlatformTransactionManager.
16  *
17  * @author Jonas Bon&#233;r
18  */

19 public class TransactionManagerProtocol {
20   private static final String JavaDoc LOCK_NAME = "tc:spring-tx-lock";
21
22   /**
23    * TODO use <code>TransactionDefinition.isReadOnly()</code> to optimize lock types.
24    */

25   public Object JavaDoc startTransaction(final StaticJoinPoint jp, final Object JavaDoc manager) throws Throwable JavaDoc {
26     try {
27       return jp.proceed();
28     } finally {
29       ManagerUtil.beginLock(LOCK_NAME, Manager.LOCK_TYPE_WRITE);
30     }
31   }
32
33   public Object JavaDoc commitTransaction(final StaticJoinPoint jp, final Object JavaDoc manager) throws Throwable JavaDoc {
34     try {
35       return jp.proceed();
36     } finally {
37       ManagerUtil.commitLock(LOCK_NAME);
38     }
39   }
40
41   public Object JavaDoc rollbackTransaction(final StaticJoinPoint jp, final Object JavaDoc manager) throws Throwable JavaDoc {
42     try {
43       return jp.proceed();
44     } finally {
45       // FIXME rollback needs to be implemented in dso
46
ManagerUtil.commitLock(LOCK_NAME);
47     }
48   }
49
50 }
51
Popular Tags