Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / raw / log / FlushedScanHandle.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java
new file mode 100644 (file)
index 0000000..b0097be
--- /dev/null
@@ -0,0 +1,187 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.log.FlushedScanHandle\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.log;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.impl.store.raw.log.LogCounter;\r
+import org.apache.derby.impl.store.raw.log.LogRecord;\r
+import org.apache.derby.impl.store.raw.log.StreamLogScan;\r
+import org.apache.derby.iapi.services.io.ArrayInputStream;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.store.raw.Loggable;\r
+import org.apache.derby.iapi.store.raw.ScanHandle;\r
+import org.apache.derby.iapi.store.raw.ScannedTransactionHandle;\r
+import org.apache.derby.iapi.store.raw.log.LogFactory;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+import org.apache.derby.iapi.store.raw.xact.TransactionId;\r
+import org.apache.derby.iapi.store.access.DatabaseInstant;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.util.Enumeration;\r
+\r
+public class FlushedScanHandle implements ScanHandle\r
+{\r
+       LogFactory lf;\r
+       StreamLogScan fs;\r
+       \r
+       LogRecord lr = null;\r
+       boolean readOptionalData = false;\r
+       int groupsIWant;\r
+       \r
+       ArrayInputStream rawInput = new ArrayInputStream(new byte[4096]);\r
+       \r
+       FlushedScanHandle(LogToFile lf, DatabaseInstant start, int groupsIWant)\r
+                throws StandardException\r
+       {\r
+               this.lf = lf;\r
+               fs = new FlushedScan(lf,((LogCounter)start).getValueAsLong());\r
+               this.groupsIWant = groupsIWant;\r
+       }\r
+       \r
+       public boolean next() throws StandardException\r
+       {\r
+               readOptionalData = false;\r
+               lr = null; \r
+\r
+               // filter the log stream so that only log records that belong to these\r
+               // interesting groups will be returned\r
+\r
+               try\r
+               {\r
+                       lr = fs.getNextRecord(rawInput,null, groupsIWant);\r
+                       if (lr==null) return false; //End of flushed log\r
+                       if (SanityManager.DEBUG)\r
+            {\r
+                if ((groupsIWant & lr.group()) == 0)\r
+                    SanityManager.THROWASSERT(groupsIWant + "/" + lr.group());\r
+            }\r
+\r
+                       return true;\r
+               }\r
+               catch (IOException ioe)\r
+               {\r
+                       ioe.printStackTrace();\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                    StandardException.newException(SQLState.LOG_IO_ERROR, ioe));\r
+               }\r
+       }\r
+\r
+       /**\r
+         Get the group for the current log record.\r
+         @exception StandardException Oops\r
+         */\r
+       public int getGroup() throws StandardException\r
+       {\r
+               return lr.group();\r
+       }\r
+\r
+       /**\r
+         Get the Loggable associated with the currentLogRecord\r
+         @exception StandardException Oops\r
+         */\r
+       public Loggable getLoggable() throws StandardException\r
+       {\r
+               try {\r
+                       return lr.getLoggable();\r
+               }\r
+\r
+               catch (IOException ioe)\r
+               {\r
+                       ioe.printStackTrace();\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                    StandardException.newException(SQLState.LOG_IO_ERROR, ioe));\r
+               }\r
+\r
+               catch (ClassNotFoundException cnfe)\r
+               {\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                StandardException.newException(SQLState.LOG_CORRUPTED, cnfe));\r
+               }\r
+       }\r
+\r
+       //This may be called only once per log record.\r
+    public InputStream getOptionalData()\r
+                throws StandardException\r
+       {\r
+               if (SanityManager.DEBUG) SanityManager.ASSERT(!readOptionalData);\r
+               if (lr == null) return null;\r
+               try\r
+               {\r
+                       int dataLength = rawInput.readInt();\r
+                       readOptionalData = true;\r
+                       rawInput.setLimit(dataLength);\r
+                       return rawInput;\r
+               }\r
+\r
+               catch (IOException ioe)\r
+               {\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                    StandardException.newException(SQLState.LOG_IO_ERROR, ioe));\r
+               }\r
+       }\r
+\r
+    public DatabaseInstant getInstant()\r
+                throws StandardException\r
+       {\r
+               return fs.getLogInstant();\r
+       }\r
+\r
+       public Object getTransactionId()\r
+                throws StandardException\r
+       {  \r
+               try\r
+        {\r
+                       return lr.getTransactionId();\r
+               }\r
+               catch (IOException ioe)\r
+               {\r
+                       ioe.printStackTrace();\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                    StandardException.newException(SQLState.LOG_IO_ERROR, ioe));\r
+               }\r
+               catch (ClassNotFoundException cnfe)\r
+               {\r
+                       fs.close();\r
+                       fs = null;\r
+                       throw lf.markCorrupt(\r
+                StandardException.newException(SQLState.LOG_CORRUPTED, cnfe));\r
+               }\r
+       }\r
+\r
+    public void close()\r
+       {\r
+               if (fs != null) fs.close();\r
+               fs = null;\r
+       }\r
+}\r