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 / SYSCHECKSRowFactory.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/catalog/SYSCHECKSRowFactory.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/catalog/SYSCHECKSRowFactory.java
new file mode 100644 (file)
index 0000000..e4cb74d
--- /dev/null
@@ -0,0 +1,225 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.catalog.SYSCHECKSRowFactory\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 java.sql.Types;\r
+\r
+import org.apache.derby.catalog.ReferencedColumns;\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.uuid.UUIDFactory;\r
+import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;\r
+import org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor;\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.SubCheckConstraintDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.SystemColumn;\r
+import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;\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.ExecutionFactory;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+import org.apache.derby.iapi.types.DataValueFactory;\r
+import org.apache.derby.iapi.types.SQLChar;\r
+\r
+/**\r
+ * Factory for creating a SYSCHECKS row.\r
+ *\r
+ */\r
+\r
+class SYSCHECKSRowFactory extends CatalogRowFactory\r
+{\r
+       private  static final String    TABLENAME_STRING = "SYSCHECKS";\r
+\r
+       private static final int                SYSCHECKS_COLUMN_COUNT = 3;\r
+       private static final int                SYSCHECKS_CONSTRAINTID = 1;\r
+       private static final int                SYSCHECKS_CHECKDEFINITION = 2;\r
+       private static final int                SYSCHECKS_REFERENCEDCOLUMNS = 3;\r
+\r
+       static final int                SYSCHECKS_INDEX1_ID = 0;\r
+\r
+       // index is unique.\r
+    private    static  final   boolean[]       uniqueness = null;\r
+\r
+       private static final int[][] indexColumnPositions =\r
+       {       \r
+               {SYSCHECKS_CONSTRAINTID}\r
+       };\r
+\r
+       private static  final   String[]        uuids =\r
+       {\r
+                "80000056-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID\r
+               ,"80000059-00d0-fd77-3ed8-000a0a0b1900" // heap UUID\r
+               ,"80000058-00d0-fd77-3ed8-000a0a0b1900" // SYSCHECKS_INDEX1 UUID\r
+       };\r
+\r
+\r
+\r
+       /////////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      CONSTRUCTORS\r
+       //\r
+       /////////////////////////////////////////////////////////////////////////////\r
+\r
+       SYSCHECKSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf)\r
+       {\r
+               super(uuidf,ef,dvf);\r
+               initInfo(SYSCHECKS_COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, uniqueness, uuids );\r
+       }\r
+\r
+       /////////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      METHODS\r
+       //\r
+       /////////////////////////////////////////////////////////////////////////////\r
+\r
+  /**\r
+        * Make a SYSCHECKS row\r
+        *\r
+        * @param td CheckConstraintDescriptorImpl\r
+        *\r
+        * @return      Row suitable for inserting into SYSCHECKS.\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+       public ExecRow makeRow(TupleDescriptor  td, TupleDescriptor parent)\r
+                                       throws StandardException \r
+       {\r
+               DataValueDescriptor             col;\r
+               ExecIndexRow                    row;\r
+               ReferencedColumns rcd = null;\r
+               String                                  checkDefinition = null;\r
+               String                                  constraintID = null;\r
+\r
+               if (td != null)\r
+               {\r
+                       CheckConstraintDescriptor cd = (CheckConstraintDescriptor)td;\r
+                       /*\r
+                       ** We only allocate a new UUID if the descriptor doesn't already have one.\r
+                       ** For descriptors replicated from a Source system, we already have an UUID.\r
+                       */\r
+                       constraintID = cd.getUUID().toString();\r
+\r
+                       checkDefinition = cd.getConstraintText();\r
+\r
+                       rcd = cd.getReferencedColumnsDescriptor();\r
+               }\r
+\r
+               /* Build the row */\r
+               row = getExecutionFactory().getIndexableRow(SYSCHECKS_COLUMN_COUNT);\r
+\r
+               /* 1st column is CONSTRAINTID (UUID - char(36)) */\r
+               row.setColumn(SYSCHECKS_CONSTRAINTID, new SQLChar(constraintID));\r
+\r
+               /* 2nd column is CHECKDEFINITION */\r
+               row.setColumn(SYSCHECKS_CHECKDEFINITION,\r
+                               dvf.getLongvarcharDataValue(checkDefinition));\r
+\r
+               /* 3rd column is REFERENCEDCOLUMNS\r
+                *  (user type org.apache.derby.catalog.ReferencedColumns)\r
+                */\r
+               row.setColumn(SYSCHECKS_REFERENCEDCOLUMNS,\r
+                       dvf.getDataValue(rcd));\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 ViewDescriptor out of a SYSCHECKS row\r
+        *\r
+        * @param row a SYSCHECKS row\r
+        * @param parentTupleDescriptor Null for this kind of descriptor.\r
+        * @param dd dataDictionary\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
+               SubCheckConstraintDescriptor checkDesc = null;\r
+\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       SanityManager.ASSERT(\r
+                               row.nColumns() == SYSCHECKS_COLUMN_COUNT, \r
+                               "Wrong number of columns for a SYSCHECKS row");\r
+               }\r
+\r
+               DataValueDescriptor             col;\r
+               DataDescriptorGenerator ddg;\r
+               ReferencedColumns       referencedColumns;\r
+               String                          constraintText;\r
+               String                          constraintUUIDString;\r
+               UUID                            constraintUUID;\r
+\r
+               ddg = dd.getDataDescriptorGenerator();\r
+\r
+               /* 1st column is CONSTRAINTID (UUID - char(36)) */\r
+               col = row.getColumn(SYSCHECKS_CONSTRAINTID);\r
+               constraintUUIDString = col.getString();\r
+               constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);\r
+\r
+               /* 2nd column is CHECKDEFINITION */\r
+               col = row.getColumn(SYSCHECKS_CHECKDEFINITION);\r
+               constraintText = col.getString();\r
+\r
+               /* 3rd column is REFERENCEDCOLUMNS */\r
+               col = row.getColumn(SYSCHECKS_REFERENCEDCOLUMNS);\r
+               referencedColumns =\r
+                       (ReferencedColumns) col.getObject();\r
+\r
+               /* now build and return the descriptor */\r
+\r
+               checkDesc = new SubCheckConstraintDescriptor(\r
+                                                                               constraintUUID,\r
+                                                                               constraintText,\r
+                                                                               referencedColumns);\r
+               return checkDesc;\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("CONSTRAINTID", false),\r
+            SystemColumnImpl.getColumn("CHECKDEFINITION", Types.LONGVARCHAR, false),\r
+            SystemColumnImpl.getJavaColumn("REFERENCEDCOLUMNS",\r
+                    "org.apache.derby.catalog.ReferencedColumns", false)             \r
+        };\r
+    }\r
+}\r