--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.WriteCursorConstantAction\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 java.io.IOException;\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+import java.util.Properties;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.io.ArrayUtil;\r
+import org.apache.derby.iapi.services.io.Formatable;\r
+import org.apache.derby.iapi.services.io.FormatableBitSet;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.sql.Activation;\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+import org.apache.derby.iapi.sql.execute.ExecRow;\r
+import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;\r
+\r
+\r
+/**\r
+ * This abstract class describes compiled constants that are passed into\r
+ * Delete, Insert, and Update ResultSets.\r
+ *\r
+ * This class and its sub-classes are not really implementations\r
+ * of ConstantAction, since they are not executed.\r
+ * \r
+ * A better name for these classes would be 'Constants'.\r
+ * E.g. WriteCursorConstants, DeleteConstants.\r
+ * \r
+ * Ideally one day the split will occur.\r
+ *\r
+ */\r
+\r
+abstract class WriteCursorConstantAction implements ConstantAction, Formatable\r
+{\r
+\r
+ /********************************************************\r
+ **\r
+ ** This class implements Formatable. But it is NOT used\r
+ ** across either major or minor releases. It is only\r
+ ** written persistently in stored prepared statements, \r
+ ** not in the replication stage. SO, IT IS OK TO CHANGE\r
+ ** ITS read/writeExternal.\r
+ **\r
+ ********************************************************/\r
+\r
+ long conglomId;\r
+ StaticCompiledOpenConglomInfo heapSCOCI;\r
+ IndexRowGenerator[] irgs;\r
+ long[] indexCIDS;\r
+ StaticCompiledOpenConglomInfo[] indexSCOCIs;\r
+ String[] indexNames;\r
+ boolean deferred;\r
+ private Properties targetProperties;\r
+ UUID targetUUID;\r
+ int lockMode;\r
+ private FKInfo[] fkInfo;\r
+ private TriggerInfo triggerInfo;\r
+\r
+ private ExecRow emptyHeapRow;\r
+ private FormatableBitSet baseRowReadList;\r
+ private int[] baseRowReadMap;\r
+ private int[] streamStorableHeapColIds;\r
+ boolean singleRowSource;\r
+\r
+\r
+ // CONSTRUCTORS\r
+\r
+ /**\r
+ * Public niladic constructor. Needed for Formatable interface to work.\r
+ *\r
+ */\r
+ public WriteCursorConstantAction() {}\r
+\r
+ /**\r
+ * Make the ConstantAction for a DELETE, INSERT, or UPDATE statement.\r
+ *\r
+ * @param conglomId Conglomerate ID of heap.\r
+ * @param heapSCOCI StaticCompiledOpenConglomInfo for heap.\r
+ * @param irgs Index descriptors\r
+ * @param indexCIDS Conglomerate IDs of indices\r
+ * @param indexSCOCIs StaticCompiledOpenConglomInfos for indexes.\r
+ * @param indexNames Names of indices on this table for error reporting.\r
+ * @param deferred True means process as a deferred update\r
+ * @param targetProperties Properties on the target table\r
+ * @param targetUUID UUID of target table\r
+ * @param lockMode The lock mode to use on the target table\r
+ * @param fkInfo Structure containing foreign key info, if any (may be null)\r
+ * @param triggerInfo Structure containing trigger info, if any (may be null)\r
+ * @param emptyHeapRow an empty heap row\r
+ * @param baseRowReadMap BaseRowReadMap[heapColId]->ReadRowColumnId. (0 based)\r
+ * @param streamStorableHeapColIds Null for non rep. (0 based)\r
+ * @param singleRowSource Whether or not source is a single row source\r
+ */\r
+ public WriteCursorConstantAction(\r
+ long conglomId,\r
+ StaticCompiledOpenConglomInfo heapSCOCI,\r
+ IndexRowGenerator[] irgs,\r
+ long[] indexCIDS,\r
+ StaticCompiledOpenConglomInfo[] indexSCOCIs,\r
+ String[] indexNames,\r
+ boolean deferred,\r
+ Properties targetProperties,\r
+ UUID targetUUID,\r
+ int lockMode,\r
+ FKInfo[] fkInfo,\r
+ TriggerInfo triggerInfo,\r
+ ExecRow emptyHeapRow,\r
+ FormatableBitSet baseRowReadList,\r
+ int[] baseRowReadMap,\r
+ int[] streamStorableHeapColIds,\r
+ boolean singleRowSource\r
+ )\r
+ {\r
+ this.conglomId = conglomId;\r
+ this.heapSCOCI = heapSCOCI;\r
+ this.irgs = irgs;\r
+ this.indexSCOCIs = indexSCOCIs;\r
+ this.indexCIDS = indexCIDS;\r
+ this.indexSCOCIs = indexSCOCIs;\r
+ this.deferred = deferred;\r
+ this.targetProperties = targetProperties;\r
+ this.targetUUID = targetUUID;\r
+ this.lockMode = lockMode;\r
+ this.emptyHeapRow = emptyHeapRow;\r
+ this.fkInfo = fkInfo;\r
+ this.triggerInfo = triggerInfo;\r
+ this.baseRowReadList = baseRowReadList;\r
+ this.baseRowReadMap = baseRowReadMap;\r
+ this.streamStorableHeapColIds = streamStorableHeapColIds;\r
+ this.singleRowSource = singleRowSource;\r
+ this.indexNames = indexNames;\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ if (fkInfo != null)\r
+ {\r
+ SanityManager.ASSERT(fkInfo.length != 0, "fkinfo array has no elements, if there are no foreign keys, then pass in null");\r
+ }\r
+ }\r
+ }\r
+\r
+ ///////////////////////////////////////////////////////////////////\r
+ //\r
+ // ACCESSORS\r
+ //\r
+ ///////////////////////////////////////////////////////////////////\r
+\r
+ /**\r
+ * Gets the foreign key information for this constant action.\r
+ * A full list of foreign keys was compiled into this constant\r
+ * action.\r
+ *\r
+ *\r
+ * @return the list of foreign keys to enforce for this action\r
+ *\r
+ */\r
+ final FKInfo[] getFKInfo()\r
+ {\r
+ return fkInfo;\r
+ }\r
+\r
+ /**\r
+ * Basically, the same as getFKInfo but for triggers.\r
+ *\r
+ * @return the triggers that should be fired\r
+ *\r
+ */\r
+ TriggerInfo getTriggerInfo()\r
+ {\r
+ return triggerInfo;\r
+ }\r
+\r
+\r
+ ///////////////////////////////////////////////////////////////////\r
+ //\r
+ // INTERFACE METHODS\r
+ //\r
+ ///////////////////////////////////////////////////////////////////\r
+\r
+ /**\r
+ * NOP routine. The work is done in InsertResultSet.\r
+ *\r
+ * @see ConstantAction#executeConstantAction\r
+ *\r
+ * @exception StandardException Thrown on failure\r
+ */\r
+ public final void executeConstantAction( Activation activation )\r
+ throws StandardException { }\r
+\r
+ // Formatable methods\r
+ /**\r
+ * Read this object from a stream of stored objects.\r
+ *\r
+ * @param in read this.\r
+ *\r
+ * @exception IOException thrown on error\r
+ * @exception ClassNotFoundException thrown on error\r
+ */\r
+ public void readExternal( ObjectInput in )\r
+ throws IOException, ClassNotFoundException\r
+ {\r
+ conglomId = in.readLong();\r
+ heapSCOCI = (StaticCompiledOpenConglomInfo) in.readObject();\r
+ irgs = new IndexRowGenerator[ArrayUtil.readArrayLength(in)];\r
+ ArrayUtil.readArrayItems(in, irgs);\r
+\r
+ indexCIDS = ArrayUtil.readLongArray(in);\r
+ indexSCOCIs = new StaticCompiledOpenConglomInfo[ArrayUtil.readArrayLength(in)];\r
+ ArrayUtil.readArrayItems(in, indexSCOCIs);\r
+\r
+ deferred = in.readBoolean();\r
+ targetProperties = (Properties) in.readObject();\r
+ targetUUID = (UUID) in.readObject();\r
+ lockMode = in.readInt();\r
+\r
+ fkInfo = new FKInfo[ArrayUtil.readArrayLength(in)];\r
+ ArrayUtil.readArrayItems(in, fkInfo);\r
+\r
+ triggerInfo = (TriggerInfo)in.readObject();\r
+\r
+ baseRowReadList = (FormatableBitSet)in.readObject();\r
+ baseRowReadMap = ArrayUtil.readIntArray(in);\r
+ streamStorableHeapColIds = ArrayUtil.readIntArray(in); \r
+ singleRowSource = in.readBoolean();\r
+ indexNames = ArrayUtil.readStringArray(in);\r
+ }\r
+\r
+ /**\r
+ * Write this object to a stream of stored objects.\r
+ *\r
+ * @param out write bytes here.\r
+ *\r
+ * @exception IOException thrown on error\r
+ */\r
+ public void writeExternal( ObjectOutput out )\r
+ throws IOException\r
+ {\r
+ out.writeLong(conglomId);\r
+ out.writeObject(heapSCOCI);\r
+ ArrayUtil.writeArray(out, irgs);\r
+ ArrayUtil.writeLongArray(out, indexCIDS);\r
+ ArrayUtil.writeArray(out, indexSCOCIs);\r
+ out.writeBoolean(deferred);\r
+ out.writeObject(targetProperties);\r
+ out.writeObject(targetUUID);\r
+ out.writeInt(lockMode);\r
+ ArrayUtil.writeArray(out, fkInfo);\r
+\r
+ //\r
+ //Added for Xena.\r
+ out.writeObject(triggerInfo);\r
+\r
+ //\r
+ //Moved from super class for Xena.\r
+ out.writeObject(baseRowReadList);\r
+\r
+ //\r
+ //Added for Xena\r
+ ArrayUtil.writeIntArray(out,baseRowReadMap);\r
+ ArrayUtil.writeIntArray(out,streamStorableHeapColIds);\r
+\r
+ //Added for Buffy\r
+ out.writeBoolean(singleRowSource);\r
+ \r
+ // Added for Mulan (Track Bug# 3322)\r
+ ArrayUtil.writeArray(out, indexNames);\r
+ \r
+ }\r
+\r
+ // ACCESSORS\r
+\r
+ /**\r
+ * Get the conglomerate id for the changed heap.\r
+ * @return the conglomerate id.\r
+ */\r
+ public long getConglomerateId() { return conglomId; }\r
+ \r
+ /**\r
+ * Get emptyHeapRow\r
+ *\r
+ * @param lcc The LanguageConnectionContext to use.\r
+ *\r
+ * @return an empty base table row for the table being updated.\r
+ *\r
+ * @exception StandardException on error\r
+ */\r
+ public ExecRow getEmptyHeapRow(LanguageConnectionContext lcc) throws StandardException\r
+ {\r
+ DataDictionary dd;\r
+ TableDescriptor td;\r
+\r
+ if (emptyHeapRow == null)\r
+ {\r
+\r
+ dd = lcc.getDataDictionary();\r
+ \r
+ td = dd.getTableDescriptor(targetUUID);\r
+ \r
+ emptyHeapRow = td.getEmptyExecRow();\r
+ }\r
+\r
+ return emptyHeapRow.getClone();\r
+ }\r
+\r
+ /**\r
+ * Get the targetProperties from the constant action.\r
+ *\r
+ * @return The targetProperties\r
+ */\r
+ public Properties getTargetProperties()\r
+ {\r
+ return targetProperties;\r
+ }\r
+\r
+ /**\r
+ * The the value of the specified key, if it exists, from\r
+ * the targetProperties.\r
+ *\r
+ * @param key The key to search for\r
+ *\r
+ * @return The value for the specified key if it exists, otherwise null.\r
+ * (Return null if targetProperties is null.)\r
+ */\r
+ public String getProperty(String key)\r
+ {\r
+ return (targetProperties == null) ? null : targetProperties.getProperty(key);\r
+ }\r
+\r
+ public FormatableBitSet getBaseRowReadList() { return baseRowReadList; }\r
+ public int[] getBaseRowReadMap() { return baseRowReadMap; }\r
+ public int[] getStreamStorableHeapColIds() { return streamStorableHeapColIds; }\r
+\r
+ /**\r
+ * get the index name given the conglomerate id of the index.\r
+ * \r
+ * @param indexCID conglomerate ID of the index.\r
+ * \r
+ * @return index name of given index.\r
+ */\r
+ public String getIndexNameFromCID(long indexCID)\r
+ {\r
+ int size = indexCIDS.length;\r
+\r
+ if (indexNames == null) \r
+ {\r
+ return null;\r
+ } \r
+ \r
+ for (int i = 0; i < size; i++)\r
+ {\r
+ if (indexCIDS[i] == indexCID)\r
+ return indexNames[i];\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public String[] getIndexNames()\r
+ {\r
+ return indexNames;\r
+ }\r
+}\r
+ \r