1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.StatementType; 25 26 import org.apache.derby.iapi.types.TypeId; 27 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 28 import org.apache.derby.iapi.error.StandardException; 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 import org.apache.derby.iapi.sql.depend.ProviderList; 31 32 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 33 34 import org.apache.derby.iapi.services.monitor.Monitor; 35 36 import org.apache.derby.iapi.util.JBitSet; 37 import org.apache.derby.iapi.util.ReuseFactory; 38 39 import org.apache.derby.catalog.UUID; 40 import org.apache.derby.iapi.services.uuid.UUIDFactory; 41 import org.apache.derby.iapi.reference.SQLState; 42 import java.util.Properties ; 43 44 50 51 public class ConstraintDefinitionNode extends TableElementNode 52 { 53 54 private TableName constraintName; 55 protected int constraintType; 56 protected Properties properties; 57 ProviderList apl; 58 59 UUIDFactory uuidFactory; 60 61 String backingIndexName; 62 UUID backingIndexUUID; 63 int[] checkColumnReferences; 64 ResultColumnList columnList; 65 String constraintText; 66 ValueNode checkCondition; 67 private int behavior; 68 private int verifyType = DataDictionary.DROP_CONSTRAINT; 70 public void init( 71 Object constraintName, 72 Object constraintType, 73 Object rcl, 74 Object properties, 75 Object checkCondition, 76 Object constraintText, 77 Object behavior) 78 { 79 this.constraintName = (TableName) constraintName; 80 81 84 super.init(null); 85 if (this.constraintName != null) 86 { 87 this.name = this.constraintName.getTableName(); 88 } 89 this.constraintType = ((Integer ) constraintType).intValue(); 90 this.properties = (Properties ) properties; 91 this.columnList = (ResultColumnList) rcl; 92 this.checkCondition = (ValueNode) checkCondition; 93 this.constraintText = (String ) constraintText; 94 this.behavior = ((Integer ) behavior).intValue(); 95 } 96 97 public void init( 98 Object constraintName, 99 Object constraintType, 100 Object rcl, 101 Object properties, 102 Object checkCondition, 103 Object constraintText) 104 { 105 init( 106 constraintName, 107 constraintType, 108 rcl, 109 properties, 110 checkCondition, 111 constraintText, 112 ReuseFactory.getInteger(StatementType.DROP_DEFAULT) 113 ); 114 } 115 116 public void init( 117 Object constraintName, 118 Object constraintType, 119 Object rcl, 120 Object properties, 121 Object checkCondition, 122 Object constraintText, 123 Object behavior, 124 Object verifyType) 125 { 126 init( constraintName, constraintType, rcl, properties, checkCondition, constraintText, behavior); 127 this.verifyType = ((Integer ) verifyType).intValue(); 128 } 129 130 136 137 public String toString() 138 { 139 if (SanityManager.DEBUG) 140 { 141 return "constraintName: " + 142 ( ( constraintName != null) ? 143 constraintName.toString() : "null" ) + "\n" + 144 "constraintType: " + constraintType + "\n" + 145 "properties: " + 146 ((properties != null) ? properties.toString() : "null") + "\n" + 147 super.toString(); 148 } 149 else 150 { 151 return ""; 152 } 153 } 154 155 163 protected void bind(DDLStatementNode ddlNode, DataDictionary dd) throws StandardException 164 { 165 if (constraintType == DataDictionary.DROP_CONSTRAINT) 168 return; 169 170 if (constraintName != null) { 172 173 String constraintSchema = constraintName.getSchemaName(); 174 175 176 if (constraintSchema != null) { 177 178 179 180 TableName tableName = ddlNode.getObjectName(); 181 String tableSchema = tableName.getSchemaName(); 182 if (tableSchema == null) { 183 tableSchema = getSchemaDescriptor((String ) null).getSchemaName(); 184 tableName.setSchemaName(tableSchema); 185 } 186 if (!constraintSchema.equals(tableSchema)) { 187 throw StandardException.newException(SQLState.LANG_CONSTRAINT_SCHEMA_MISMATCH, 188 constraintName, tableName); 189 190 } 191 } 192 } 193 else { 194 name = getBackingIndexName(dd); 195 } 196 } 197 198 204 String getConstraintMoniker() 205 { 206 return name; 207 } 208 209 214 String getDropSchemaName() { 215 if (constraintName != null) 216 return constraintName.getSchemaName(); 217 return null; 218 } 219 220 226 UUID getBackingIndexUUID() 227 { 228 if ( backingIndexUUID == null ) 229 { 230 backingIndexUUID = getUUIDFactory().createUUID(); 231 } 232 233 return backingIndexUUID; 234 } 235 236 244 String getBackingIndexName(DataDictionary dd) 245 { 246 if ( backingIndexName == null ) 247 backingIndexName = dd.getSystemSQLName(); 248 249 return backingIndexName; 250 } 251 252 257 void setAuxiliaryProviderList(ProviderList apl) 258 { 259 this.apl = apl; 260 } 261 262 267 public ProviderList getAuxiliaryProviderList() 268 { 269 return apl; 270 } 271 272 277 boolean hasPrimaryKeyConstraint() 278 { 279 return constraintType == DataDictionary.PRIMARYKEY_CONSTRAINT; 280 } 281 282 287 boolean hasUniqueKeyConstraint() 288 { 289 return constraintType == DataDictionary.UNIQUE_CONSTRAINT; 290 } 291 292 297 boolean hasForeignKeyConstraint() 298 { 299 return constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT; 300 } 301 302 307 boolean hasCheckConstraint() 308 { 309 return constraintType == DataDictionary.CHECK_CONSTRAINT; 310 } 311 312 317 boolean hasConstraint() 318 { 319 return true; 320 } 321 322 327 boolean requiresBackingIndex() 328 { 329 switch (constraintType) 330 { 331 case DataDictionary.FOREIGNKEY_CONSTRAINT: 332 case DataDictionary.PRIMARYKEY_CONSTRAINT: 333 case DataDictionary.UNIQUE_CONSTRAINT: 334 return true; 335 default: 336 return false; 337 } 338 } 339 340 345 boolean requiresUniqueIndex() 346 { 347 switch (constraintType) 348 { 349 case DataDictionary.PRIMARYKEY_CONSTRAINT: 350 case DataDictionary.UNIQUE_CONSTRAINT: 351 return true; 352 default: 353 return false; 354 } 355 } 356 357 362 int getConstraintType() 363 { 364 return constraintType; 365 } 366 367 372 public void setProperties(Properties properties) 373 { 374 this.properties = properties; 375 } 376 377 383 public Properties getProperties() 384 { 385 return properties; 386 } 387 388 389 394 public boolean isReferenced() 395 { 396 return false; 397 } 398 399 405 public int getReferenceCount() 406 { 407 return 0; 408 } 409 414 public boolean isEnabled() 415 { 416 return true; 417 } 418 419 424 public ResultColumnList getColumnList() 425 { 426 return columnList; 427 } 428 429 435 public void setColumnList(ResultColumnList columnList) 436 { 437 this.columnList = columnList; 438 } 439 440 445 public ValueNode getCheckCondition() 446 { 447 return checkCondition; 448 } 449 450 455 public void setCheckCondition(ValueNode checkCondition) 456 { 457 this.checkCondition = checkCondition; 458 } 459 460 465 public String getConstraintText() 466 { 467 return constraintText; 468 } 469 470 475 public int[] getCheckColumnReferences() 476 { 477 return checkColumnReferences; 478 } 479 480 486 public void setCheckColumnReferences(int[] checkColumnReferences) 487 { 488 this.checkColumnReferences = checkColumnReferences; 489 } 490 491 496 int getDropBehavior() 497 { 498 return behavior; 499 } 500 501 505 int getVerifyType() 506 { 507 return verifyType; 508 } 509 510 521 private UUIDFactory getUUIDFactory() 522 { 523 if ( uuidFactory == null ) 524 { 525 uuidFactory = Monitor.getMonitor().getUUIDFactory(); 526 } 527 return uuidFactory; 528 } 529 } 530 | Popular Tags |