Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / catalog / SYSFILESRowFactory.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/catalog/SYSFILESRowFactory.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/catalog/SYSFILESRowFactory.java
new file mode 100644 (file)
index 0000000..205dd97
--- /dev/null
@@ -0,0 +1,257 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.catalog.SYSFILESRowFactory\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.monitor.Monitor;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.db.Database;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;\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.SchemaDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.SystemColumn;\r
+import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;\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.types.DataValueFactory;\r
+import org.apache.derby.iapi.types.RowLocation;\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
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+import org.apache.derby.iapi.types.TypeId;\r
+import org.apache.derby.iapi.services.uuid.UUIDFactory;\r
+import org.apache.derby.catalog.TypeDescriptor;\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import java.sql.Types;\r
+import java.util.Properties;\r
+\r
+/**\r
+ * Factory for creating a SYSFILES row.\r
+ *\r
+ *\r
+ * @version 0.1\r
+ */\r
+\r
+class SYSFILESRowFactory extends CatalogRowFactory\r
+{\r
+       private static final String     TABLENAME_STRING = "SYSFILES";\r
+\r
+    private static final int           SYSFILES_COLUMN_COUNT = 4;\r
+\r
+       /* Column #s (1 based) */\r
+    private static final int           ID_COL_NUM = 1;\r
+    private static final String   ID_COL_NAME = "FILEID";\r
+\r
+    private static final int           SCHEMA_ID_COL_NUM = 2;\r
+    private static final String   SCHEMA_ID_COL_NAME = "SCHEMAID";\r
+\r
+    private static final int           NAME_COL_NUM = 3;\r
+    private static final String   NAME_COL_NAME = "FILENAME";\r
+\r
+    private static final int           GENERATION_ID_COL_NUM = 4;\r
+    private static final String   GENERATION_ID_COL_NAME = "GENERATIONID";\r
+\r
+    static final int           SYSFILES_INDEX1_ID = 0;\r
+    static final int           SYSFILES_INDEX2_ID = 1;\r
+\r
+       private static final int[][] indexColumnPositions =\r
+       {\r
+               {NAME_COL_NUM, SCHEMA_ID_COL_NUM},\r
+               {ID_COL_NUM}\r
+       };\r
+\r
+    private    static  final   boolean[]       uniqueness = null;\r
+\r
+       private static  final   String[]        uuids =\r
+       {\r
+               "80000000-00d3-e222-873f-000a0a0b1900", // catalog UUID\r
+               "80000000-00d3-e222-9920-000a0a0b1900", // heap UUID\r
+               "80000000-00d3-e222-a373-000a0a0b1900", // SYSSQLFILES_INDEX1\r
+               "80000000-00d3-e222-be7b-000a0a0b1900"  // SYSSQLFILES_INDEX2\r
+       };\r
+\r
+       /////////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      CONSTRUCTORS\r
+       //\r
+       /////////////////////////////////////////////////////////////////////////////\r
+\r
+    SYSFILESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf) \r
+       {\r
+               super(uuidf,ef,dvf);\r
+               initInfo(SYSFILES_COLUMN_COUNT, TABLENAME_STRING, \r
+                                indexColumnPositions, uniqueness, uuids );\r
+       }\r
+\r
+       /////////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      METHODS\r
+       //\r
+       /////////////////////////////////////////////////////////////////////////////\r
+\r
+       /**\r
+        * Make a SYSFILES row\r
+        *\r
+        * @return      Row suitable for inserting into SYSFILES\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+\r
+       public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)\r
+                                       throws StandardException\r
+       {\r
+               String                                  id_S = null;\r
+               String                                  schemaId_S = null;\r
+               String                  SQLname = null;\r
+               long                    generationId = 0;\r
+               \r
+               ExecRow                         row;\r
+\r
+               if (td != null) \r
+               {\r
+                       FileInfoDescriptor descriptor = (FileInfoDescriptor)td;\r
+                       id_S = descriptor.getUUID().toString();\r
+                       schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString();\r
+                       SQLname = descriptor.getName();\r
+                       generationId = descriptor.getGenerationId();\r
+               }\r
+       \r
+               /* Build the row to insert  */\r
+               row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);\r
+\r
+               /* 1st column is ID (UUID - char(36)) */\r
+               row.setColumn(ID_COL_NUM, new SQLChar(id_S));\r
+\r
+               /* 2nd column is SCHEMAID (UUID - char(36)) */\r
+               row.setColumn(SCHEMA_ID_COL_NUM, new SQLChar(schemaId_S));\r
+\r
+               /* 3rd column is NAME (varchar(30)) */\r
+               row.setColumn(NAME_COL_NUM, new SQLVarchar(SQLname));\r
+\r
+               /* 4th column is GENERATIONID (long) */\r
+               row.setColumn(GENERATION_ID_COL_NUM, dvf.getDataValue(generationId));\r
+\r
+               return row;\r
+       }\r
+\r
+       ///////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory\r
+       //\r
+       ///////////////////////////////////////////////////////////////////////////\r
+\r
+       /**\r
+        * Make a descriptor out of a SYSFILES row\r
+        *\r
+        * @param row a row\r
+        * @param parentTupleDescriptor Null for this kind of descriptor.\r
+        * @param dd dataDictionary\r
+        *\r
+        * @return      a descriptor equivalent to a row\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+       public TupleDescriptor buildDescriptor(\r
+               ExecRow                                 row,\r
+               TupleDescriptor                 parentTupleDescriptor,\r
+               DataDictionary                  dd )\r
+                                       throws StandardException\r
+       {\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       if (row.nColumns() != SYSFILES_COLUMN_COUNT)\r
+                       {\r
+                               SanityManager.THROWASSERT("Wrong number of columns for a SYSFILES row: "+\r
+                                                        row.nColumns());\r
+                       }\r
+               }\r
+\r
+               DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();\r
+\r
+               String  id_S;\r
+               UUID    id;\r
+               String  schemaId_S;\r
+               UUID    schemaId;\r
+               String  name;\r
+               long     generationId;\r
+               DataValueDescriptor     col;\r
+\r
+               SchemaDescriptor        schemaDescriptor;\r
+               FileInfoDescriptor      result;\r
+\r
+               /* 1st column is ID (UUID - char(36)) */\r
+               col = row.getColumn(ID_COL_NUM);\r
+               id_S = col.getString();\r
+               id = getUUIDFactory().recreateUUID(id_S);\r
+\r
+               /* 2nd column is SchemaId */\r
+               col = row.getColumn(SCHEMA_ID_COL_NUM);\r
+               schemaId_S = col.getString();\r
+               schemaId = getUUIDFactory().recreateUUID(schemaId_S);\r
+               \r
+               schemaDescriptor = dd.getSchemaDescriptor(schemaId, null);\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       if (schemaDescriptor == null)\r
+                       {\r
+                               SanityManager.THROWASSERT("Missing schema for FileInfo: "+id_S);\r
+                       }\r
+               }\r
+\r
+               /* 3nd column is NAME (varchar(128)) */\r
+               col = row.getColumn(NAME_COL_NUM);\r
+               name = col.getString();\r
+\r
+               /* 4th column is generationId (long) */\r
+               col = row.getColumn(GENERATION_ID_COL_NUM);\r
+               generationId = col.getLong();\r
+\r
+           result = ddg.newFileInfoDescriptor(id,schemaDescriptor,name,\r
+                                                                                  generationId);\r
+               return result;\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
+    public SystemColumn[]   buildColumnList()\r
+    {\r
+        return new SystemColumn[] {\r
+           SystemColumnImpl.getUUIDColumn(ID_COL_NAME, false),\r
+           SystemColumnImpl.getUUIDColumn(SCHEMA_ID_COL_NAME, false),\r
+           SystemColumnImpl.getIdentifierColumn(NAME_COL_NAME, false),\r
+           SystemColumnImpl.getColumn(GENERATION_ID_COL_NAME, Types.BIGINT, false)\r
+                \r
+        };\r
+    }\r
+}\r