Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / access / conglomerate / OpenConglomerateScratchSpace.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/conglomerate/OpenConglomerateScratchSpace.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/conglomerate/OpenConglomerateScratchSpace.java
new file mode 100644 (file)
index 0000000..cba50fd
--- /dev/null
@@ -0,0 +1,225 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.conglomerate.OpenConglomerateScratchSpace\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.error.StandardException; \r
+\r
+import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;\r
+import org.apache.derby.iapi.store.access.RowUtil;\r
+\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.services.io.FormatableBitSet;\r
+import org.apache.derby.iapi.services.loader.InstanceGetter;\r
+\r
+/**\r
+\r
+A utility class to store and use temporary scratch space associated with\r
+a conglomerate.\r
+\r
+**/\r
+\r
+public class OpenConglomerateScratchSpace \r
+    implements DynamicCompiledOpenConglomInfo\r
+{\r
+\r
+    /**************************************************************************\r
+     * Fields of the class\r
+     **************************************************************************\r
+     */\r
+\r
+    /**\r
+     * A template of info about the classes in the returned row.\r
+     * <p>\r
+     * This template is allocated on demand, and is used to efficiently\r
+     * create new rows for export from this class.  This variable is for\r
+     * use by get_row_for_export().\r
+     **/\r
+    private FormatableBitSet        row_for_export_column_list;\r
+    private DataValueDescriptor[]   row_for_export_template;\r
+\r
+    /**\r
+     * A Scratch template used for searching and qualifying rows in the \r
+     * conglomerate.  This is a full template, independent of the \r
+     * FormatableBitSet used for access.\r
+     **/\r
+    private DataValueDescriptor[]   scratch_template;\r
+\r
+    /**\r
+     * A Scratch row used for qualifying rows in the \r
+     * conglomerate.  This is a row which matches the FormatableBitSet of rows\r
+     * being returned.\r
+     **/\r
+    private DataValueDescriptor[]   scratch_row;\r
+\r
+    /**\r
+     * A complete array of format id's and collation_ids for this conglomerate.\r
+     **/\r
+    private int[]                   format_ids;\r
+    private int[]                   collation_ids;\r
+\r
+\r
+    /* scratch space used by ConglomerateController.delete and replace */\r
+    private RowPosition             scratch_row_position;\r
+\r
+    /**************************************************************************\r
+     * Constructors for This class:\r
+     **************************************************************************\r
+     */\r
+    public OpenConglomerateScratchSpace(\r
+    int[]   format_ids,\r
+    int[]   collation_ids)\r
+    {\r
+        this.format_ids     = format_ids;\r
+        this.collation_ids  = collation_ids;\r
+    }\r
+\r
+    /**************************************************************************\r
+     * Private/Protected methods of This class:\r
+     **************************************************************************\r
+     */\r
+\r
+    /**************************************************************************\r
+     * Public Methods of This class:\r
+     **************************************************************************\r
+     */\r
+\r
+    /**\r
+     * Return an empty template (possibly partial) row to be given back to \r
+     * a client.\r
+     * <p>\r
+     * The main use of this is for fetchSet() and fetchNextGroup() which\r
+     * allocate rows and then give them back entirely to the caller.\r
+     * <p>\r
+     *\r
+        * @return The row to use.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public DataValueDescriptor[] get_row_for_export(Transaction rawtran)\r
+        throws StandardException\r
+    {\r
+        // Create a partial row class template template from the initial scan\r
+        // parameters.\r
+        if (row_for_export_template == null)\r
+        {\r
+            row_for_export_template = \r
+                RowUtil.newTemplate(\r
+                    rawtran.getDataValueFactory(), \r
+                    row_for_export_column_list, format_ids, collation_ids);\r
+        }\r
+\r
+        // Allocate a new row based on the class template.\r
+        return(RowUtil.newRowFromTemplate(row_for_export_template));\r
+    }\r
+\r
+    /**\r
+     * Return an empty template (possibly partial) row to be used and \r
+     * reused internally for processing.\r
+     * <p>\r
+     * The main use of this is for qualifying rows where a row has not been\r
+     * provided by the client.  This routine cache's a single row for reuse\r
+     * by the caller, if the caller needs 2 concurrent scratch rows, some other\r
+     * mechanism must be used.\r
+     * <p>\r
+     *\r
+        * @return The row to use.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public DataValueDescriptor[] get_scratch_row(Transaction    rawtran)\r
+        throws StandardException\r
+    {\r
+        // Create a partial row class template template from the initial scan\r
+        // parameters.\r
+        if (scratch_row == null)\r
+        {\r
+            scratch_row = get_row_for_export(rawtran);\r
+        }\r
+\r
+        // Allocate a new row based on the class template.\r
+        return(scratch_row);\r
+    }\r
+\r
+    /**\r
+     * Return a complete empty row.  \r
+     * <p>\r
+     * The main use of this is for searching a tree where a complete copy of\r
+     * the row is needed for searching.\r
+     * <p>\r
+     *\r
+        * @return The template to use.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public DataValueDescriptor[] get_template(Transaction rawtran)\r
+        throws StandardException\r
+    {\r
+        // Create a partial row class template from the initial scan parameters.\r
+        if (scratch_template == null)\r
+        {\r
+            scratch_template = \r
+                TemplateRow.newRow(\r
+                    rawtran, \r
+                    (FormatableBitSet) null, format_ids, collation_ids);\r
+        }\r
+\r
+        return(scratch_template);\r
+    }\r
+\r
+    /**\r
+     * Return a scratch RowPosition.\r
+     * <p>\r
+     * Used by GenericConglomerateController.delete() and \r
+     * GenericConglomerateController.replace().  It may be reused so callers\r
+     * must insure that object no longer needed before next possible call\r
+     * to get it again.\r
+     * <p>\r
+     *\r
+        * @return a scratch RowPosition.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public RowPosition get_scratch_row_position()\r
+    {\r
+        if (scratch_row_position == null)\r
+        {\r
+            scratch_row_position = new RowPosition();\r
+        }\r
+\r
+        return(scratch_row_position);\r
+    }\r
+\r
+    /**\r
+     * Initialize scratch space for reuse by possibly different template.\r
+     * <p>\r
+     * Some data is only valid per statement.\r
+     **/\r
+    public void init(\r
+    FormatableBitSet export_column_list)\r
+    {\r
+        row_for_export_template       = null;\r
+        row_for_export_column_list    = null;\r
+    }\r
+}\r