--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.InsertConstantAction\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.stream.HeaderPrintWriter;\r
+\r
+\r
+import org.apache.derby.iapi.services.io.ArrayUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+\r
+import org.apache.derby.iapi.services.context.ContextManager;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\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.store.access.StaticCompiledOpenConglomInfo;\r
+import org.apache.derby.iapi.types.RowLocation;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+import java.util.Properties;\r
+\r
+/**\r
+ * This class describes compiled constants that are passed into\r
+ * InsertResultSets.\r
+ *\r
+ */\r
+\r
+public class InsertConstantAction extends WriteCursorConstantAction\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
+ /* Which (0-based) columns are indexed */\r
+ boolean[] indexedCols;\r
+\r
+ /* These variables are needed to support Autoincrement-- after an insert\r
+ * we need to remember the last autoincrement value inserted into the \r
+ * table and the user could do a search based on schema,table,columnname\r
+ */\r
+ private String schemaName;\r
+ private String tableName;\r
+ private String columnNames[];\r
+\r
+ /**\r
+ * An array of row location objects (0 based), one for each\r
+ * column in the table. If the column is an \r
+ * autoincrement table then the array points to\r
+ * the row location of the column in SYSCOLUMNS.\r
+ * if not, then it contains null.\r
+ */\r
+ protected RowLocation[] autoincRowLocation;\r
+ private long[] autoincIncrement;\r
+ \r
+ // CONSTRUCTORS\r
+\r
+ /**\r
+ * Public niladic constructor. Needed for Formatable interface to work.\r
+ *\r
+ */\r
+ public InsertConstantAction() { super(); }\r
+\r
+ /**\r
+ * Make the ConstantAction for an INSERT statement.\r
+ *\r
+ * @param conglomId Conglomerate ID.\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 insert.\r
+ * @param targetProperties Properties on the target table.\r
+ * @param targetUUID UUID of target table\r
+ * @param lockMode The lockMode to use on the target table\r
+ * @param fkInfo Array of structures containing foreign key info, \r
+ * if any (may be null)\r
+ * @param triggerInfo Array of structures containing trigger info, \r
+ * if any (may be null)\r
+ * @param streamStorableHeapColIds Null for non rep. (0 based)\r
+ * @param indexedCols boolean[] of which (0-based) columns are indexed.\r
+ * @param singleRowSource Whether or not source is a single row source\r
+ * @param autoincRowLocation Array of rowlocations of autoincrement values\r
+ * in SYSCOLUMNS for each ai column.\r
+ */\r
+ public InsertConstantAction(TableDescriptor tableDescriptor,\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
+ int[] streamStorableHeapColIds,\r
+ boolean[] indexedCols,\r
+ boolean singleRowSource,\r
+ RowLocation[] autoincRowLocation)\r
+ {\r
+ super(conglomId, \r
+ heapSCOCI,\r
+ irgs, \r
+ indexCIDS, \r
+ indexSCOCIs,\r
+ indexNames,\r
+ deferred, \r
+ targetProperties,\r
+ targetUUID,\r
+ lockMode,\r
+ fkInfo, \r
+ triggerInfo,\r
+ (ExecRow)null, // never need to pass in a heap row\r
+ null,\r
+ null,\r
+ streamStorableHeapColIds,\r
+ singleRowSource\r
+ );\r
+ this.indexedCols = indexedCols;\r
+ this.autoincRowLocation = autoincRowLocation;\r
+ this.schemaName = tableDescriptor.getSchemaName();\r
+ this.tableName = tableDescriptor.getName();\r
+ this.columnNames = tableDescriptor.getColumnNamesArray();\r
+ this.autoincIncrement = tableDescriptor.getAutoincIncrementArray();\r
+ this.indexNames = indexNames;\r
+ }\r
+\r
+ // INTERFACE METHODS\r
+\r
+ // Formatable methods\r
+ public void readExternal (ObjectInput in)\r
+ throws IOException, ClassNotFoundException\r
+ {\r
+ Object[] objectArray = null;\r
+ super.readExternal(in);\r
+ indexedCols = ArrayUtil.readBooleanArray(in);\r
+\r
+ // RESOLVEAUTOINCREMENT: this is the new stuff-- probably version!!\r
+ objectArray = ArrayUtil.readObjectArray(in);\r
+ \r
+ if (objectArray != null)\r
+ {\r
+ // is there a better way to do cast the whole array?\r
+ autoincRowLocation = new RowLocation[objectArray.length];\r
+ for (int i = 0; i < objectArray.length; i++)\r
+ autoincRowLocation[i] = (RowLocation)objectArray[i];\r
+ }\r
+ \r
+ schemaName = (String)in.readObject();\r
+ tableName = (String)in.readObject();\r
+ objectArray = ArrayUtil.readObjectArray(in);\r
+ if (objectArray != null)\r
+ {\r
+ // is there a better way to do cast the whole array?\r
+ columnNames = new String[objectArray.length];\r
+ for (int i = 0; i < objectArray.length; i++)\r
+ columnNames[i] = (String)objectArray[i];\r
+ }\r
+ \r
+ autoincIncrement = ArrayUtil.readLongArray(in);\r
+ }\r
+\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
+ super.writeExternal(out);\r
+ ArrayUtil.writeBooleanArray(out, indexedCols);\r
+ ArrayUtil.writeArray(out, autoincRowLocation);\r
+ out.writeObject(schemaName);\r
+ out.writeObject(tableName);\r
+ ArrayUtil.writeArray(out, columnNames);\r
+ ArrayUtil.writeLongArray(out, autoincIncrement);\r
+ }\r
+\r
+ /**\r
+ * Gets the name of the schema that the table is in\r
+ *\r
+ * @return schema name\r
+ */\r
+ public String getSchemaName() { return schemaName; }\r
+\r
+ /**\r
+ * Gets the name of the table being inserted into\r
+ *\r
+ * @return name of table being inserted into\r
+ */\r
+ public String getTableName() { return tableName; }\r
+\r
+\r
+ /**\r
+ * gets the name of the desired column in the taget table.\r
+ * \r
+ * @param i the column number\r
+ */\r
+ public String getColumnName(int i) { return columnNames[i]; }\r
+\r
+ /**\r
+ * gets the increment value for a column.\r
+ *\r
+ * @param i the column number\r
+ */\r
+ public long getAutoincIncrement(int i) { return autoincIncrement[i]; }\r
+\r
+ /**\r
+ * Does the target table has autoincrement columns.\r
+ *\r
+ * @return True if the table has ai columns\r
+ */\r
+ public boolean hasAutoincrement()\r
+ {\r
+ return (autoincRowLocation != null);\r
+ }\r
+\r
+ /**\r
+ * gets the row location \r
+ */\r
+ public RowLocation[] getAutoincRowLocation()\r
+ {\r
+ return autoincRowLocation;\r
+ }\r
+ \r
+ /**\r
+ * Get the formatID which corresponds to this class.\r
+ *\r
+ * @return the formatID of this class\r
+ */\r
+ public int getTypeFormatId() { return StoredFormatIds.INSERT_CONSTANT_ACTION_V01_ID; }\r
+\r
+ // CLASS METHODS\r
+\r
+}\r