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 BaseModification extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final ModificationPeer peer = 35 new ModificationPeer(); 36 37 38 39 private Integer tableId; 40 41 42 private Integer columnId; 43 44 45 private Integer modifiedBy; 46 47 48 private Integer createdBy; 49 50 51 private Date modifiedDate; 52 53 54 private Date createdDate; 55 56 57 62 public Integer getTableId() 63 { 64 return tableId; 65 } 66 67 68 73 public void setTableId(Integer v) 74 { 75 76 if (!ObjectUtils.equals(this.tableId, v)) 77 { 78 this.tableId = v; 79 setModified(true); 80 } 81 82 83 } 84 85 90 public Integer getColumnId() 91 { 92 return columnId; 93 } 94 95 96 101 public void setColumnId(Integer v) 102 { 103 104 if (!ObjectUtils.equals(this.columnId, v)) 105 { 106 this.columnId = v; 107 setModified(true); 108 } 109 110 111 } 112 113 118 public Integer getModifiedBy() 119 { 120 return modifiedBy; 121 } 122 123 124 129 public void setModifiedBy(Integer v) 130 { 131 132 if (!ObjectUtils.equals(this.modifiedBy, v)) 133 { 134 this.modifiedBy = v; 135 setModified(true); 136 } 137 138 139 } 140 141 146 public Integer getCreatedBy() 147 { 148 return createdBy; 149 } 150 151 152 157 public void setCreatedBy(Integer v) 158 { 159 160 if (!ObjectUtils.equals(this.createdBy, v)) 161 { 162 this.createdBy = v; 163 setModified(true); 164 } 165 166 167 } 168 169 174 public Date getModifiedDate() 175 { 176 return modifiedDate; 177 } 178 179 180 185 public void setModifiedDate(Date v) 186 { 187 188 if (!ObjectUtils.equals(this.modifiedDate, v)) 189 { 190 this.modifiedDate = v; 191 setModified(true); 192 } 193 194 195 } 196 197 202 public Date getCreatedDate() 203 { 204 return createdDate; 205 } 206 207 208 213 public void setCreatedDate(Date v) 214 { 215 216 if (!ObjectUtils.equals(this.createdDate, v)) 217 { 218 this.createdDate = v; 219 setModified(true); 220 } 221 222 223 } 224 225 226 227 private static List fieldNames = null; 228 229 234 public static synchronized List getFieldNames() 235 { 236 if (fieldNames == null) 237 { 238 fieldNames = new ArrayList (); 239 fieldNames.add("TableId"); 240 fieldNames.add("ColumnId"); 241 fieldNames.add("ModifiedBy"); 242 fieldNames.add("CreatedBy"); 243 fieldNames.add("ModifiedDate"); 244 fieldNames.add("CreatedDate"); 245 fieldNames = Collections.unmodifiableList(fieldNames); 246 } 247 return fieldNames; 248 } 249 250 256 public Object getByName(String name) 257 { 258 if (name.equals("TableId")) 259 { 260 return getTableId(); 261 } 262 if (name.equals("ColumnId")) 263 { 264 return getColumnId(); 265 } 266 if (name.equals("ModifiedBy")) 267 { 268 return getModifiedBy(); 269 } 270 if (name.equals("CreatedBy")) 271 { 272 return getCreatedBy(); 273 } 274 if (name.equals("ModifiedDate")) 275 { 276 return getModifiedDate(); 277 } 278 if (name.equals("CreatedDate")) 279 { 280 return getCreatedDate(); 281 } 282 return null; 283 } 284 285 293 public Object getByPeerName(String name) 294 { 295 if (name.equals(ModificationPeer.TABLE_ID)) 296 { 297 return getTableId(); 298 } 299 if (name.equals(ModificationPeer.COLUMN_ID)) 300 { 301 return getColumnId(); 302 } 303 if (name.equals(ModificationPeer.MODIFIED_BY)) 304 { 305 return getModifiedBy(); 306 } 307 if (name.equals(ModificationPeer.CREATED_BY)) 308 { 309 return getCreatedBy(); 310 } 311 if (name.equals(ModificationPeer.MODIFIED_DATE)) 312 { 313 return getModifiedDate(); 314 } 315 if (name.equals(ModificationPeer.CREATED_DATE)) 316 { 317 return getCreatedDate(); 318 } 319 return null; 320 } 321 322 329 public Object getByPosition(int pos) 330 { 331 if (pos == 0) 332 { 333 return getTableId(); 334 } 335 if (pos == 1) 336 { 337 return getColumnId(); 338 } 339 if (pos == 2) 340 { 341 return getModifiedBy(); 342 } 343 if (pos == 3) 344 { 345 return getCreatedBy(); 346 } 347 if (pos == 4) 348 { 349 return getModifiedDate(); 350 } 351 if (pos == 5) 352 { 353 return getCreatedDate(); 354 } 355 return null; 356 } 357 358 364 public void save() throws Exception 365 { 366 save(ModificationPeer.getMapBuilder() 367 .getDatabaseMap().getName()); 368 } 369 370 380 public void save(String dbName) throws TorqueException 381 { 382 Connection con = null; 383 try 384 { 385 con = Transaction.begin(dbName); 386 save(con); 387 Transaction.commit(con); 388 } 389 catch(TorqueException e) 390 { 391 Transaction.safeRollback(con); 392 throw e; 393 } 394 } 395 396 398 private boolean alreadyInSave = false; 399 409 public void save(Connection con) throws TorqueException 410 { 411 if (!alreadyInSave) 412 { 413 alreadyInSave = true; 414 415 416 417 if (isModified()) 419 { 420 if (isNew()) 421 { 422 ModificationPeer.doInsert((Modification)this, con); 423 setNew(false); 424 } 425 else 426 { 427 ModificationPeer.doUpdate((Modification)this, con); 428 } 429 430 if (isCacheOnSave()) 431 { 432 ModificationManager.putInstance(this); 433 } 434 } 435 436 alreadyInSave = false; 437 } 438 } 439 440 444 protected boolean isCacheOnSave() 445 { 446 return true; 447 } 448 449 450 451 private final SimpleKey[] pks = new SimpleKey[2]; 452 private final ComboKey comboPK = new ComboKey(pks); 453 454 459 public void setPrimaryKey(ObjectKey key) throws TorqueException 460 { 461 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 462 SimpleKey tmpKey = null; 463 setTableId(new Integer (((NumberKey)keys[0]).intValue())); 464 setColumnId(new Integer (((NumberKey)keys[1]).intValue())); 465 } 466 467 473 public void setPrimaryKey( Integer tableId, Integer columnId) 474 475 { 476 setTableId(tableId); 477 setColumnId(columnId); 478 } 479 480 483 public void setPrimaryKey(String key) throws TorqueException 484 { 485 setPrimaryKey(new ComboKey(key)); 486 } 487 488 492 public ObjectKey getPrimaryKey() 493 { 494 pks[0] = SimpleKey.keyFor(getTableId()); 495 pks[1] = SimpleKey.keyFor(getColumnId()); 496 return comboPK; 497 } 498 499 503 public String getQueryKey() 504 { 505 if (getPrimaryKey() == null) 506 { 507 return ""; 508 } 509 else 510 { 511 return getPrimaryKey().toString(); 512 } 513 } 514 515 519 public void setQueryKey(String key) 520 throws TorqueException 521 { 522 setPrimaryKey(key); 523 } 524 525 531 public Modification copy() throws TorqueException 532 { 533 Modification copyObj = new Modification(); 534 copyObj.setTableId(tableId); 535 copyObj.setColumnId(columnId); 536 copyObj.setModifiedBy(modifiedBy); 537 copyObj.setCreatedBy(createdBy); 538 copyObj.setModifiedDate(modifiedDate); 539 copyObj.setCreatedDate(createdDate); 540 541 copyObj.setTableId((Integer )null); 542 copyObj.setColumnId((Integer )null); 543 544 return copyObj; 545 } 546 547 553 public ModificationPeer getPeer() 554 { 555 return peer; 556 } 557 558 public String toString() 559 { 560 StringBuffer str = new StringBuffer (); 561 str.append("Modification:\n"); 562 str.append("TableId = ") 563 .append(getTableId()) 564 .append("\n"); 565 str.append("ColumnId = ") 566 .append(getColumnId()) 567 .append("\n"); 568 str.append("ModifiedBy = ") 569 .append(getModifiedBy()) 570 .append("\n"); 571 str.append("CreatedBy = ") 572 .append(getCreatedBy()) 573 .append("\n"); 574 str.append("ModifiedDate = ") 575 .append(getModifiedDate()) 576 .append("\n"); 577 str.append("CreatedDate = ") 578 .append(getCreatedDate()) 579 .append("\n"); 580 return(str.toString()); 581 } 582 } 583 | Popular Tags |