01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.jta;
18:
19: import java.util.List;
20:
21: import javax.transaction.Status;
22: import javax.transaction.Synchronization;
23:
24: import org.springframework.transaction.support.TransactionSynchronization;
25: import org.springframework.transaction.support.TransactionSynchronizationUtils;
26:
27: /**
28: * Adapter for a JTA Synchronization, invoking the <code>afterCompletion</code> of
29: * Spring TransactionSynchronizations after the outer JTA transaction has completed.
30: * Applied when participating in an existing (non-Spring) JTA transaction.
31: *
32: * @author Juergen Hoeller
33: * @since 2.0
34: */
35: public class JtaAfterCompletionSynchronization implements
36: Synchronization {
37:
38: private final List synchronizations;
39:
40: /**
41: * Create a new JtaAfterCompletionSynchronization for the given synchronization objects.
42: * @param synchronizations the List of TransactionSynchronization objects
43: * @see org.springframework.transaction.support.TransactionSynchronization
44: */
45: public JtaAfterCompletionSynchronization(List synchronizations) {
46: this .synchronizations = synchronizations;
47: }
48:
49: public void beforeCompletion() {
50: }
51:
52: public void afterCompletion(int status) {
53: switch (status) {
54: case Status.STATUS_COMMITTED:
55: try {
56: TransactionSynchronizationUtils
57: .invokeAfterCommit(this.synchronizations);
58: } finally {
59: TransactionSynchronizationUtils.invokeAfterCompletion(
60: this.synchronizations,
61: TransactionSynchronization.STATUS_COMMITTED);
62: }
63: break;
64: case Status.STATUS_ROLLEDBACK:
65: TransactionSynchronizationUtils.invokeAfterCompletion(
66: this.synchronizations,
67: TransactionSynchronization.STATUS_ROLLED_BACK);
68: break;
69: default:
70: TransactionSynchronizationUtils.invokeAfterCompletion(
71: this.synchronizations,
72: TransactionSynchronization.STATUS_UNKNOWN);
73: }
74: }
75: }
|