--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.RISetChecker\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.execute;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.sql.execute.ExecRow;\r
+import org.apache.derby.iapi.sql.execute.ExecIndexRow;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+/**\r
+ * Checks a set or referential integrity constraints. Used\r
+ * to shield the caller from ReferencedKeyRIChecker and\r
+ * ForeignKeyRICheckers.\r
+ */\r
+public class RISetChecker\r
+{\r
+ private GenericRIChecker[] checkers;\r
+\r
+ /**\r
+ * @param tc the xact controller\r
+ * @param fkInfo the foreign key information \r
+ *\r
+ * @exception StandardException Thrown on failure\r
+ */\r
+ public RISetChecker(TransactionController tc, FKInfo fkInfo[])\r
+ throws StandardException\r
+ {\r
+ if (fkInfo == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ checkers = new GenericRIChecker[fkInfo.length];\r
+\r
+ for (int i = 0; i < fkInfo.length; i++)\r
+ {\r
+ checkers[i] = (fkInfo[i].type == FKInfo.FOREIGN_KEY) ?\r
+ (GenericRIChecker)new ForeignKeyRIChecker(tc, fkInfo[i]) :\r
+ (GenericRIChecker)new ReferencedKeyRIChecker(tc, fkInfo[i]);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Do any work needed to reopen our ri checkers\r
+ * for another round of checks. Must do a close()\r
+ * first.\r
+ *\r
+ * @exception StandardException on error\r
+ */\r
+ void reopen() throws StandardException\r
+ {\r
+ // currently a noop\r
+ }\r
+\r
+ /**\r
+ * Check that there are no referenced primary keys in\r
+ * the passed in row. So for each foreign key that\r
+ * references a primary key constraint, make sure\r
+ * that there is no row that matches the values in\r
+ * the passed in row.\r
+ *\r
+ * @param row the row to check\r
+ *\r
+ * @exception StandardException on unexpected error, or\r
+ * on a primary/unique key violation\r
+ */\r
+ public void doPKCheck(ExecRow row, boolean restrictCheckOnly) throws StandardException\r
+ {\r
+ if (checkers == null)\r
+ return;\r
+\r
+ for (int i = 0; i < checkers.length; i++)\r
+ {\r
+ if (checkers[i] instanceof ReferencedKeyRIChecker)\r
+ {\r
+ checkers[i].doCheck(row,restrictCheckOnly);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Check that everything in the row is ok, i.e.\r
+ * that there are no foreign keys in the passed\r
+ * in row that have invalid values.\r
+ *\r
+ * @param row the row to check\r
+ *\r
+ * @exception StandardException on unexpected error, or\r
+ * on a primary/unique key violation\r
+ */\r
+ public void doFKCheck(ExecRow row) throws StandardException\r
+ {\r
+ if (checkers == null)\r
+ return;\r
+\r
+ for (int i = 0; i < checkers.length; i++)\r
+ {\r
+ if (checkers[i] instanceof ForeignKeyRIChecker)\r
+ {\r
+ checkers[i].doCheck(row);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Execute the specific RI check on the passed in row.\r
+ *\r
+ * @param index index into fkInfo\r
+ * @param row the row to check\r
+ *\r
+ * @exception StandardException on unexpected error, or\r
+ * on a primary/unique key violation\r
+ */\r
+ public void doRICheck(int index, ExecRow row, boolean restrictCheckOnly) throws StandardException\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ if (checkers == null)\r
+ {\r
+ SanityManager.THROWASSERT("no checkers, how can i execute checker "+index);\r
+ }\r
+\r
+ if (index >= checkers.length)\r
+ {\r
+ SanityManager.THROWASSERT("there are only "+\r
+ checkers.length+" checkers, "+index+" is invalid");\r
+ }\r
+ }\r
+\r
+ checkers[index].doCheck(row, restrictCheckOnly);\r
+ }\r
+\r
+ /**\r
+ * clean up\r
+ *\r
+ * @exception StandardException on error\r
+ */\r
+ public void close() throws StandardException\r
+ {\r
+ if (checkers == null)\r
+ return;\r
+\r
+ for (int i = 0; i < checkers.length; i++)\r
+ {\r
+ checkers[i].close();\r
+ }\r
+ } \r
+}\r
+\r