1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.types.DataTypeDescriptor; 25 import org.apache.derby.iapi.types.DataValueDescriptor; 26 27 import org.apache.derby.iapi.reference.SQLState; 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 import org.apache.derby.iapi.sql.StatementType; 30 31 import org.apache.derby.catalog.DefaultInfo; 32 import org.apache.derby.catalog.UUID; 33 34 import org.apache.derby.impl.sql.compile.ColumnDefinitionNode; 35 36 58 59 public final class ColumnDescriptor extends TupleDescriptor 60 { 61 62 private DefaultInfo columnDefaultInfo; 64 private TableDescriptor table; 65 private String columnName; 66 private int columnPosition; 67 private DataTypeDescriptor columnType; 68 private DataValueDescriptor columnDefault; 69 private UUID uuid; 70 private UUID defaultUUID; 71 private long autoincStart; 72 private long autoincInc; 73 long autoinc_create_or_modify_Start_Increment = -1; 78 79 103 104 public ColumnDescriptor(String columnName, int columnPosition, 105 DataTypeDescriptor columnType, DataValueDescriptor columnDefault, 106 DefaultInfo columnDefaultInfo, 107 TableDescriptor table, 108 UUID defaultUUID, long autoincStart, long autoincInc, 109 long userChangedWhat) 110 { 111 this(columnName, columnPosition, columnType, columnDefault, 112 columnDefaultInfo, table, defaultUUID, autoincStart, 113 autoincInc); 114 autoinc_create_or_modify_Start_Increment = userChangedWhat; 115 } 116 117 134 135 public ColumnDescriptor(String columnName, int columnPosition, 136 DataTypeDescriptor columnType, DataValueDescriptor columnDefault, 137 DefaultInfo columnDefaultInfo, 138 TableDescriptor table, 139 UUID defaultUUID, long autoincStart, long autoincInc) 140 { 141 this.columnName = columnName; 142 this.columnPosition = columnPosition; 143 this.columnType = columnType; 144 this.columnDefault = columnDefault; 145 this.columnDefaultInfo = columnDefaultInfo; 146 this.defaultUUID = defaultUUID; 147 if (table != null) 148 { 149 this.table = table; 150 this.uuid = table.getUUID(); 151 } 152 153 assertAutoinc(autoincInc != 0, 154 autoincInc, 155 columnDefaultInfo); 156 157 this.autoincStart = autoincStart; 158 this.autoincInc = autoincInc; 159 160 } 161 162 181 public ColumnDescriptor(String columnName, int columnPosition, 182 DataTypeDescriptor columnType, DataValueDescriptor columnDefault, 183 DefaultInfo columnDefaultInfo, 184 UUID uuid, 185 UUID defaultUUID, 186 long autoincStart, long autoincInc) 187 188 { 189 this.columnName = columnName; 190 this.columnPosition = columnPosition; 191 this.columnType = columnType; 192 this.columnDefault = columnDefault; 193 this.columnDefaultInfo = columnDefaultInfo; 194 this.uuid = uuid; 195 this.defaultUUID = defaultUUID; 196 197 assertAutoinc(autoincInc!=0, 198 autoincInc, 199 columnDefaultInfo); 200 201 this.autoincStart = autoincStart; 202 this.autoincInc = autoincInc; 203 } 204 205 210 public UUID getReferencingUUID() 211 { 212 return uuid; 213 } 214 215 220 public TableDescriptor getTableDescriptor() 221 { 222 return table; 223 } 224 225 230 public String getColumnName() 231 { 232 return columnName; 233 } 234 235 240 public void setColumnName(String newColumnName) 241 { 242 this.columnName = newColumnName; 243 } 244 245 250 public void setTableDescriptor(TableDescriptor tableDescriptor) 251 { 252 this.table = tableDescriptor; 253 } 254 255 260 public int getPosition() 261 { 262 return columnPosition; 263 } 264 265 270 public DataTypeDescriptor getType() 271 { 272 return columnType; 273 } 274 275 280 public boolean hasNonNullDefault() 281 { 282 if (columnDefault != null && ! columnDefault.isNull()) 283 { 284 return true; 285 } 286 287 return columnDefaultInfo != null; 288 } 289 290 299 public DataValueDescriptor getDefaultValue() 300 { 301 return columnDefault; 302 } 303 304 309 public DefaultInfo getDefaultInfo() 310 { 311 return columnDefaultInfo; 312 } 313 314 319 public UUID getDefaultUUID() 320 { 321 return defaultUUID; 322 } 323 324 331 public DefaultDescriptor getDefaultDescriptor(DataDictionary dd) 332 { 333 DefaultDescriptor defaultDescriptor = null; 334 335 if (defaultUUID != null) 336 { 337 defaultDescriptor = new DefaultDescriptor(dd, defaultUUID, uuid, columnPosition); 338 } 339 340 return defaultDescriptor; 341 } 342 343 348 public boolean isAutoincrement() 349 { 350 return (autoincInc != 0); 351 } 352 public boolean updatableByCursor() 353 { 354 return false; 355 } 356 357 360 public boolean isAutoincAlways(){ 361 return (columnDefaultInfo == null) && isAutoincrement(); 362 } 363 364 369 public long getAutoincStart() 370 { 371 return autoincStart; 372 } 373 374 379 public long getAutoincInc() 380 { 381 return autoincInc; 382 } 383 384 public long getAutoinc_create_or_modify_Start_Increment() 385 { 386 return autoinc_create_or_modify_Start_Increment; 387 } 388 389 392 public void setPosition(int columnPosition) 393 { 394 this.columnPosition = columnPosition; 395 } 396 397 402 403 public String toString() 404 { 405 if (SanityManager.DEBUG) 406 { 407 411 return "columnName: " + columnName + "\n" + 412 "columnPosition: " + columnPosition + "\n" + 413 "columnType: " + columnType + "\n" + 414 "columnDefault: " + columnDefault + "\n" + 415 "uuid: " + uuid + "\n" + 416 "defaultUUID: " + defaultUUID + "\n"; 417 } 418 else 419 { 420 return ""; 421 } 422 } 423 424 425 public String getDescriptorName() 426 { 427 return columnName; 429 } 430 431 432 public String getDescriptorType() 433 { 434 return "Column"; 435 } 436 437 438 private static void assertAutoinc(boolean autoinc, 439 long autoincInc, 440 DefaultInfo defaultInfo){ 441 442 if (SanityManager.DEBUG) { 443 if (autoinc){ 444 SanityManager.ASSERT((autoincInc != 0), 445 "increment is zero for autoincrement column"); 446 SanityManager.ASSERT((defaultInfo == null || 447 defaultInfo.isDefaultValueAutoinc()), 448 "If column is autoinc and have defaultInfo, " + 449 "isDefaultValueAutoinc must be true."); 450 } 451 else{ 452 SanityManager.ASSERT((autoincInc == 0), 453 "increment is non-zero for non-autoincrement column"); 454 SanityManager.ASSERT((defaultInfo == null || 455 ! defaultInfo.isDefaultValueAutoinc()), 456 "If column is not autoinc and have defaultInfo, " + 457 "isDefaultValueAutoinc can not be true"); 458 } 459 } 460 } 461 462 } 463 | Popular Tags |