1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.io.Formatable; 25 import org.apache.derby.iapi.services.io.StoredFormatIds; 26 import org.apache.derby.iapi.services.io.FormatIdUtil; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.types.DataTypeDescriptor; 31 import org.apache.derby.iapi.types.DataValueDescriptor; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 35 import org.apache.derby.catalog.DefaultInfo; 36 import org.apache.derby.catalog.UUID; 37 38 import org.apache.derby.iapi.services.io.FormatableHashtable; 39 import org.apache.derby.iapi.services.io.FormatableIntHolder; 40 import org.apache.derby.iapi.services.io.FormatableLongHolder; 41 42 import java.io.ObjectOutput ; 43 import java.io.ObjectInput ; 44 import java.io.IOException ; 45 46 53 54 public class ColumnInfo implements Formatable 55 { 56 69 70 public int action; 71 public String name; 72 public DataTypeDescriptor dataType; 73 public DefaultInfo defaultInfo; 74 public DataValueDescriptor defaultValue; 75 public UUID newDefaultUUID; 76 public UUID oldDefaultUUID; 77 public long autoincStart; 79 public long autoincInc; 80 public long autoinc_create_or_modify_Start_Increment = -1; 84 85 public static final int CREATE = 0; 87 public static final int DROP = 1; 88 public static final int MODIFY_COLUMN_TYPE = 2; 89 public static final int MODIFY_COLUMN_CONSTRAINT = 3; 90 public static final int MODIFY_COLUMN_CONSTRAINT_NOT_NULL = 4; 91 public static final int MODIFY_COLUMN_DEFAULT_RESTART = 5; 93 public static final int MODIFY_COLUMN_DEFAULT_INCREMENT = 6; 95 97 101 public ColumnInfo() {} 102 103 118 public ColumnInfo( 119 String name, 120 DataTypeDescriptor dataType, 121 DataValueDescriptor defaultValue, 122 DefaultInfo defaultInfo, 123 UUID newDefaultUUID, 124 UUID oldDefaultUUID, 125 int action, 126 long autoincStart, 127 long autoincInc, 128 long autoinc_create_or_modify_Start_Increment) 129 { 130 this.name = name; 131 this.dataType = dataType; 132 this.defaultValue = defaultValue; 133 this.defaultInfo = defaultInfo; 134 this.newDefaultUUID = newDefaultUUID; 135 this.oldDefaultUUID = oldDefaultUUID; 136 this.action = action; 137 this.autoincStart = autoincStart; 138 this.autoincInc = autoincInc; 139 this.autoinc_create_or_modify_Start_Increment = autoinc_create_or_modify_Start_Increment; 140 } 141 142 144 152 public void readExternal( ObjectInput in ) 153 throws IOException , ClassNotFoundException 154 { 155 156 FormatableLongHolder flh; 157 158 FormatableHashtable fh = (FormatableHashtable)in.readObject(); 159 name = (String )fh.get("name"); 160 dataType = (DataTypeDescriptor) fh.get("dataType"); 161 defaultValue = (DataValueDescriptor)fh.get("defaultValue"); 162 defaultInfo = (DefaultInfo)fh.get("defaultInfo"); 163 newDefaultUUID = (UUID)fh.get("newDefaultUUID"); 164 oldDefaultUUID = (UUID)fh.get("oldDefaultUUID"); 165 action = fh.getInt("action"); 166 167 if (fh.get("autoincStart") != null) 168 { 169 autoincStart = fh.getLong("autoincStart"); 170 autoincInc = fh.getLong("autoincInc"); 171 } 172 else 173 { 174 autoincInc = autoincStart = 0; 175 } 176 } 177 178 185 public void writeExternal( ObjectOutput out ) 186 throws IOException 187 { 188 FormatableHashtable fh = new FormatableHashtable(); 189 fh.put("name", name); 190 fh.put("dataType", dataType); 191 fh.put("defaultValue", defaultValue); 192 fh.put("defaultInfo", defaultInfo); 193 fh.put("newDefaultUUID", newDefaultUUID); 194 fh.put("oldDefaultUUID", oldDefaultUUID ); 195 fh.putInt("action", action); 196 197 if (autoincInc != 0) 198 { 199 fh.putLong("autoincStart", autoincStart); 201 fh.putLong("autoincInc", autoincInc); 202 } 203 out.writeObject(fh); 204 } 205 206 211 public int getTypeFormatId() { return StoredFormatIds.COLUMN_INFO_V02_ID; } 212 213 216 public String toString() 217 { 218 if (SanityManager.DEBUG) 219 { 220 String traceName; 221 String traceDataType; 222 String traceDefaultValue; 223 String traceDefaultInfo; 224 String traceNewDefaultUUID; 225 String traceOldDefaultUUID; 226 String traceAction; 227 String traceAI; 228 if (name == null) 229 { 230 traceName = "name: null "; 231 } 232 else 233 { 234 traceName = "name: "+name+" "; 235 } 236 237 if (dataType == null) 238 { 239 traceDataType = "dataType: null "; 240 } 241 else 242 { 243 traceDataType = "dataType: "+dataType+" "; 244 } 245 246 if (defaultValue == null) 247 { 248 traceDefaultValue = "defaultValue: null "; 249 } 250 else 251 { 252 traceDefaultValue = "defaultValue: "+defaultValue+" "; 253 } 254 255 if (defaultInfo == null) 256 { 257 traceDefaultInfo = "defaultInfo: null "; 258 } 259 else 260 { 261 traceDefaultInfo = "defaultInfo: "+defaultInfo+" "; 262 } 263 264 if (newDefaultUUID == null) 265 { 266 traceNewDefaultUUID = "newDefaultUUID: null "; 267 } 268 else 269 { 270 traceNewDefaultUUID = "newDefaultUUID: "+newDefaultUUID+" "; 271 } 272 273 if (oldDefaultUUID == null) 274 { 275 traceOldDefaultUUID = "oldDefaultUUID: null "; 276 } 277 else 278 { 279 traceOldDefaultUUID = "oldDefaultUUID: "+oldDefaultUUID+" "; 280 } 281 282 traceAction = "action: "+action+" "; 283 284 if (autoincInc != 0) 285 { 286 traceAI = "autoincrement, start: " + autoincStart + 287 " increment:" + autoincInc; 288 } 289 else 290 { 291 traceAI = "NOT autoincrement"; 292 } 293 return "ColumnInfo: ("+traceName+traceDataType+traceDefaultValue+ 294 traceDefaultInfo+traceNewDefaultUUID+traceOldDefaultUUID+traceAction+traceAI+")"; 295 } 296 else 297 { 298 return ""; 299 } 300 } 301 } 302 | Popular Tags |