--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.catalog.SYSDEPENDSRowFactory\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.DependableFinder;\r
+import org.apache.derby.catalog.TypeDescriptor;\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\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.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.DependencyDescriptor;\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.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 SYSDEPENDSS row.\r
+ *\r
+ */\r
+\r
+public class SYSDEPENDSRowFactory extends CatalogRowFactory\r
+{\r
+ private static final String TABLENAME_STRING = "SYSDEPENDS";\r
+\r
+ protected static final int SYSDEPENDS_COLUMN_COUNT = 4;\r
+ protected static final int SYSDEPENDS_DEPENDENTID = 1;\r
+ protected static final int SYSDEPENDS_DEPENDENTTYPE = 2;\r
+ protected static final int SYSDEPENDS_PROVIDERID = 3;\r
+ protected static final int SYSDEPENDS_PROVIDERTYPE = 4;\r
+\r
+ protected static final int SYSDEPENDS_INDEX1_ID = 0;\r
+ protected static final int SYSDEPENDS_INDEX2_ID = 1;\r
+\r
+ \r
+ private static final boolean[] uniqueness = {\r
+ false,\r
+ false\r
+ };\r
+\r
+ private static final int[][] indexColumnPositions =\r
+ {\r
+ {SYSDEPENDS_DEPENDENTID},\r
+ {SYSDEPENDS_PROVIDERID}\r
+ };\r
+\r
+ private static final String[] uuids =\r
+ {\r
+ "8000003e-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID\r
+ ,"80000043-00d0-fd77-3ed8-000a0a0b1900" // heap UUID\r
+ ,"80000040-00d0-fd77-3ed8-000a0a0b1900" // SYSDEPENDS_INDEX1\r
+ ,"80000042-00d0-fd77-3ed8-000a0a0b1900" // SYSDEPENDS_INDEX2\r
+ };\r
+\r
+ /////////////////////////////////////////////////////////////////////////////\r
+ //\r
+ // CONSTRUCTORS\r
+ //\r
+ /////////////////////////////////////////////////////////////////////////////\r
+\r
+ SYSDEPENDSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf)\r
+ {\r
+ super(uuidf,ef,dvf);\r
+ initInfo(SYSDEPENDS_COLUMN_COUNT,TABLENAME_STRING, indexColumnPositions,\r
+ uniqueness, uuids );\r
+ }\r
+\r
+ /////////////////////////////////////////////////////////////////////////////\r
+ //\r
+ // METHODS\r
+ //\r
+ /////////////////////////////////////////////////////////////////////////////\r
+\r
+ /**\r
+ * Make a SYSDEPENDS row\r
+ *\r
+ * @param td DependencyDescriptor. If its null then we want to make an empty\r
+ * row. \r
+ *\r
+ * @return Row suitable for inserting into SYSDEPENDS.\r
+ *\r
+ * @exception StandardException thrown on failure\r
+ */\r
+ public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)\r
+ throws StandardException \r
+ {\r
+ DataValueDescriptor col;\r
+ ExecRow row;\r
+ String dependentID = null;\r
+ DependableFinder dependentBloodhound = null;\r
+ String providerID = null;\r
+ DependableFinder providerBloodhound = null;\r
+\r
+ if (td != null)\r
+ {\r
+ DependencyDescriptor dd = (DependencyDescriptor)td;\r
+ dependentID = dd.getUUID().toString();\r
+ dependentBloodhound = dd.getDependentFinder();\r
+ if ( dependentBloodhound == null )\r
+ {\r
+ throw StandardException.newException(SQLState.DEP_UNABLE_TO_STORE);\r
+ }\r
+\r
+ providerID = dd.getProviderID().toString();\r
+ providerBloodhound = dd.getProviderFinder();\r
+ if ( providerBloodhound == null )\r
+ {\r
+ throw StandardException.newException(SQLState.DEP_UNABLE_TO_STORE);\r
+ }\r
+\r
+ }\r
+\r
+ /* Insert info into sysdepends */\r
+\r
+ /* RESOLVE - It would be nice to require less knowledge about sysdepends\r
+ * and have this be more table driven.\r
+ */\r
+\r
+ /* Build the row to insert */\r
+ row = getExecutionFactory().getValueRow(SYSDEPENDS_COLUMN_COUNT);\r
+\r
+ /* 1st column is DEPENDENTID (UUID - char(36)) */\r
+ row.setColumn(SYSDEPENDS_DEPENDENTID, new SQLChar(dependentID));\r
+\r
+ /* 2nd column is DEPENDENTFINDER */\r
+ row.setColumn(SYSDEPENDS_DEPENDENTTYPE,\r
+ dvf.getDataValue(dependentBloodhound));\r
+\r
+ /* 3rd column is PROVIDERID (UUID - char(36)) */\r
+ row.setColumn(SYSDEPENDS_PROVIDERID, new SQLChar(providerID));\r
+\r
+ /* 4th column is PROVIDERFINDER */\r
+ row.setColumn(SYSDEPENDS_PROVIDERTYPE,\r
+ dvf.getDataValue(providerBloodhound));\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 ConstraintDescriptor out of a SYSDEPENDS row\r
+ *\r
+ * @param row a SYSDEPENDSS 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
+ DependencyDescriptor dependencyDesc = null;\r
+\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(\r
+ row.nColumns() == SYSDEPENDS_COLUMN_COUNT, \r
+ "Wrong number of columns for a SYSDEPENDS row");\r
+ }\r
+\r
+ DataValueDescriptor col;\r
+ String dependentIDstring;\r
+ UUID dependentUUID;\r
+ DependableFinder dependentBloodhound;\r
+ String providerIDstring;\r
+ UUID providerUUID;\r
+ DependableFinder providerBloodhound;\r
+\r
+ /* 1st column is DEPENDENTID (UUID - char(36)) */\r
+ col = row.getColumn(SYSDEPENDS_DEPENDENTID);\r
+ dependentIDstring = col.getString();\r
+ dependentUUID = getUUIDFactory().recreateUUID(dependentIDstring);\r
+\r
+ /* 2nd column is DEPENDENTTYPE */\r
+ col = row.getColumn(SYSDEPENDS_DEPENDENTTYPE);\r
+ dependentBloodhound = (DependableFinder) col.getObject();\r
+\r
+ /* 3rd column is PROVIDERID (UUID - char(36)) */\r
+ col = row.getColumn(SYSDEPENDS_PROVIDERID);\r
+ providerIDstring = col.getString();\r
+ providerUUID = getUUIDFactory().recreateUUID(providerIDstring);\r
+\r
+ /* 4th column is PROVIDERTYPE */\r
+ col = row.getColumn(SYSDEPENDS_PROVIDERTYPE);\r
+ providerBloodhound = (DependableFinder) col.getObject();\r
+\r
+ /* now build and return the descriptor */\r
+ return new DependencyDescriptor(dependentUUID, dependentBloodhound,\r
+ providerUUID, providerBloodhound);\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("DEPENDENTID", false),\r
+ SystemColumnImpl.getJavaColumn("DEPENDENTFINDER",\r
+ "org.apache.derby.catalog.DependableFinder", false),\r
+ SystemColumnImpl.getUUIDColumn("PROVIDERID", false),\r
+ SystemColumnImpl.getJavaColumn("PROVIDERFINDER",\r
+ "org.apache.derby.catalog.DependableFinder", false),\r
+ };\r
+ }\r
+}\r