--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.catalog.SYSSCHEMASRowFactory\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.types.DataTypeDescriptor;\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.DataValueDescriptor;\r
+\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.DataValueFactory;\r
+import org.apache.derby.iapi.types.RowLocation;\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.TupleDescriptor;\r
+\r
+import org.apache.derby.iapi.sql.execute.ExecutionFactory;\r
+import org.apache.derby.iapi.sql.execute.ExecIndexRow;\r
+import org.apache.derby.iapi.sql.execute.ExecRow;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.services.uuid.UUIDFactory;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+/**\r
+ * Factory for creating a SYSSCHEMAS row.\r
+ *\r
+ *\r
+ * @version 0.1\r
+ */\r
+\r
+public class SYSSCHEMASRowFactory extends CatalogRowFactory\r
+{\r
+ private static final String TABLENAME_STRING = "SYSSCHEMAS";\r
+\r
+ public static final int SYSSCHEMAS_COLUMN_COUNT = 3;\r
+ /* Column #s for sysinfo (1 based) */\r
+ public static final int SYSSCHEMAS_SCHEMAID = 1;\r
+ public static final int SYSSCHEMAS_SCHEMANAME = 2;\r
+ public static final int SYSSCHEMAS_SCHEMAAID = 3;\r
+\r
+ protected static final int SYSSCHEMAS_INDEX1_ID = 0;\r
+ protected static final int SYSSCHEMAS_INDEX2_ID = 1;\r
+\r
+\r
+ private static final int[][] indexColumnPositions =\r
+ {\r
+ {SYSSCHEMAS_SCHEMANAME},\r
+ {SYSSCHEMAS_SCHEMAID}\r
+ };\r
+ \r
+ private static final boolean[] uniqueness = null;\r
+\r
+ private static final String[] uuids =\r
+ {\r
+ "80000022-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID\r
+ ,"8000002a-00d0-fd77-3ed8-000a0a0b1900" // heap UUID\r
+ ,"80000024-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX1\r
+ ,"80000026-00d0-fd77-3ed8-000a0a0b1900" // SYSSCHEMAS_INDEX2\r
+ };\r
+\r
+ /////////////////////////////////////////////////////////////////////////////\r
+ //\r
+ // CONSTRUCTORS\r
+ //\r
+ /////////////////////////////////////////////////////////////////////////////\r
+\r
+ SYSSCHEMASRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf)\r
+ {\r
+ super(uuidf,ef,dvf);\r
+ initInfo(SYSSCHEMAS_COLUMN_COUNT, TABLENAME_STRING, \r
+ indexColumnPositions, uniqueness, uuids );\r
+ }\r
+\r
+ /////////////////////////////////////////////////////////////////////////////\r
+ //\r
+ // METHODS\r
+ //\r
+ /////////////////////////////////////////////////////////////////////////////\r
+\r
+ /**\r
+ * Make a SYSSCHEMAS row\r
+ *\r
+ * @return Row suitable for inserting into SYSSCHEMAS.\r
+ *\r
+ * @exception StandardException thrown on failure\r
+ */\r
+\r
+ public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)\r
+ throws StandardException\r
+ {\r
+ DataTypeDescriptor dtd;\r
+ ExecRow row;\r
+ DataValueDescriptor col;\r
+ String name = null;\r
+ UUID oid = null;\r
+ String uuid = null; \r
+ String aid = null;\r
+\r
+ if (td != null)\r
+ {\r
+ SchemaDescriptor schemaDescriptor = (SchemaDescriptor)td;\r
+\r
+ name = schemaDescriptor.getSchemaName();\r
+ oid = schemaDescriptor.getUUID();\r
+ if ( oid == null )\r
+ {\r
+ oid = getUUIDFactory().createUUID();\r
+ schemaDescriptor.setUUID(oid);\r
+ }\r
+ uuid = oid.toString();\r
+\r
+ aid = schemaDescriptor.getAuthorizationId();\r
+ }\r
+\r
+ /* Build the row to insert */\r
+ row = getExecutionFactory().getValueRow(SYSSCHEMAS_COLUMN_COUNT);\r
+\r
+ /* 1st column is SCHEMAID */\r
+ row.setColumn(1, new SQLChar(uuid));\r
+\r
+ /* 2nd column is SCHEMANAME */\r
+ row.setColumn(2, new SQLVarchar(name));\r
+\r
+ /* 3rd column is SCHEMAAID */\r
+ row.setColumn(3, new SQLVarchar(aid));\r
+\r
+ return row;\r
+ }\r
+\r
+\r
+ ///////////////////////////////////////////////////////////////////////////\r
+ //\r
+ // ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory\r
+ //\r
+ ///////////////////////////////////////////////////////////////////////////\r
+\r
+ /**\r
+ * Make an Tuple Descriptor out of a SYSSCHEMAS row\r
+ *\r
+ * @param row a SYSSCHEMAS row\r
+ * @param parentTupleDescriptor unused\r
+ * @param dd dataDictionary\r
+ *\r
+ * @return a descriptor equivalent to a SYSSCHEMAS 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
+ DataValueDescriptor col;\r
+ SchemaDescriptor descriptor;\r
+ String name;\r
+ UUID id;\r
+ String aid;\r
+ String uuid;\r
+ DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();\r
+\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(row.nColumns() == SYSSCHEMAS_COLUMN_COUNT, \r
+ "Wrong number of columns for a SYSSCHEMAS row");\r
+ }\r
+\r
+ // first column is schemaid (UUID - char(36))\r
+ col = row.getColumn(1);\r
+ uuid = col.getString();\r
+ id = getUUIDFactory().recreateUUID(uuid);\r
+\r
+ // second column is schemaname (varchar(128))\r
+ col = row.getColumn(2);\r
+ name = col.getString();\r
+\r
+ // third column is auid (varchar(128))\r
+ col = row.getColumn(3);\r
+ aid = col.getString();\r
+\r
+ descriptor = ddg.newSchemaDescriptor(name, aid, id);\r
+\r
+ return descriptor;\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("SCHEMAID", false),\r
+ SystemColumnImpl.getIdentifierColumn("SCHEMANAME", false),\r
+ SystemColumnImpl.getIdentifierColumn("AUTHORIZATIONID", false),\r
+ };\r
+ }\r
+}\r