1 package org.tigris.scarab.om; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.fulcrum.intake.Retrievable; 13 import org.apache.torque.TorqueException; 14 import org.apache.torque.om.BaseObject; 15 import org.apache.torque.om.ComboKey; 16 import org.apache.torque.om.DateKey; 17 import org.apache.torque.om.NumberKey; 18 import org.apache.torque.om.ObjectKey; 19 import org.apache.torque.om.SimpleKey; 20 import org.apache.torque.om.StringKey; 21 import org.apache.torque.om.Persistent; 22 import org.apache.torque.util.Criteria; 23 import org.apache.torque.util.Transaction; 24 25 26 30 public abstract class BaseAttributeClass extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final AttributeClassPeer peer = 35 new AttributeClassPeer(); 36 37 38 39 private Integer attributeClassId; 40 41 42 private String name; 43 44 45 private String desc; 46 47 48 private String javaClassName; 49 50 51 56 public Integer getAttributeClassId() 57 { 58 return attributeClassId; 59 } 60 61 62 67 public void setAttributeClassId(Integer v) throws TorqueException 68 { 69 70 if (!ObjectUtils.equals(this.attributeClassId, v)) 71 { 72 this.attributeClassId = v; 73 setModified(true); 74 } 75 76 77 78 if (collAttributeTypes != null) 80 { 81 for (int i = 0; i < collAttributeTypes.size(); i++) 82 { 83 ((AttributeType) collAttributeTypes.get(i)) 84 .setClassId(v); 85 } 86 } 87 } 88 89 94 public String getName() 95 { 96 return name; 97 } 98 99 100 105 public void setName(String v) 106 { 107 108 if (!ObjectUtils.equals(this.name, v)) 109 { 110 this.name = v; 111 setModified(true); 112 } 113 114 115 } 116 117 122 public String getDesc() 123 { 124 return desc; 125 } 126 127 128 133 public void setDesc(String v) 134 { 135 136 if (!ObjectUtils.equals(this.desc, v)) 137 { 138 this.desc = v; 139 setModified(true); 140 } 141 142 143 } 144 145 150 public String getJavaClassName() 151 { 152 return javaClassName; 153 } 154 155 156 161 public void setJavaClassName(String v) 162 { 163 164 if (!ObjectUtils.equals(this.javaClassName, v)) 165 { 166 this.javaClassName = v; 167 setModified(true); 168 } 169 170 171 } 172 173 174 175 176 179 protected List collAttributeTypes; 180 181 186 protected void initAttributeTypes() 187 { 188 if (collAttributeTypes == null) 189 { 190 collAttributeTypes = new ArrayList (); 191 } 192 } 193 194 195 202 public void addAttributeType(AttributeType l) throws TorqueException 203 { 204 getAttributeTypes().add(l); 205 l.setAttributeClass((AttributeClass)this); 206 } 207 208 211 private Criteria lastAttributeTypesCriteria = null; 212 213 220 public List getAttributeTypes() throws TorqueException 221 { 222 if (collAttributeTypes == null) 223 { 224 collAttributeTypes = getAttributeTypes(new Criteria(10)); 225 } 226 return collAttributeTypes; 227 } 228 229 240 public List getAttributeTypes(Criteria criteria) throws TorqueException 241 { 242 if (collAttributeTypes == null) 243 { 244 if (isNew()) 245 { 246 collAttributeTypes = new ArrayList (); 247 } 248 else 249 { 250 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 251 collAttributeTypes = AttributeTypePeer.doSelect(criteria); 252 } 253 } 254 else 255 { 256 if (!isNew()) 258 { 259 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 263 if (!lastAttributeTypesCriteria.equals(criteria)) 264 { 265 collAttributeTypes = AttributeTypePeer.doSelect(criteria); 266 } 267 } 268 } 269 lastAttributeTypesCriteria = criteria; 270 271 return collAttributeTypes; 272 } 273 274 282 public List getAttributeTypes(Connection con) throws TorqueException 283 { 284 if (collAttributeTypes == null) 285 { 286 collAttributeTypes = getAttributeTypes(new Criteria(10),con); 287 } 288 return collAttributeTypes; 289 } 290 291 303 public List getAttributeTypes(Criteria criteria,Connection con) throws TorqueException 304 { 305 if (collAttributeTypes == null) 306 { 307 if (isNew()) 308 { 309 collAttributeTypes = new ArrayList (); 310 } 311 else 312 { 313 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 314 collAttributeTypes = AttributeTypePeer.doSelect(criteria,con); 315 } 316 } 317 else 318 { 319 if (!isNew()) 321 { 322 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 326 if (!lastAttributeTypesCriteria.equals(criteria)) 327 { 328 collAttributeTypes = AttributeTypePeer.doSelect(criteria,con); 329 } 330 } 331 } 332 lastAttributeTypesCriteria = criteria; 333 334 return collAttributeTypes; 335 } 336 337 338 339 340 341 342 343 344 345 346 347 358 protected List getAttributeTypesJoinAttributeClass(Criteria criteria) 359 throws TorqueException 360 { 361 if (collAttributeTypes == null) 362 { 363 if (isNew()) 364 { 365 collAttributeTypes = new ArrayList (); 366 } 367 else 368 { 369 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 370 collAttributeTypes = AttributeTypePeer.doSelectJoinAttributeClass(criteria); 371 } 372 } 373 else 374 { 375 379 criteria.add(AttributeTypePeer.ATTRIBUTE_CLASS_ID, getAttributeClassId() ); 380 if (!lastAttributeTypesCriteria.equals(criteria)) 381 { 382 collAttributeTypes = AttributeTypePeer.doSelectJoinAttributeClass(criteria); 383 } 384 } 385 lastAttributeTypesCriteria = criteria; 386 387 return collAttributeTypes; 388 } 389 390 391 392 393 private static List fieldNames = null; 394 395 400 public static synchronized List getFieldNames() 401 { 402 if (fieldNames == null) 403 { 404 fieldNames = new ArrayList (); 405 fieldNames.add("AttributeClassId"); 406 fieldNames.add("Name"); 407 fieldNames.add("Desc"); 408 fieldNames.add("JavaClassName"); 409 fieldNames = Collections.unmodifiableList(fieldNames); 410 } 411 return fieldNames; 412 } 413 414 420 public Object getByName(String name) 421 { 422 if (name.equals("AttributeClassId")) 423 { 424 return getAttributeClassId(); 425 } 426 if (name.equals("Name")) 427 { 428 return getName(); 429 } 430 if (name.equals("Desc")) 431 { 432 return getDesc(); 433 } 434 if (name.equals("JavaClassName")) 435 { 436 return getJavaClassName(); 437 } 438 return null; 439 } 440 441 449 public Object getByPeerName(String name) 450 { 451 if (name.equals(AttributeClassPeer.ATTRIBUTE_CLASS_ID)) 452 { 453 return getAttributeClassId(); 454 } 455 if (name.equals(AttributeClassPeer.ATTRIBUTE_CLASS_NAME)) 456 { 457 return getName(); 458 } 459 if (name.equals(AttributeClassPeer.ATTRIBUTE_CLASS_DESC)) 460 { 461 return getDesc(); 462 } 463 if (name.equals(AttributeClassPeer.JAVA_CLASS_NAME)) 464 { 465 return getJavaClassName(); 466 } 467 return null; 468 } 469 470 477 public Object getByPosition(int pos) 478 { 479 if (pos == 0) 480 { 481 return getAttributeClassId(); 482 } 483 if (pos == 1) 484 { 485 return getName(); 486 } 487 if (pos == 2) 488 { 489 return getDesc(); 490 } 491 if (pos == 3) 492 { 493 return getJavaClassName(); 494 } 495 return null; 496 } 497 498 504 public void save() throws Exception 505 { 506 save(AttributeClassPeer.getMapBuilder() 507 .getDatabaseMap().getName()); 508 } 509 510 520 public void save(String dbName) throws TorqueException 521 { 522 Connection con = null; 523 try 524 { 525 con = Transaction.begin(dbName); 526 save(con); 527 Transaction.commit(con); 528 } 529 catch(TorqueException e) 530 { 531 Transaction.safeRollback(con); 532 throw e; 533 } 534 } 535 536 538 private boolean alreadyInSave = false; 539 549 public void save(Connection con) throws TorqueException 550 { 551 if (!alreadyInSave) 552 { 553 alreadyInSave = true; 554 555 556 557 if (isModified()) 559 { 560 if (isNew()) 561 { 562 AttributeClassPeer.doInsert((AttributeClass)this, con); 563 setNew(false); 564 } 565 else 566 { 567 AttributeClassPeer.doUpdate((AttributeClass)this, con); 568 } 569 570 if (isCacheOnSave()) 571 { 572 AttributeClassManager.putInstance(this); 573 } 574 } 575 576 577 if (collAttributeTypes != null) 578 { 579 for (int i = 0; i < collAttributeTypes.size(); i++) 580 { 581 ((AttributeType)collAttributeTypes.get(i)).save(con); 582 } 583 } 584 alreadyInSave = false; 585 } 586 } 587 588 592 protected boolean isCacheOnSave() 593 { 594 return true; 595 } 596 597 598 603 public void setPrimaryKey(ObjectKey attributeClassId) 604 throws TorqueException { 605 setAttributeClassId(new Integer (((NumberKey)attributeClassId).intValue())); 606 } 607 608 613 public void setPrimaryKey(String key) throws TorqueException 614 { 615 setAttributeClassId(new Integer (key)); 616 } 617 618 619 623 public ObjectKey getPrimaryKey() 624 { 625 return SimpleKey.keyFor(getAttributeClassId()); 626 } 627 628 632 public String getQueryKey() 633 { 634 if (getPrimaryKey() == null) 635 { 636 return ""; 637 } 638 else 639 { 640 return getPrimaryKey().toString(); 641 } 642 } 643 644 648 public void setQueryKey(String key) 649 throws TorqueException 650 { 651 setPrimaryKey(key); 652 } 653 654 660 public AttributeClass copy() throws TorqueException 661 { 662 AttributeClass copyObj = new AttributeClass(); 663 copyObj.setAttributeClassId(attributeClassId); 664 copyObj.setName(name); 665 copyObj.setDesc(desc); 666 copyObj.setJavaClassName(javaClassName); 667 668 copyObj.setAttributeClassId((Integer )null); 669 670 671 672 List v = getAttributeTypes(); 673 for (int i = 0; i < v.size(); i++) 674 { 675 AttributeType obj = (AttributeType) v.get(i); 676 copyObj.addAttributeType(obj.copy()); 677 } 678 return copyObj; 679 } 680 681 687 public AttributeClassPeer getPeer() 688 { 689 return peer; 690 } 691 692 public String toString() 693 { 694 StringBuffer str = new StringBuffer (); 695 str.append("AttributeClass:\n"); 696 str.append("AttributeClassId = ") 697 .append(getAttributeClassId()) 698 .append("\n"); 699 str.append("Name = ") 700 .append(getName()) 701 .append("\n"); 702 str.append("Desc = ") 703 .append(getDesc()) 704 .append("\n"); 705 str.append("JavaClassName = ") 706 .append(getJavaClassName()) 707 .append("\n"); 708 return(str.toString()); 709 } 710 } 711 | Popular Tags |