001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.command;
018
019 /**
020 * @openwire:marshaller code="111"
021 *
022 */
023 public class LocalTransactionId extends TransactionId implements Comparable<LocalTransactionId> {
024
025 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_LOCAL_TRANSACTION_ID;
026
027 protected ConnectionId connectionId;
028 protected long value;
029
030 private transient String transactionKey;
031 private transient int hashCode;
032
033 public LocalTransactionId() {
034 }
035
036 public LocalTransactionId(ConnectionId connectionId, long transactionId) {
037 this.connectionId = connectionId;
038 this.value = transactionId;
039 }
040
041 public byte getDataStructureType() {
042 return DATA_STRUCTURE_TYPE;
043 }
044
045 public boolean isXATransaction() {
046 return false;
047 }
048
049 public boolean isLocalTransaction() {
050 return true;
051 }
052
053 public String getTransactionKey() {
054 if (transactionKey == null) {
055 transactionKey = "TX:" + connectionId + ":" + value;
056 }
057 return transactionKey;
058 }
059
060 public String toString() {
061 return getTransactionKey();
062 }
063
064 public int hashCode() {
065 if (hashCode == 0) {
066 hashCode = connectionId.hashCode() ^ (int)value;
067 }
068 return hashCode;
069 }
070
071 public boolean equals(Object o) {
072 if (this == o) {
073 return true;
074 }
075 if (o == null || o.getClass() != LocalTransactionId.class) {
076 return false;
077 }
078 LocalTransactionId tx = (LocalTransactionId)o;
079 return value == tx.value && connectionId.equals(tx.connectionId);
080 }
081
082 /**
083 * @param o
084 * @return
085 * @see java.lang.Comparable#compareTo(java.lang.Object)
086 */
087 public int compareTo(LocalTransactionId o) {
088 int result = connectionId.compareTo(o.connectionId);
089 if (result == 0) {
090 result = (int)(value - o.value);
091 }
092 return result;
093 }
094
095 /**
096 * @openwire:property version=1
097 */
098 public long getValue() {
099 return value;
100 }
101
102 public void setValue(long transactionId) {
103 this.value = transactionId;
104 }
105
106 /**
107 * @openwire:property version=1 cache=true
108 */
109 public ConnectionId getConnectionId() {
110 return connectionId;
111 }
112
113 public void setConnectionId(ConnectionId connectionId) {
114 this.connectionId = connectionId;
115 }
116
117 }