KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > command > LocalTransactionId


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.command;
19
20 /**
21  * @openwire:marshaller code="111"
22  * @version $Revision: 1.11 $
23  */

24 public class LocalTransactionId extends TransactionId implements Comparable JavaDoc<LocalTransactionId>{
25
26     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.ACTIVEMQ_LOCAL_TRANSACTION_ID;
27
28     protected ConnectionId connectionId;
29     protected long value;
30
31     private transient String JavaDoc transactionKey;
32     private transient int hashCode;
33
34     public LocalTransactionId() {
35     }
36     
37     public LocalTransactionId(ConnectionId connectionId, long transactionId) {
38         this.connectionId=connectionId;
39         this.value=transactionId;
40     }
41
42     public byte getDataStructureType() {
43         return DATA_STRUCTURE_TYPE;
44     }
45
46     public boolean isXATransaction() {
47         return false;
48     }
49
50     public boolean isLocalTransaction() {
51         return true;
52     }
53
54     public String JavaDoc getTransactionKey() {
55         if( transactionKey==null ) {
56             transactionKey = "TX:"+connectionId+":"+value;
57         }
58         return transactionKey;
59     }
60     
61     public String JavaDoc toString() {
62         return getTransactionKey();
63     }
64
65     public int hashCode() {
66         if( hashCode == 0 ) {
67             hashCode = connectionId.hashCode() ^ (int)value;
68         }
69         return hashCode;
70     }
71     
72     public boolean equals(Object JavaDoc o) {
73         if( this == o )
74             return true;
75         if( o == null || o.getClass()!=LocalTransactionId.class )
76             return false;
77         LocalTransactionId tx = (LocalTransactionId) o;
78         return value==tx.value
79                 && connectionId.equals(tx.connectionId);
80     }
81     
82     
83     /**
84      * @param o
85      * @return
86      * @see java.lang.Comparable#compareTo(java.lang.Object)
87      */

88     public int compareTo(LocalTransactionId o){
89         int result = connectionId.compareTo(o.connectionId);
90         if (result==0) {
91             result = (int) (value - o.value);
92         }
93         return result;
94     }
95     /**
96      * @openwire:property version=1
97      */

98     public long getValue() {
99         return value;
100     }
101     public void setValue(long transactionId) {
102         this.value = transactionId;
103     }
104
105     /**
106      * @openwire:property version=1 cache=true
107      */

108     public ConnectionId getConnectionId() {
109         return connectionId;
110     }
111     public void setConnectionId(ConnectionId connectionId) {
112         this.connectionId = connectionId;
113     }
114
115     
116
117
118 }
119
Popular Tags