KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > jta > JtaAfterCompletionSynchronization


1 /*
2  * Copyright 2002-2006 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.jta;
18
19 import java.util.List JavaDoc;
20
21 import javax.transaction.Status JavaDoc;
22 import javax.transaction.Synchronization JavaDoc;
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 Synchronization JavaDoc {
36
37     private final List JavaDoc synchronizations;
38
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 JavaDoc synchronizations) {
46         this.synchronizations = synchronizations;
47     }
48
49
50     public void beforeCompletion() {
51     }
52
53     public void afterCompletion(int status) {
54         switch (status) {
55             case Status.STATUS_COMMITTED:
56                 try {
57                     TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
58                 }
59                 finally {
60                     TransactionSynchronizationUtils.invokeAfterCompletion(
61                             this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
62                 }
63                 break;
64             case Status.STATUS_ROLLEDBACK:
65                 TransactionSynchronizationUtils.invokeAfterCompletion(
66                         this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
67                 break;
68             default:
69                 TransactionSynchronizationUtils.invokeAfterCompletion(
70                         this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
71         }
72     }
73 }
74
Popular Tags