--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.ColumnInfo\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.io.Formatable;\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.error.StandardException;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.catalog.DefaultInfo;\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.iapi.services.io.FormatableHashtable;\r
+import org.apache.derby.iapi.services.io.FormatableIntHolder;\r
+import org.apache.derby.iapi.services.io.FormatableLongHolder;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * This is the Column descriptor that is passed from Compilation to Execution\r
+ * for CREATE TABLE statements.\r
+ *\r
+ * @version 0.1\r
+ */\r
+\r
+public class ColumnInfo implements Formatable\r
+{\r
+ /********************************************************\r
+ **\r
+ ** This class implements Formatable. That means that it\r
+ ** can write itself to and from a formatted stream. If\r
+ ** you add more fields to this class, make sure that you\r
+ ** also write/read them with the writeExternal()/readExternal()\r
+ ** methods.\r
+ **\r
+ ** If, inbetween releases, you add more fields to this class,\r
+ ** then you should bump the version number emitted by the getTypeFormatId()\r
+ ** method.\r
+ **\r
+ ********************************************************/\r
+\r
+ public int action;\r
+ public String name;\r
+ public DataTypeDescriptor dataType;\r
+ public DefaultInfo defaultInfo;\r
+ public DataValueDescriptor defaultValue;\r
+ public UUID newDefaultUUID;\r
+ public UUID oldDefaultUUID;\r
+ // autoinc columns.\r
+ public long autoincStart;\r
+ public long autoincInc;\r
+ //if this is an autoincrement column, then following variable will have CREATE or\r
+ //MODIFY_COLUMN_DEFAULT_RESTART or MODIFY_COLUMN_DEFAULT_INCREMENT. Otherwise,\r
+ //this variable will be set to -1.\r
+ public long autoinc_create_or_modify_Start_Increment = -1;\r
+\r
+ //This indicates column is for CREATE TABLE\r
+ public static final int CREATE = 0;\r
+ public static final int DROP = 1;\r
+ public static final int MODIFY_COLUMN_TYPE = 2;\r
+ public static final int MODIFY_COLUMN_CONSTRAINT = 3;\r
+ public static final int MODIFY_COLUMN_CONSTRAINT_NOT_NULL = 4;\r
+ //This indicates column is for ALTER TABLE to change the start value of autoinc column \r
+ public static final int MODIFY_COLUMN_DEFAULT_RESTART = 5;\r
+ //This indicates column is for ALTER TABLE to change the increment value of autoinc column \r
+ public static final int MODIFY_COLUMN_DEFAULT_INCREMENT = 6;\r
+ public static final int MODIFY_COLUMN_DEFAULT_VALUE = 7;\r
+ // CONSTRUCTORS\r
+\r
+ /**\r
+ * Public niladic constructor. Needed for Formatable interface to work.\r
+ *\r
+ */\r
+ public ColumnInfo() {}\r
+\r
+ /**\r
+ * Make one of these puppies.\r
+ *\r
+ * @param name Column name.\r
+ * @param dataType Column type.\r
+ * @param defaultValue Column default value.\r
+ * @param defaultInfo Column default info.\r
+ * @param newDefaultUUID New UUID for default.\r
+ * @param oldDefaultUUID Old UUID for default.\r
+ * @param action Action (create, modify default, etc.)\r
+ * @param autoincStart Start of autoincrement values.\r
+ * @param autoincInc Increment of autoincrement values-- if parameter\r
+ * is 0, it implies that this is not an autoincrement\r
+ * value.\r
+ */\r
+ public ColumnInfo(\r
+ String name,\r
+ DataTypeDescriptor dataType,\r
+ DataValueDescriptor defaultValue,\r
+ DefaultInfo defaultInfo,\r
+ UUID newDefaultUUID,\r
+ UUID oldDefaultUUID,\r
+ int action,\r
+ long autoincStart,\r
+ long autoincInc,\r
+ long autoinc_create_or_modify_Start_Increment)\r
+ {\r
+ this.name = name;\r
+ this.dataType = dataType;\r
+ this.defaultValue = defaultValue;\r
+ this.defaultInfo = defaultInfo;\r
+ this.newDefaultUUID = newDefaultUUID;\r
+ this.oldDefaultUUID = oldDefaultUUID;\r
+ this.action = action;\r
+ this.autoincStart = autoincStart;\r
+ this.autoincInc = autoincInc;\r
+ this.autoinc_create_or_modify_Start_Increment = autoinc_create_or_modify_Start_Increment;\r
+ }\r
+\r
+ // Formatable methods\r
+\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
+\r
+ FormatableLongHolder flh;\r
+\r
+ FormatableHashtable fh = (FormatableHashtable)in.readObject();\r
+ name = (String)fh.get("name");\r
+ dataType = (DataTypeDescriptor) fh.get("dataType");\r
+ defaultValue = (DataValueDescriptor)fh.get("defaultValue");\r
+ defaultInfo = (DefaultInfo)fh.get("defaultInfo");\r
+ newDefaultUUID = (UUID)fh.get("newDefaultUUID");\r
+ oldDefaultUUID = (UUID)fh.get("oldDefaultUUID");\r
+ action = fh.getInt("action");\r
+ \r
+ if (fh.get("autoincStart") != null)\r
+ {\r
+ autoincStart = fh.getLong("autoincStart");\r
+ autoincInc = fh.getLong("autoincInc");\r
+ }\r
+ else\r
+ {\r
+ autoincInc = autoincStart = 0;\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
+ FormatableHashtable fh = new FormatableHashtable();\r
+ fh.put("name", name);\r
+ fh.put("dataType", dataType);\r
+ fh.put("defaultValue", defaultValue);\r
+ fh.put("defaultInfo", defaultInfo);\r
+ fh.put("newDefaultUUID", newDefaultUUID);\r
+ fh.put("oldDefaultUUID", oldDefaultUUID );\r
+ fh.putInt("action", action);\r
+ \r
+ if (autoincInc != 0)\r
+ {\r
+ // only write out autoinc values if its an autoinc column.\r
+ fh.putLong("autoincStart", autoincStart);\r
+ fh.putLong("autoincInc", autoincInc);\r
+ }\r
+ out.writeObject(fh);\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.COLUMN_INFO_V02_ID; }\r
+\r
+ /*\r
+ Object methods.\r
+ */\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ String traceName;\r
+ String traceDataType;\r
+ String traceDefaultValue;\r
+ String traceDefaultInfo;\r
+ String traceNewDefaultUUID;\r
+ String traceOldDefaultUUID;\r
+ String traceAction;\r
+ String traceAI;\r
+ if (name == null)\r
+ {\r
+ traceName = "name: null ";\r
+ }\r
+ else\r
+ {\r
+ traceName = "name: "+name+" ";\r
+ }\r
+\r
+ if (dataType == null)\r
+ {\r
+ traceDataType = "dataType: null ";\r
+ }\r
+ else\r
+ {\r
+ traceDataType = "dataType: "+dataType+" ";\r
+ }\r
+\r
+ if (defaultValue == null)\r
+ {\r
+ traceDefaultValue = "defaultValue: null ";\r
+ }\r
+ else\r
+ {\r
+ traceDefaultValue = "defaultValue: "+defaultValue+" ";\r
+ }\r
+\r
+ if (defaultInfo == null)\r
+ {\r
+ traceDefaultInfo = "defaultInfo: null ";\r
+ }\r
+ else\r
+ {\r
+ traceDefaultInfo = "defaultInfo: "+defaultInfo+" ";\r
+ }\r
+\r
+ if (newDefaultUUID == null)\r
+ {\r
+ traceNewDefaultUUID = "newDefaultUUID: null ";\r
+ }\r
+ else\r
+ {\r
+ traceNewDefaultUUID = "newDefaultUUID: "+newDefaultUUID+" ";\r
+ }\r
+\r
+ if (oldDefaultUUID == null)\r
+ {\r
+ traceOldDefaultUUID = "oldDefaultUUID: null ";\r
+ }\r
+ else\r
+ {\r
+ traceOldDefaultUUID = "oldDefaultUUID: "+oldDefaultUUID+" ";\r
+ }\r
+\r
+ traceAction = "action: "+action+" ";\r
+\r
+ if (autoincInc != 0)\r
+ {\r
+ traceAI = "autoincrement, start: " + autoincStart +\r
+ " increment:" + autoincInc;\r
+ }\r
+ else\r
+ {\r
+ traceAI = "NOT autoincrement";\r
+ }\r
+ return "ColumnInfo: ("+traceName+traceDataType+traceDefaultValue+\r
+ traceDefaultInfo+traceNewDefaultUUID+traceOldDefaultUUID+traceAction+traceAI+")";\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+ }\r
+}\r