--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.store.raw.xact.XactId\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.store.raw.xact;\r
+\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.store.raw.xact.TransactionId;\r
+\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+ Use this class for a short hand representation of the transaction. This\r
+ value is only guarentee to be unique within one continuous operation of the\r
+ raw store, in other words, every reboot may reuse the same value.\r
+\r
+ Whereas GlobalXactId is unique for all times across all raw store, a XactId\r
+ is only unique within a particular rawstore and may be reused.\r
+\r
+ XactId keeps track of the outstanding transactionId and is responsible\r
+ for dispensing new transactionIds\r
+*/\r
+public class XactId implements TransactionId\r
+{\r
+ /*\r
+ ** Fields\r
+ */\r
+ private long id; // immutable \r
+\r
+ /*\r
+ ** Constructor\r
+ */\r
+ public XactId(long id) {\r
+ this.id = id;\r
+ }\r
+\r
+ /*\r
+ * Formatable methods\r
+ */\r
+\r
+ // no-arg constructor, required by Formatable \r
+ public XactId() { super(); }\r
+\r
+ /**\r
+ Write this out.\r
+ @exception IOException error writing to log stream\r
+ */\r
+ public void writeExternal(ObjectOutput out) throws IOException \r
+ {\r
+ CompressedNumber.writeLong(out, id);\r
+ }\r
+\r
+ /**\r
+ Read this in\r
+ @exception IOException error reading from log stream\r
+ */\r
+ public void readExternal(ObjectInput in) throws IOException\r
+ {\r
+ id = CompressedNumber.readLong(in);\r
+ }\r
+\r
+ /**\r
+ Return my format identifier.\r
+ */\r
+ public int getTypeFormatId() {\r
+ return StoredFormatIds.RAW_STORE_XACT_ID;\r
+ }\r
+\r
+ /**\r
+ TransactionId method\r
+ */\r
+ \r
+ public int getMaxStoredSize()\r
+ {\r
+ return FormatIdUtil.getFormatIdByteLength(StoredFormatIds.RAW_STORE_XACT_ID) +\r
+ CompressedNumber.MAX_LONG_STORED_SIZE; \r
+ }\r
+\r
+ public boolean equals(Object other) {\r
+ if (other == this)\r
+ return true;\r
+\r
+ // assume cast will be successful rather than waste time doing an\r
+ // instanceof first. Catch the exception if it failed.\r
+ try\r
+ {\r
+ XactId oxid = (XactId)other;\r
+ return (id == oxid.id);\r
+ }\r
+ catch (ClassCastException cce)\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public int hashCode()\r
+ {\r
+ return (int)id;\r
+ }\r
+\r
+ /**\r
+ Methods specific to this class\r
+ */\r
+\r
+ \r
+ /**\r
+ Return 0 if a == b, \r
+ +ve number if a > b\r
+ -ve number if a < b\r
+ */\r
+ public static long compare(TransactionId a, TransactionId b)\r
+ {\r
+ if (a == null || b == null)\r
+ {\r
+ if (a == null)\r
+ return -1;\r
+ else if (b == null)\r
+ return 1;\r
+ else\r
+ return 0;\r
+ }\r
+\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(a instanceof XactId);\r
+ SanityManager.ASSERT(b instanceof XactId);\r
+ }\r
+ XactId A = (XactId)a;\r
+ XactId B = (XactId)b;\r
+\r
+ return A.id - B.id;\r
+ }\r
+\r
+ protected long getId() \r
+ {\r
+ return id;\r
+ }\r
+\r
+\r
+ public String toString()\r
+ {\r
+ // needed for virtual lock table\r
+ return Long.toString(id);\r
+ }\r
+\r
+\r
+}\r
+\r
+\r