1 package org.campware.cream.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.turbine.om.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 34 public abstract class BaseProjectCategory extends BaseObject 35 implements org.apache.turbine.om.Retrievable 36 { 37 38 private static final ProjectCategoryPeer peer = 39 new ProjectCategoryPeer(); 40 41 42 43 private int projectCatId; 44 45 46 private String projectCatName; 47 48 49 54 public int getProjectCatId() 55 { 56 return projectCatId; 57 } 58 59 60 65 public void setProjectCatId(int v) throws TorqueException 66 { 67 68 if (this.projectCatId != v) 69 { 70 this.projectCatId = v; 71 setModified(true); 72 } 73 74 75 76 if (collProjects != null) 78 { 79 for (int i = 0; i < collProjects.size(); i++) 80 { 81 ((Project) collProjects.get(i)) 82 .setProjectCatId(v); 83 } 84 } 85 } 86 87 92 public String getProjectCatName() 93 { 94 return projectCatName; 95 } 96 97 98 103 public void setProjectCatName(String v) 104 { 105 106 if (!ObjectUtils.equals(this.projectCatName, v)) 107 { 108 this.projectCatName = v; 109 setModified(true); 110 } 111 112 113 } 114 115 116 117 118 121 protected List collProjects; 122 123 128 protected void initProjects() 129 { 130 if (collProjects == null) 131 { 132 collProjects = new ArrayList (); 133 } 134 } 135 136 143 public void addProject(Project l) throws TorqueException 144 { 145 getProjects().add(l); 146 l.setProjectCategory((ProjectCategory) this); 147 } 148 149 152 private Criteria lastProjectsCriteria = null; 153 154 161 public List getProjects() throws TorqueException 162 { 163 if (collProjects == null) 164 { 165 collProjects = getProjects(new Criteria(10)); 166 } 167 return collProjects; 168 } 169 170 181 public List getProjects(Criteria criteria) throws TorqueException 182 { 183 if (collProjects == null) 184 { 185 if (isNew()) 186 { 187 collProjects = new ArrayList (); 188 } 189 else 190 { 191 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId() ); 192 collProjects = ProjectPeer.doSelect(criteria); 193 } 194 } 195 else 196 { 197 if (!isNew()) 199 { 200 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId()); 204 if (!lastProjectsCriteria.equals(criteria)) 205 { 206 collProjects = ProjectPeer.doSelect(criteria); 207 } 208 } 209 } 210 lastProjectsCriteria = criteria; 211 212 return collProjects; 213 } 214 215 223 public List getProjects(Connection con) throws TorqueException 224 { 225 if (collProjects == null) 226 { 227 collProjects = getProjects(new Criteria(10), con); 228 } 229 return collProjects; 230 } 231 232 244 public List getProjects(Criteria criteria, Connection con) 245 throws TorqueException 246 { 247 if (collProjects == null) 248 { 249 if (isNew()) 250 { 251 collProjects = new ArrayList (); 252 } 253 else 254 { 255 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId()); 256 collProjects = ProjectPeer.doSelect(criteria, con); 257 } 258 } 259 else 260 { 261 if (!isNew()) 263 { 264 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId()); 268 if (!lastProjectsCriteria.equals(criteria)) 269 { 270 collProjects = ProjectPeer.doSelect(criteria, con); 271 } 272 } 273 } 274 lastProjectsCriteria = criteria; 275 276 return collProjects; 277 } 278 279 280 281 282 283 284 285 286 287 288 289 300 protected List getProjectsJoinProjectCategory(Criteria criteria) 301 throws TorqueException 302 { 303 if (collProjects == null) 304 { 305 if (isNew()) 306 { 307 collProjects = new ArrayList (); 308 } 309 else 310 { 311 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId()); 312 collProjects = ProjectPeer.doSelectJoinProjectCategory(criteria); 313 } 314 } 315 else 316 { 317 321 criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId()); 322 if (!lastProjectsCriteria.equals(criteria)) 323 { 324 collProjects = ProjectPeer.doSelectJoinProjectCategory(criteria); 325 } 326 } 327 lastProjectsCriteria = criteria; 328 329 return collProjects; 330 } 331 332 333 334 335 private static List fieldNames = null; 336 337 342 public static synchronized List getFieldNames() 343 { 344 if (fieldNames == null) 345 { 346 fieldNames = new ArrayList (); 347 fieldNames.add("ProjectCatId"); 348 fieldNames.add("ProjectCatName"); 349 fieldNames = Collections.unmodifiableList(fieldNames); 350 } 351 return fieldNames; 352 } 353 354 360 public Object getByName(String name) 361 { 362 if (name.equals("ProjectCatId")) 363 { 364 return new Integer (getProjectCatId()); 365 } 366 if (name.equals("ProjectCatName")) 367 { 368 return getProjectCatName(); 369 } 370 return null; 371 } 372 373 381 public Object getByPeerName(String name) 382 { 383 if (name.equals(ProjectCategoryPeer.PROJECT_CAT_ID)) 384 { 385 return new Integer (getProjectCatId()); 386 } 387 if (name.equals(ProjectCategoryPeer.PROJECT_CAT_NAME)) 388 { 389 return getProjectCatName(); 390 } 391 return null; 392 } 393 394 401 public Object getByPosition(int pos) 402 { 403 if (pos == 0) 404 { 405 return new Integer (getProjectCatId()); 406 } 407 if (pos == 1) 408 { 409 return getProjectCatName(); 410 } 411 return null; 412 } 413 414 420 public void save() throws Exception  421 { 422 save(ProjectCategoryPeer.getMapBuilder() 423 .getDatabaseMap().getName()); 424 } 425 426 436 public void save(String dbName) throws TorqueException 437 { 438 Connection con = null; 439 try 440 { 441 con = Transaction.begin(dbName); 442 save(con); 443 Transaction.commit(con); 444 } 445 catch(TorqueException e) 446 { 447 Transaction.safeRollback(con); 448 throw e; 449 } 450 } 451 452 454 private boolean alreadyInSave = false; 455 465 public void save(Connection con) throws TorqueException 466 { 467 if (!alreadyInSave) 468 { 469 alreadyInSave = true; 470 471 472 473 if (isModified()) 475 { 476 if (isNew()) 477 { 478 ProjectCategoryPeer.doInsert((ProjectCategory) this, con); 479 setNew(false); 480 } 481 else 482 { 483 ProjectCategoryPeer.doUpdate((ProjectCategory) this, con); 484 } 485 } 486 487 488 489 if (collProjects != null) 490 { 491 for (int i = 0; i < collProjects.size(); i++) 492 { 493 ((Project) collProjects.get(i)).save(con); 494 } 495 } 496 alreadyInSave = false; 497 } 498 } 499 500 501 506 public void setPrimaryKey(ObjectKey key) 507 throws TorqueException 508 { 509 setProjectCatId(((NumberKey) key).intValue()); 510 } 511 512 517 public void setPrimaryKey(String key) throws TorqueException 518 { 519 setProjectCatId(Integer.parseInt(key)); 520 } 521 522 523 527 public ObjectKey getPrimaryKey() 528 { 529 return SimpleKey.keyFor(getProjectCatId()); 530 } 531 532 536 public String getQueryKey() 537 { 538 if (getPrimaryKey() == null) 539 { 540 return ""; 541 } 542 else 543 { 544 return getPrimaryKey().toString(); 545 } 546 } 547 548 552 public void setQueryKey(String key) 553 throws TorqueException 554 { 555 setPrimaryKey(key); 556 } 557 558 564 public ProjectCategory copy() throws TorqueException 565 { 566 return copyInto(new ProjectCategory()); 567 } 568 569 protected ProjectCategory copyInto(ProjectCategory copyObj) throws TorqueException 570 { 571 copyObj.setProjectCatId(projectCatId); 572 copyObj.setProjectCatName(projectCatName); 573 574 copyObj.setProjectCatId( 0); 575 576 577 578 List v = getProjects(); 579 for (int i = 0; i < v.size(); i++) 580 { 581 Project obj = (Project) v.get(i); 582 copyObj.addProject(obj.copy()); 583 } 584 return copyObj; 585 } 586 587 593 public ProjectCategoryPeer getPeer() 594 { 595 return peer; 596 } 597 598 public String toString() 599 { 600 StringBuffer str = new StringBuffer (); 601 str.append("ProjectCategory:\n"); 602 str.append("ProjectCatId = ") 603 .append(getProjectCatId()) 604 .append("\n"); 605 str.append("ProjectCatName = ") 606 .append(getProjectCatName()) 607 .append("\n"); 608 return(str.toString()); 609 } 610 } 611
| Popular Tags
|