Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / raw / data / InitPageOperation.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/data/InitPageOperation.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/data/InitPageOperation.java
new file mode 100644 (file)
index 0000000..0be1481
--- /dev/null
@@ -0,0 +1,245 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.InitPageOperation\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.data;\r
+\r
+import org.apache.derby.impl.store.raw.data.BasePage;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.store.raw.RecordHandle;\r
+import org.apache.derby.iapi.store.raw.Page;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+\r
+import java.io.OutputStream;\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 initializes the page that is being allocated,\r
+       this operation does not change the alloc page information.\r
+\r
+       <PRE>\r
+       @format_id      LOGOP_INIT_PAGE\r
+               the formatId is written by FormatIdOutputStream when this object is\r
+               written out by writeObject\r
+       @purpose        initialized a page\r
+       @upgrade\r
+       @disk_layout\r
+               PhysicalPageOperation the superclass\r
+               nextRecordId(CompressedInt)     the next recordId this page should give out\r
+               initFlag(CompressedInt)         initialization flag: reuse, overflow\r
+               pageformat(int)                         the page's formatId\r
+\r
+               OptionalData    none\r
+       @end_format\r
+       </PRE>\r
+*/\r
+public final class InitPageOperation extends PhysicalPageOperation\r
+{\r
+       protected int   nextRecordId; // next recordId\r
+       protected int   initFlag;\r
+       protected int   pageFormatId;\r
+       protected long  pageOffset;\r
+\r
+       protected boolean reuse;        // is this page being initialize for reuse, or for first time\r
+       protected boolean overflowPage; // is this page an overflow page\r
+\r
+       public InitPageOperation(BasePage page, int flag, int formatid, \r
+                                                        long offset)\r
+                throws StandardException\r
+       {\r
+               super(page);\r
+\r
+               initFlag = flag;\r
+               pageFormatId = formatid;\r
+               pageOffset = offset;\r
+\r
+               // unless we specified recordId should be reusable, when we reuse a\r
+               // page, we keep incrementing the existing recordId\r
+               if ((initFlag & BasePage.INIT_PAGE_REUSE_RECORDID) == 0)\r
+                       nextRecordId = page.newRecordId();\r
+               else\r
+                       nextRecordId = RecordHandle.FIRST_RECORD_ID;\r
+       }\r
+\r
+       /*\r
+        * Formatable methods\r
+        */\r
+\r
+       // no-arg constructor, required by Formatable \r
+       public InitPageOperation() { 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
+               super.writeExternal(out);\r
+               CompressedNumber.writeInt(out, nextRecordId);\r
+               CompressedNumber.writeInt(out, initFlag);\r
+               CompressedNumber.writeLong(out, pageOffset);\r
+               out.writeInt(pageFormatId);\r
+       }\r
+\r
+       /**\r
+               Read this in\r
+               @exception IOException error reading from log stream\r
+               @exception ClassNotFoundException log stream corrupted\r
+       */\r
+       public void readExternal(ObjectInput in) \r
+                throws IOException, ClassNotFoundException\r
+       {\r
+               super.readExternal(in);\r
+               nextRecordId = CompressedNumber.readInt(in);\r
+               initFlag = CompressedNumber.readInt(in);\r
+               pageOffset = CompressedNumber.readLong(in);\r
+               pageFormatId = in.readInt();\r
+       }\r
+\r
+       /**\r
+               Return my format identifier.\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.LOGOP_INIT_PAGE;\r
+       }\r
+       /*\r
+        * Loggable methods\r
+        */\r
+       /**\r
+               Mark the page as valid, and clear out any crud from the page\r
+\r
+               @exception IOException Can be thrown by any of the methods of ObjectInput.\r
+               @exception StandardException Standard Derby policy.\r
+\r
+               @see org.apache.derby.iapi.store.raw.Loggable#doMe\r
+       */\r
+       public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)\r
+                throws StandardException, IOException \r
+       {\r
+               boolean overflowPage = ((initFlag & BasePage.INIT_PAGE_OVERFLOW) != 0);\r
+               boolean reuse = ((initFlag & BasePage.INIT_PAGE_REUSE) != 0);\r
+\r
+               this.page.initPage(instant,\r
+                                                  BasePage.VALID_PAGE,\r
+                                                  nextRecordId,\r
+                                                  overflowPage, reuse);\r
+       }\r
+\r
+       /*\r
+        * Override PageBasicOperation's getPageForRedoRecovery\r
+        */\r
+       /**\r
+               If we are in load tran, this page may not exist for the container yet.\r
+               We need to create it first.\r
+\r
+               This routine is called as the last resort of find page, the container\r
+               handle has already been found and it is not dropped.\r
+\r
+               @exception StandardException Standard Derby policy.\r
+       */\r
+       protected BasePage getPageForRedoRecovery(Transaction xact)\r
+                throws StandardException\r
+       {\r
+               BasePage p = super.getPageForRedoRecovery(xact);\r
+               if (p != null)\r
+                       return p;\r
+\r
+               // create the page\r
+               // RESOLVE: we need the page format to properly recreate an Alloc page\r
+               // NEED TO UPGRADE this log record.\r
+               p = (BasePage)containerHdl.reCreatePageForRedoRecovery(\r
+                                               pageFormatId,                                                              \r
+                                               getPageId().getPageNumber(), \r
+                                               pageOffset);\r
+               return p;\r
+       }\r
+       \r
+\r
+       /*\r
+        * PhysicalPageOperation method\r
+        */\r
+\r
+       /**\r
+               Mark the page as free\r
+\r
+               @exception StandardException Thrown by methods I call\r
+               @exception IOException Thrown by methods I call\r
+\r
+               @see PhysicalPageOperation#undoMe\r
+       */\r
+       public void undoMe(Transaction xact, BasePage undoPage, LogInstant CLRInstant, \r
+                                          LimitObjectInput in)\r
+                throws StandardException, IOException \r
+       {\r
+               undoPage.setPageStatus(CLRInstant, BasePage.INVALID_PAGE);\r
+               // only set the page to invalid, cannot wipe out the page to zero's\r
+               // becuase recovery may need to redo some operations that depend on the\r
+               // content of the page.\r
+\r
+               undoPage.setAuxObject(null);\r
+       }\r
+\r
+\r
+       /*\r
+        * PageBasicOperation methods\r
+        */\r
+       \r
+       /** \r
+        * restore the before image of the page\r
+        *\r
+        * @exception StandardException Standard Derby Error Policy\r
+        * @exception IOException problem reading the complete log record from the\r
+        * input stream\r
+        */\r
+       public void restoreMe(Transaction xact, BasePage undoPage,\r
+                                          LogInstant CLRInstant, LimitObjectInput in)\r
+                throws StandardException, IOException \r
+       {\r
+               undoMe(xact, undoPage, CLRInstant, in);\r
+       }\r
+\r
+       public String toString()\r
+       {\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       boolean overflowPage = ((initFlag & BasePage.INIT_PAGE_OVERFLOW) != 0);\r
+                       boolean reuse = ((initFlag & BasePage.INIT_PAGE_REUSE) != 0);\r
+\r
+                       return super.toString() + "Init Page.  Overflow = "\r
+                               + overflowPage + " reuse " + reuse + " nextRecordId " + nextRecordId;\r
+               }\r
+               else\r
+                       return null;\r
+       }\r
+\r
+}\r