Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / access / conglomerate / BinaryOrderableWrapper.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/conglomerate/BinaryOrderableWrapper.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/conglomerate/BinaryOrderableWrapper.java
new file mode 100644 (file)
index 0000000..35f5d91
--- /dev/null
@@ -0,0 +1,180 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.conglomerate.BinaryOrderableWrapper\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.access.conglomerate;\r
+\r
+import org.apache.derby.iapi.services.io.ArrayInputStream;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.services.io.Storable;\r
+import org.apache.derby.iapi.services.io.TypedFormat;\r
+\r
+import org.apache.derby.iapi.store.access.BinaryOrderable;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+\r
+The BinaryOrderableWrapper is a wrapper class which intercepts the \r
+readExternal() callback made by raw store during a fetch, and does a comparison\r
+instead.\r
+**/\r
+\r
+class BinaryOrderableWrapper implements Storable\r
+{\r
+\r
+    BinaryOrderable    ref_object; \r
+    BinaryOrderable    other_object;\r
+    int                cmp_result;\r
+\r
+    /* Constructors for This class: */\r
+    BinaryOrderableWrapper()\r
+    {\r
+    }\r
+\r
+    /* Private/Protected methods of This class: */\r
+    /**\r
+     * Short one line description of routine.\r
+     * <p>\r
+     * Longer descrption of routine.\r
+     * <p>\r
+     *\r
+     * @param ref_object    The object that this object is wrapping (ie. being\r
+     *                      read from disk)\r
+     * @param other_object  The object to compare ref_object to.\r
+     **/\r
+    protected void init (\r
+    BinaryOrderable ref_object,\r
+    BinaryOrderable other_object)\r
+    {\r
+        this.ref_object     = ref_object;\r
+        this.other_object   = other_object;\r
+    }\r
+\r
+    /* Public Methods of This class: */\r
+    /**\r
+     * Short one line description of routine.\r
+     * <p>\r
+     * Longer descrption of routine.\r
+     * <p>\r
+     *\r
+        * @return The identifier to be used to open the conglomerate later.\r
+     **/\r
+    public int getCmpResult()\r
+    {\r
+        return(this.cmp_result);\r
+    }\r
+\r
+\r
+    /* Public Methods of Storable interface - Externalizable, TypedFormat: \r
+    */\r
+\r
+       public int getTypeFormatId() {\r
+        // RESOLVE - what should this return?\r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("If someone calls this it is a problem.");\r
+        return(((TypedFormat)this.ref_object).getTypeFormatId());\r
+       }\r
+\r
+       /**\r
+       Return whether the value is null or not.\r
+       The containerid being zero is what determines nullness;  subclasses\r
+       are not expected to override this method.\r
+       @see org.apache.derby.iapi.services.io.Storable#isNull\r
+       **/\r
+       public boolean isNull()\r
+       {\r
+        // RESOLVE - what does it mean for this wrapper to be called isNull()?\r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("If someone calls this it is a problem.");\r
+        return(false);\r
+       }\r
+\r
+       /**\r
+       Restore the in-memory representation to the null value.\r
+       The containerid being zero is what determines nullness;  subclasses\r
+       are not expected to override this method.\r
+\r
+       @see org.apache.derby.iapi.services.io.Storable#restoreToNull\r
+       **/\r
+       public void restoreToNull()\r
+       {\r
+        // RESOLVE - base object is null.\r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("WORK TODO - code up null compare.");\r
+\r
+        return;\r
+       }\r
+\r
+       /**\r
+       Restore the in-memory representation from the stream.\r
+\r
+       @exception ClassNotFoundException Thrown if the stored representation is\r
+       serialized and a class named in the stream could not be found.\r
+\r
+    @exception IOException thrown by readObject()\r
+\r
+       \r
+       @see java.io.Externalizable#readExternal\r
+       */\r
+       public void readExternal(ObjectInput in) \r
+        throws IOException, ClassNotFoundException\r
+       {\r
+\r
+        // do the read byte by byte and return the comparison \r
+        this.cmp_result = this.ref_object.binarycompare(in, this.other_object);\r
+        \r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("WORK TODO - code up readExternal.");\r
+       }\r
+       public void readExternalFromArray(ArrayInputStream in) \r
+        throws IOException, ClassNotFoundException\r
+       {\r
+\r
+        // do the read byte by byte and return the comparison \r
+        this.cmp_result = this.ref_object.binarycompare(in, this.other_object);\r
+        \r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("WORK TODO - code up readExternal.");\r
+       }\r
+       \r
+    /**\r
+     * Store the stored representation of the column value in the stream.\r
+     * <p>\r
+     * A BinaryOrderableWrapper is never used to store data out, only to read\r
+     * data from disk and compare it to another byte stream.\r
+     *\r
+     * @param out    Stream to write the object to.\r
+     *\r
+     * @exception IOException thrown by writeObject()\r
+     *\r
+     **/\r
+       public void writeExternal(ObjectOutput out) \r
+        throws IOException\r
+    {\r
+        if (SanityManager.DEBUG)\r
+            SanityManager.THROWASSERT("Write should never be called.");\r
+        return;\r
+       }\r
+}\r