01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcspring;
05:
06: import com.tc.aspectwerkz.joinpoint.StaticJoinPoint;
07: import com.tc.object.bytecode.Manager;
08: import com.tc.object.bytecode.ManagerUtil;
09:
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ér
18: */
19: public class TransactionManagerProtocol {
20: private static final String LOCK_NAME = "tc:spring-tx-lock";
21:
22: /**
23: * TODO use <code>TransactionDefinition.isReadOnly()</code> to optimize lock types.
24: */
25: public Object startTransaction(final StaticJoinPoint jp,
26: final Object manager) throws Throwable {
27: try {
28: return jp.proceed();
29: } finally {
30: ManagerUtil.beginLock(LOCK_NAME, Manager.LOCK_TYPE_WRITE);
31: }
32: }
33:
34: public Object commitTransaction(final StaticJoinPoint jp,
35: final Object manager) throws Throwable {
36: try {
37: return jp.proceed();
38: } finally {
39: ManagerUtil.commitLock(LOCK_NAME);
40: }
41: }
42:
43: public Object rollbackTransaction(final StaticJoinPoint jp,
44: final Object manager) throws Throwable {
45: try {
46: return jp.proceed();
47: } finally {
48: // FIXME rollback needs to be implemented in dso
49: ManagerUtil.commitLock(LOCK_NAME);
50: }
51: }
52:
53: }
|