1 package org.apache.torque.map; 2 3 21 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 26 import org.apache.commons.collections.map.ListOrderedMap; 27 28 39 public class ColumnMap implements java.io.Serializable 40 { 41 42 private static final long serialVersionUID = -5971184507395399165L; 43 44 45 private Object type = null; 46 47 48 private String torqueType = null; 49 50 51 private boolean usePrimitive = true; 52 53 54 private int size = 0; 55 56 57 private int scale = 0; 58 59 60 private boolean pk = false; 61 62 63 private boolean notNull = false; 64 65 66 private String relatedTableName = ""; 67 68 69 private String relatedColumnName = ""; 70 71 72 private TableMap table; 73 74 75 private String columnName; 76 77 81 private String javaName; 82 83 84 private boolean autoIncrement = false; 85 86 87 private String description = ""; 88 89 90 private boolean isProtected = false; 91 92 97 private String defaultValue = null; 98 99 100 private String inheritance = "false"; 101 102 106 private boolean useInheritance; 107 108 109 private Map inheritanceMaps = Collections 110 .synchronizedMap(new ListOrderedMap()); 111 112 113 private String inputValidator; 114 115 116 private String javaNamingMethod; 117 118 119 private String javaType; 120 121 122 private int position = -1; 123 124 130 public ColumnMap(String name, TableMap containingTable) 131 { 132 table = containingTable; 133 this.columnName = normalizeName(name); 134 } 135 136 143 protected String normalizeName(String name) 144 { 145 if (name.indexOf('.') > 0) 146 { 147 return name.substring(name.lastIndexOf('.') + 1); 148 } 149 return name; 150 } 151 152 157 public String getColumnName() 158 { 159 return columnName; 160 } 161 162 167 public String getFullyQualifiedName() 168 { 169 return table.getName() + "." + columnName; 170 } 171 172 177 public String getTableName() 178 { 179 return table.getName(); 180 } 181 182 187 public void setType(Object type) 188 { 189 this.type = type; 190 } 191 192 197 public void setTorqueType(String torqueType) 198 { 199 this.torqueType = torqueType; 200 } 201 202 207 public void setSize(int size) 208 { 209 this.size = size; 210 } 211 212 217 public void setPrimaryKey(boolean pk) 218 { 219 this.pk = pk; 220 } 221 222 227 public void setNotNull(boolean nn) 228 { 229 this.notNull = nn; 230 } 231 232 238 public void setForeignKey(String fullyQualifiedName) 239 { 240 if (fullyQualifiedName != null && fullyQualifiedName.length() > 0) 241 { 242 relatedTableName = fullyQualifiedName.substring( 243 0, fullyQualifiedName.indexOf('.')); 244 relatedColumnName = fullyQualifiedName.substring( 245 fullyQualifiedName.indexOf('.') + 1); 246 } 247 else 248 { 249 relatedTableName = ""; 250 relatedColumnName = ""; 251 } 252 } 253 254 260 public void setForeignKey(String tableName, String columnName) 261 { 262 if (tableName != null && tableName.length() > 0 && columnName != null 263 && columnName.length() > 0) 264 { 265 relatedTableName = tableName; 266 relatedColumnName = normalizeName(columnName); 267 } 268 else 269 { 270 relatedTableName = ""; 271 relatedColumnName = ""; 272 } 273 } 274 275 281 public Object getType() 282 { 283 return type; 284 } 285 286 291 public String getTorqueType() 292 { 293 return torqueType; 294 } 295 296 309 public int getSize() 310 { 311 return size; 312 } 313 314 319 public boolean isPrimaryKey() 320 { 321 return pk; 322 } 323 324 329 public boolean isNotNull() 330 { 331 return (notNull || isPrimaryKey()); 332 } 333 334 339 public boolean isForeignKey() 340 { 341 return (relatedTableName != null && relatedTableName.length() > 0); 342 } 343 344 349 public String getRelatedName() 350 { 351 return relatedTableName + "." + relatedColumnName; 352 } 353 354 359 public String getRelatedTableName() 360 { 361 return relatedTableName; 362 } 363 364 369 public String getRelatedColumnName() 370 { 371 return relatedColumnName; 372 } 373 374 382 public int getScale() 383 { 384 return scale; 385 } 386 387 390 public void setScale(int scale) 391 { 392 this.scale = scale; 393 } 394 395 401 public String getJavaName() 402 { 403 return this.javaName; 404 } 405 406 411 public void setJavaName(String name) 412 { 413 this.javaName = name; 414 } 415 416 421 public boolean isAutoIncrement() 422 { 423 return autoIncrement; 424 } 425 426 431 public void setAutoIncrement(boolean autoIncrement) 432 { 433 this.autoIncrement = autoIncrement; 434 } 435 436 441 public String getDefault() 442 { 443 return defaultValue; 444 } 445 446 451 public void setDefault(String defaultValue) 452 { 453 this.defaultValue = defaultValue; 454 } 455 456 461 public String getDescription() 462 { 463 return description; 464 } 465 466 471 public void setDescription(String description) 472 { 473 this.description = description; 474 } 475 476 482 public InheritanceMap[] getInheritanceMaps() 483 { 484 InheritanceMap[] iMaps = new InheritanceMap[inheritanceMaps.size()]; 485 synchronized (inheritanceMaps) 486 { 487 Iterator it = inheritanceMaps.values().iterator(); 488 int i = 0; 489 while (it.hasNext()) 490 { 491 iMaps[i++] = (InheritanceMap) it.next(); 492 } 493 } 494 return iMaps; 495 } 496 497 502 public void addInheritanceMap(InheritanceMap map) 503 { 504 setUseInheritance(true); 505 this.inheritanceMaps.put(map.getKey(), map); 506 } 507 508 513 public String getInheritance() 514 { 515 return inheritance; 516 } 517 518 523 public void setInheritance(String inheritanceType) 524 { 525 this.inheritance = inheritanceType; 526 } 527 528 534 public String getInputValidator() 535 { 536 return inputValidator; 537 } 538 539 544 public void setInputValidator(String inputValidator) 545 { 546 this.inputValidator = inputValidator; 547 } 548 549 555 public boolean isProtected() 556 { 557 return isProtected; 558 } 559 560 567 public void setProtected(boolean isProtected) 568 { 569 this.isProtected = isProtected; 570 } 571 572 577 public boolean isPk() 578 { 579 return pk; 580 } 581 582 587 public void setPk(boolean pk) 588 { 589 this.pk = pk; 590 } 591 592 597 public boolean isUseInheritance() 598 { 599 return useInheritance; 600 } 601 602 607 public void setUseInheritance(boolean useInheritance) 608 { 609 this.useInheritance = useInheritance; 610 } 611 612 619 public InheritanceMap getInheritanceMap(String key) 620 { 621 return (InheritanceMap) inheritanceMaps.get(key); 622 } 623 624 630 public boolean isUsePrimitive() 631 { 632 return usePrimitive; 633 } 634 635 641 public void setUsePrimitive(boolean usePrimitive) 642 { 643 this.usePrimitive = usePrimitive; 644 } 645 646 651 public String getJavaNamingMethod() 652 { 653 return javaNamingMethod; 654 } 655 656 661 public void setJavaNamingMethod(String javaNamingMethod) 662 { 663 this.javaNamingMethod = javaNamingMethod; 664 } 665 666 671 public TableMap getTable() 672 { 673 return table; 674 } 675 676 682 public int getPosition() 683 { 684 return position; 685 } 686 687 692 public void setPosition(int position) 693 { 694 this.position = position; 695 } 696 697 702 public String getJavaType() 703 { 704 return javaType; 705 } 706 707 712 public void setJavaType(String javaType) 713 { 714 this.javaType = javaType; 715 } 716 } 717 | Popular Tags |