--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.store.raw.xact.BeginXact\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.store.raw.Transaction;\r
+import org.apache.derby.iapi.store.raw.Loggable;\r
+import org.apache.derby.iapi.store.raw.GlobalTransactionId;\r
+\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction;\r
+\r
+import org.apache.derby.iapi.util.ByteArray;\r
+\r
+import java.io.OutputStream;\r
+import java.io.InputStream;\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+import org.apache.derby.iapi.services.io.LimitObjectInput;\r
+\r
+/**\r
+ This operation indicates the beginning of a transaction.\r
+ @see Loggable\r
+*/\r
+\r
+public class BeginXact implements Loggable {\r
+\r
+ protected int transactionStatus;\r
+ protected GlobalTransactionId xactId;\r
+\r
+\r
+ public BeginXact(GlobalTransactionId xid, int s)\r
+ {\r
+ xactId = xid;\r
+ transactionStatus = s;\r
+ }\r
+\r
+ /*\r
+ * Formatable methods\r
+ */\r
+ public BeginXact()\r
+ { super() ; }\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException \r
+ {\r
+ out.writeInt(transactionStatus);\r
+ out.writeObject(xactId);\r
+ }\r
+\r
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException\r
+ {\r
+ transactionStatus = in.readInt();\r
+ xactId = (GlobalTransactionId)in.readObject();\r
+ }\r
+\r
+ /**\r
+ Return my format identifier.\r
+ */\r
+ public int getTypeFormatId() {\r
+ return StoredFormatIds.LOGOP_BEGIN_XACT;\r
+ }\r
+\r
+ /**\r
+ Loggable methods\r
+ @see Loggable\r
+ */\r
+\r
+ /**\r
+ Apply the change indicated by this operation and optional data.\r
+\r
+ @param xact the Transaction\r
+ @param instant the log instant of this operation\r
+ @param in optional data\r
+\r
+ */\r
+ public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)\r
+ {\r
+ RawTransaction rt = (RawTransaction)xact;\r
+\r
+ // If we are not doing fake logging for in memory database\r
+ if (instant != null) \r
+ {\r
+ rt.setFirstLogInstant(instant);\r
+\r
+ // need to do this here rather than in the transaction object for\r
+ // recovery.\r
+ rt.addUpdateTransaction(transactionStatus);\r
+ }\r
+ }\r
+\r
+ /**\r
+ the default for prepared log is always null for all the operations\r
+ that don't have optionalData. If an operation has optional data,\r
+ the operation need to prepare the optional data for this method.\r
+\r
+ BeginXact has no optional data to write out\r
+\r
+ @see ObjectOutput\r
+ */\r
+ public ByteArray getPreparedLog()\r
+ {\r
+ return (ByteArray) null;\r
+ }\r
+\r
+ /**\r
+ Always redo a BeginXact.\r
+\r
+ @param xact The transaction trying to redo this operation\r
+ @return true if operation needs redoing, false if not.\r
+ */\r
+ public boolean needsRedo(Transaction xact)\r
+ {\r
+ return true; // always redo this\r
+ }\r
+\r
+\r
+ /**\r
+ BeginXact has no resource to release\r
+ */\r
+ public void releaseResource(Transaction xact)\r
+ {}\r
+\r
+\r
+ /**\r
+ BeginXact is both a FIRST and a RAWSTORE log record\r
+ */\r
+ public int group()\r
+ {\r
+ int group = Loggable.FIRST | Loggable.RAWSTORE;\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ DEBUG: Print self.\r
+ */\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ return "BeginXact " + xactId + " transactionStatus " + Integer.toHexString(transactionStatus);\r
+ else\r
+ return null;\r
+\r
+ }\r
+\r
+ /**\r
+ BeginXact method\r
+ */\r
+ public GlobalTransactionId getGlobalId()\r
+ {\r
+ return xactId;\r
+ }\r
+\r
+\r
+}\r
+\r