KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > transaction > ExternalTransactionContext


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/transaction/ExternalTransactionContext.java,v 1.4 2004/07/28 09:34:33 ib Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/07/28 09:34:33 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.transaction;
24
25 import javax.transaction.Status JavaDoc;
26 import javax.transaction.Transaction JavaDoc;
27
28 import java.util.*;
29
30 /**
31  * Context for external transaction started an controlled by clients.
32  *
33  */

34 public class ExternalTransactionContext {
35
36     protected static Map transactions = Collections.synchronizedMap(new HashMap());
37
38     public static void registerContext(Object JavaDoc txId, Transaction JavaDoc transaction) {
39         ExternalTransactionContext context = new ExternalTransactionContext(transaction, txId);
40         context.setStatus(Status.STATUS_ACTIVE);
41         transactions.put(txId, context);
42     }
43
44     public static ExternalTransactionContext lookupContext(Object JavaDoc txId) {
45         return (ExternalTransactionContext) transactions.get(txId);
46     }
47
48     public static void deregisterContext(Object JavaDoc txId) {
49         transactions.remove(txId);
50     }
51
52     protected Transaction JavaDoc transaction;
53     protected Object JavaDoc txId;
54     protected volatile int status;
55
56     protected ExternalTransactionContext(Transaction JavaDoc transaction, Object JavaDoc txId) {
57         this.transaction = transaction;
58         this.txId = txId;
59     }
60
61     /**
62      * @return
63      */

64     public int getStatus() {
65         return status;
66     }
67
68     /**
69      * @param i
70      */

71     public void setStatus(int i) {
72         status = i;
73     }
74     /**
75      * @return
76      */

77     public Transaction JavaDoc getTransaction() {
78         return transaction;
79     }
80
81 }
82
Popular Tags