Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / catalog / SYSCONGLOMERATESRowFactory.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/catalog/SYSCONGLOMERATESRowFactory.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/catalog/SYSCONGLOMERATESRowFactory.java
new file mode 100644 (file)
index 0000000..bf5e36d
--- /dev/null
@@ -0,0 +1,443 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.catalog.SYSCONGLOMERATESRowFactory\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.sql.catalog;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.types.SQLChar;\r
+import org.apache.derby.iapi.types.SQLVarchar;\r
+import org.apache.derby.iapi.types.TypeId;\r
+import org.apache.derby.iapi.sql.dictionary.SystemColumn;\r
+import org.apache.derby.catalog.TypeDescriptor;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.types.DataValueFactory;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;\r
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;\r
+\r
+import org.apache.derby.iapi.types.RowLocation;\r
+\r
+import org.apache.derby.iapi.sql.execute.ExecIndexRow;\r
+import org.apache.derby.iapi.sql.execute.ExecRow;\r
+import org.apache.derby.iapi.sql.execute.ExecutionContext;\r
+import org.apache.derby.iapi.sql.execute.ExecutionFactory;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.uuid.UUIDFactory;\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.catalog.IndexDescriptor;\r
+\r
+import java.sql.Types;\r
+import java.util.Properties;\r
+\r
+/**\r
+ * Factory for creating a SYSCONGLOMERATES row.\r
+ *\r
+ */\r
+\r
+public class SYSCONGLOMERATESRowFactory extends CatalogRowFactory\r
+{\r
+       private static final String             TABLENAME_STRING = "SYSCONGLOMERATES";\r
+\r
+       protected static final int              SYSCONGLOMERATES_COLUMN_COUNT = 8;\r
+       protected static final int              SYSCONGLOMERATES_SCHEMAID = 1;\r
+       protected static final int              SYSCONGLOMERATES_TABLEID = 2;\r
+       protected static final int              SYSCONGLOMERATES_CONGLOMERATENUMBER = 3;\r
+       protected static final int              SYSCONGLOMERATES_CONGLOMERATENAME = 4;\r
+       protected static final int              SYSCONGLOMERATES_ISINDEX = 5;\r
+       protected static final int              SYSCONGLOMERATES_DESCRIPTOR = 6;\r
+       protected static final int              SYSCONGLOMERATES_ISCONSTRAINT = 7;\r
+       protected static final int              SYSCONGLOMERATES_CONGLOMERATEID = 8;\r
+\r
+       protected static final int              SYSCONGLOMERATES_INDEX1_ID = 0;\r
+       protected static final int              SYSCONGLOMERATES_INDEX2_ID = 1;\r
+       protected static final int              SYSCONGLOMERATES_INDEX3_ID = 2;\r
+\r
+    private    static  final   boolean[]       uniqueness = {\r
+                                                              false,\r
+                                                                                                          true,\r
+                                                                                                          false\r
+                                                        };\r
+\r
+       private static final int[][] indexColumnPositions =\r
+       {\r
+               {SYSCONGLOMERATES_CONGLOMERATEID},\r
+               {SYSCONGLOMERATES_CONGLOMERATENAME, SYSCONGLOMERATES_SCHEMAID},\r
+               {SYSCONGLOMERATES_TABLEID}\r
+       };\r
+\r
+       private static  final   String[]        uuids =\r
+       {\r
+                "80000010-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID\r
+               ,"80000027-00d0-fd77-3ed8-000a0a0b1900" // heap UUID\r
+               ,"80000012-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX1\r
+               ,"80000014-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX2\r
+               ,"80000016-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX3\r
+       };\r
+\r
+       SYSCONGLOMERATESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf)\r
+       {\r
+               super(uuidf,ef,dvf);\r
+               initInfo(SYSCONGLOMERATES_COLUMN_COUNT, \r
+                                TABLENAME_STRING, indexColumnPositions, \r
+                                uniqueness, uuids );\r
+       }\r
+\r
+  /**\r
+        * Make a SYSCONGLOMERATES row\r
+        *\r
+        * @return      Row suitable for inserting into SYSCONGLOMERATES.\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+       public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)\r
+                                       throws StandardException\r
+       {\r
+               ExecRow                                 row;\r
+               DataValueDescriptor             col;\r
+               String                                  tabID =null;\r
+               Long                                    conglomNumber = null;\r
+               String                                  conglomName = null;\r
+               Boolean                                 supportsIndex = null;\r
+               IndexRowGenerator               indexRowGenerator = null;\r
+               Boolean                                 supportsConstraint = null;\r
+               String                                  conglomUUIDString = null;\r
+               String                                  schemaID = null;\r
+               ConglomerateDescriptor  conglomerate = (ConglomerateDescriptor)td;\r
+\r
+               /* Insert info into sysconglomerates */\r
+\r
+               if (td != null)\r
+               {\r
+                       /* Sometimes the SchemaDescriptor is non-null and sometimes it\r
+                        * is null.  (We can't just rely on getting the schema id from \r
+                        * the ConglomerateDescriptor because it can be null when\r
+                        * we are creating a new conglomerate.\r
+                        */\r
+                       if (parent != null)\r
+                       {\r
+                               SchemaDescriptor sd = (SchemaDescriptor)parent;\r
+                               schemaID = sd.getUUID().toString();     \r
+                       }\r
+                       else\r
+                       {\r
+                               schemaID = conglomerate.getSchemaID().toString();       \r
+                       }\r
+                       tabID = conglomerate.getTableID().toString();\r
+                       conglomNumber = new Long( conglomerate.getConglomerateNumber() );\r
+                       conglomName = conglomerate.getConglomerateName();\r
+                       conglomUUIDString = conglomerate.getUUID().toString();\r
+\r
+                       supportsIndex = new Boolean( conglomerate.isIndex() );\r
+                       indexRowGenerator = conglomerate.getIndexDescriptor();\r
+                       supportsConstraint = new Boolean( conglomerate.isConstraint() );\r
+               }\r
+\r
+               /* RESOLVE - It would be nice to require less knowledge about sysconglomerates\r
+                * and have this be more table driven.\r
+                */\r
+\r
+               /* Build the row to insert */\r
+               row = getExecutionFactory().getValueRow(SYSCONGLOMERATES_COLUMN_COUNT);\r
+\r
+               /* 1st column is SCHEMAID (UUID - char(36)) */\r
+               row.setColumn(1, new SQLChar(schemaID));\r
+\r
+               /* 2nd column is TABLEID (UUID - char(36)) */\r
+               row.setColumn(2, new SQLChar(tabID));\r
+\r
+               /* 3rd column is CONGLOMERATENUMBER (long) */\r
+               row.setColumn(3, dvf.getDataValue(conglomNumber));\r
+\r
+               /* 4th column is CONGLOMERATENAME (varchar(128)) \r
+               ** If null, use the tableid so we always\r
+               ** have a unique column\r
+               */\r
+               row.setColumn(4, (conglomName == null) ?\r
+                new SQLVarchar(tabID): new SQLVarchar(conglomName));\r
+\r
+               /* 5th  column is ISINDEX (boolean) */\r
+               row.setColumn(5, dvf.getDataValue(supportsIndex));\r
+\r
+               /* 6th column is DESCRIPTOR\r
+               *  (user type org.apache.derby.catalog.IndexDescriptor)\r
+               */\r
+               row.setColumn(6,\r
+                       dvf.getDataValue(\r
+                                               (indexRowGenerator == null ?\r
+                                                       (IndexDescriptor) null :\r
+                                                       indexRowGenerator.getIndexDescriptor()\r
+                                               )\r
+                                       )\r
+                               );\r
+\r
+               /* 7th column is ISCONSTRAINT (boolean) */\r
+               row.setColumn(7, dvf.getDataValue(supportsConstraint));\r
+\r
+               /* 8th column is CONGLOMERATEID (UUID - char(36)) */\r
+               row.setColumn(8, new SQLChar(conglomUUIDString));\r
+\r
+               return row;\r
+       }\r
+\r
+       public ExecRow makeEmptyRow() throws StandardException\r
+       {\r
+               return makeRow(null, null);\r
+       }\r
+\r
+\r
+       /**\r
+        * Get the Properties associated with creating the heap.\r
+        *\r
+        * @return The Properties associated with creating the heap.\r
+        */\r
+       public Properties getCreateHeapProperties()\r
+       {\r
+               Properties properties = new Properties();\r
+               // keep page size at 4K since its a big table\r
+               properties.put("derby.storage.pageSize","4096");\r
+               // default properties for system tables:\r
+               properties.put("derby.storage.pageReservedSpace","0");\r
+               properties.put("derby.storage.minimumRecordSize","1");\r
+               return properties;\r
+       }\r
+\r
+       /**\r
+        * Get the Properties associated with creating the specified index.\r
+        *\r
+        * @param indexNumber   The specified index number.\r
+        *\r
+        * @return The Properties associated with creating the specified index.\r
+        */\r
+       public Properties getCreateIndexProperties(int indexNumber)\r
+       {\r
+               Properties properties = new Properties();\r
+               // keep page size for all indexes at 4K since its a big table\r
+               properties.put("derby.storage.pageSize","4096");\r
+               return properties;\r
+       }\r
+\r
+       ///////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory\r
+       //\r
+       ///////////////////////////////////////////////////////////////////////////\r
+\r
+       /**\r
+        *\r
+        * @param row a SYSCOLUMNS row\r
+        * @param parentTupleDescriptor Null for this kind of descriptor.\r
+        * @param dd dataDictionary\r
+        *\r
+        * @return      a conglomerate descriptor equivalent to a SYSCONGOMERATES row\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+\r
+       public TupleDescriptor buildDescriptor(\r
+               ExecRow                                 row,\r
+               TupleDescriptor                 parentTupleDescriptor,\r
+               DataDictionary                  dd )\r
+                                       throws StandardException\r
+       {\r
+               if (SanityManager.DEBUG)\r
+               SanityManager.ASSERT(\r
+                       row.nColumns() == SYSCONGLOMERATES_COLUMN_COUNT, \r
+                       "Wrong number of columns for a SYSCONGLOMERATES row");\r
+\r
+               DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();\r
+               long conglomerateNumber;\r
+               String  name;\r
+               boolean isConstraint;\r
+               boolean isIndex;\r
+               IndexRowGenerator       indexRowGenerator;\r
+               DataValueDescriptor col;\r
+               ConglomerateDescriptor conglomerateDesc;\r
+               String          conglomUUIDString;\r
+               UUID            conglomUUID;\r
+               String          schemaUUIDString;\r
+               UUID            schemaUUID;\r
+               String          tableUUIDString;\r
+               UUID            tableUUID;\r
+\r
+               /* 1st column is SCHEMAID (UUID - char(36)) */\r
+               col = row.getColumn(1);\r
+               schemaUUIDString = col.getString();\r
+               schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);\r
+\r
+               /* 2nd column is TABLEID (UUID - char(36)) */\r
+               col = row.getColumn(2);\r
+               tableUUIDString = col.getString();\r
+               tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);\r
+\r
+\r
+               /* 3nd column is CONGLOMERATENUMBER (long) */\r
+               col = row.getColumn(3);\r
+               conglomerateNumber = col.getLong();\r
+\r
+               /* 4rd column is CONGLOMERATENAME (varchar(128)) */\r
+               col = row.getColumn(4);\r
+               name = col.getString();\r
+\r
+               /* 5th column is ISINDEX (boolean) */\r
+               col = row.getColumn(5);\r
+               isIndex = col.getBoolean();\r
+\r
+               /* 6th column is DESCRIPTOR */\r
+               col = row.getColumn(6);\r
+               indexRowGenerator = new IndexRowGenerator(\r
+                       (IndexDescriptor) col.getObject());\r
+\r
+               /* 7th column is ISCONSTRAINT (boolean) */\r
+               col = row.getColumn(7);\r
+               isConstraint = col.getBoolean();\r
+\r
+               /* 8th column is CONGLOMERATEID (UUID - char(36)) */\r
+               col = row.getColumn(8);\r
+               conglomUUIDString = col.getString();\r
+               conglomUUID = getUUIDFactory().recreateUUID(conglomUUIDString);\r
+\r
+               /* now build and return the descriptor */\r
+               conglomerateDesc = ddg.newConglomerateDescriptor(conglomerateNumber,\r
+                                                                                                                name,\r
+                                                                                                                isIndex,\r
+                                                                                                                indexRowGenerator,\r
+                                                                                                                isConstraint,\r
+                                                                                                                conglomUUID,\r
+                                                                                                                tableUUID,\r
+                                                                                                                schemaUUID);\r
+               return conglomerateDesc;\r
+       }\r
+\r
+       /**\r
+        * Get the conglomerate's UUID of the row.\r
+        * \r
+        * @param row   The row from sysconglomerates\r
+        *\r
+        * @return UUID The conglomerates UUID\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+        protected UUID getConglomerateUUID(ExecRow row)\r
+                throws StandardException\r
+        {\r
+               DataValueDescriptor     col;\r
+               String                          conglomerateUUIDString;\r
+\r
+               /* 8th column is CONGLOMERATEID (UUID - char(36)) */\r
+               col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATEID);\r
+               conglomerateUUIDString = col.getString();\r
+               return getUUIDFactory().recreateUUID(conglomerateUUIDString);\r
+        }\r
+\r
+       /**\r
+        * Get the table's UUID from the row.\r
+        * \r
+        * @param row   The row from sysconglomerates\r
+        *\r
+        * @return UUID The table's UUID\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+        protected UUID getTableUUID(ExecRow row)\r
+                throws StandardException\r
+        {\r
+               DataValueDescriptor     col;\r
+               String                          tableUUIDString;\r
+\r
+               /* 2nd column is TABLEID (UUID - char(36)) */\r
+               col = row.getColumn(SYSCONGLOMERATES_TABLEID);\r
+               tableUUIDString = col.getString();\r
+               return getUUIDFactory().recreateUUID(tableUUIDString);\r
+        }\r
+\r
+       /**\r
+        * Get the schema's UUID from the row.\r
+        * \r
+        * @param row   The row from sysconglomerates\r
+        *\r
+        * @return UUID The schema's UUID\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+        protected UUID getSchemaUUID(ExecRow row)\r
+                throws StandardException\r
+        {\r
+               DataValueDescriptor     col;\r
+               String                          schemaUUIDString;\r
+\r
+               /* 1st column is SCHEMAID (UUID - char(36)) */\r
+               col = row.getColumn(SYSCONGLOMERATES_SCHEMAID);\r
+               schemaUUIDString = col.getString();\r
+               return getUUIDFactory().recreateUUID(schemaUUIDString);\r
+        }\r
+\r
+       /**\r
+        * Get the conglomerate's name of the row.\r
+        * \r
+        * @param row   The row from sysconglomerates\r
+        *\r
+        * @return String       The conglomerates name\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+        protected String getConglomerateName(ExecRow row)\r
+                throws StandardException\r
+        {\r
+               DataValueDescriptor     col;\r
+\r
+               /* 4th column is CONGLOMERATENAME (varchar(128)) */\r
+               col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATENAME);\r
+               return col.getString();\r
+        }\r
+\r
+       /**\r
+        * Builds a list of columns suitable for creating this Catalog.\r
+        *\r
+        *\r
+        * @return array of SystemColumn suitable for making this catalog.\r
+        */\r
+               \r
+       public SystemColumn[]   buildColumnList()\r
+       {\r
+            return new SystemColumn[] {\r
+               SystemColumnImpl.getUUIDColumn("SCHEMAID", false),\r
+               SystemColumnImpl.getUUIDColumn("TABLEID", false),\r
+               SystemColumnImpl.getColumn("CONGLOMERATENUMBER", Types.BIGINT, false),\r
+               SystemColumnImpl.getIdentifierColumn("CONGLOMERATENAME", true),\r
+               SystemColumnImpl.getColumn("ISINDEX", Types.BOOLEAN, false),\r
+               SystemColumnImpl.getJavaColumn("DESCRIPTOR",\r
+                       "org.apache.derby.catalog.IndexDescriptor", true),\r
+               SystemColumnImpl.getColumn("ISCONSTRAINT", Types.BOOLEAN, true),\r
+               SystemColumnImpl.getUUIDColumn("CONGLOMERATEID", false)\r
+           };\r
+       }\r
+}\r