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 27 28 32 public abstract class BaseIssueVote extends BaseObject 33 implements org.apache.fulcrum.intake.Retrievable 34 { 35 36 private static final IssueVotePeer peer = 37 new IssueVotePeer(); 38 39 40 41 private Long issueId; 42 43 44 private Integer userId; 45 46 47 private int votes = 0; 48 49 50 55 public Long getIssueId() 56 { 57 return issueId; 58 } 59 60 61 66 public void setIssueId(Long v) throws TorqueException 67 { 68 69 if (!ObjectUtils.equals(this.issueId, v)) 70 { 71 this.issueId = v; 72 setModified(true); 73 } 74 75 76 if (aIssue != null && !ObjectUtils.equals(aIssue.getIssueId(), v)) 77 { 78 aIssue = null; 79 } 80 81 } 82 83 88 public Integer getUserId() 89 { 90 return userId; 91 } 92 93 94 99 public void setUserId(Integer v) throws TorqueException 100 { 101 102 if (!ObjectUtils.equals(this.userId, v)) 103 { 104 this.userId = v; 105 setModified(true); 106 } 107 108 109 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v)) 110 { 111 aScarabUser = null; 112 } 113 114 } 115 116 121 public int getVotes() 122 { 123 return votes; 124 } 125 126 127 132 public void setVotes(int v) 133 { 134 135 if (this.votes != v) 136 { 137 this.votes = v; 138 setModified(true); 139 } 140 141 142 } 143 144 145 146 147 private Issue aIssue; 148 149 155 public void setIssue(Issue v) throws TorqueException 156 { 157 if (v == null) 158 { 159 setIssueId((Long ) null); 160 } 161 else 162 { 163 setIssueId(v.getIssueId()); 164 } 165 aIssue = v; 166 } 167 168 169 175 public Issue getIssue() throws TorqueException 176 { 177 if ( !ObjectUtils.equals(getIssueId(), null) ) 178 { 179 return IssueManager.getInstance(SimpleKey.keyFor(getIssueId())); 180 } 181 return aIssue; 182 } 183 184 190 public void setIssueKey(ObjectKey key) throws TorqueException 191 { 192 193 setIssueId(new Long (((NumberKey) key).longValue())); 194 } 195 196 197 198 private ScarabUser aScarabUser; 199 200 206 public void setScarabUser(ScarabUser v) throws TorqueException 207 { 208 if (v == null) 209 { 210 setUserId((Integer ) null); 211 } 212 else 213 { 214 setUserId(v.getUserId()); 215 } 216 aScarabUser = v; 217 } 218 219 220 226 public ScarabUser getScarabUser() throws TorqueException 227 { 228 if ( !ObjectUtils.equals(getUserId(), null) ) 229 { 230 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId())); 231 } 232 return aScarabUser; 233 } 234 235 241 public void setScarabUserKey(ObjectKey key) throws TorqueException 242 { 243 244 setUserId(new Integer (((NumberKey) key).intValue())); 245 } 246 247 248 private static List fieldNames = null; 249 250 255 public static synchronized List getFieldNames() 256 { 257 if (fieldNames == null) 258 { 259 fieldNames = new ArrayList (); 260 fieldNames.add("IssueId"); 261 fieldNames.add("UserId"); 262 fieldNames.add("Votes"); 263 fieldNames = Collections.unmodifiableList(fieldNames); 264 } 265 return fieldNames; 266 } 267 268 274 public Object getByName(String name) 275 { 276 if (name.equals("IssueId")) 277 { 278 return getIssueId(); 279 } 280 if (name.equals("UserId")) 281 { 282 return getUserId(); 283 } 284 if (name.equals("Votes")) 285 { 286 return new Integer (getVotes()); 287 } 288 return null; 289 } 290 291 299 public Object getByPeerName(String name) 300 { 301 if (name.equals(IssueVotePeer.ISSUE_ID)) 302 { 303 return getIssueId(); 304 } 305 if (name.equals(IssueVotePeer.USER_ID)) 306 { 307 return getUserId(); 308 } 309 if (name.equals(IssueVotePeer.VOTES)) 310 { 311 return new Integer (getVotes()); 312 } 313 return null; 314 } 315 316 323 public Object getByPosition(int pos) 324 { 325 if (pos == 0) 326 { 327 return getIssueId(); 328 } 329 if (pos == 1) 330 { 331 return getUserId(); 332 } 333 if (pos == 2) 334 { 335 return new Integer (getVotes()); 336 } 337 return null; 338 } 339 340 346 public void save() throws Exception 347 { 348 save(IssueVotePeer.getMapBuilder() 349 .getDatabaseMap().getName()); 350 } 351 352 362 public void save(String dbName) throws TorqueException 363 { 364 Connection con = null; 365 try 366 { 367 con = Transaction.begin(dbName); 368 save(con); 369 Transaction.commit(con); 370 } 371 catch(TorqueException e) 372 { 373 Transaction.safeRollback(con); 374 throw e; 375 } 376 } 377 378 380 private boolean alreadyInSave = false; 381 391 public void save(Connection con) throws TorqueException 392 { 393 if (!alreadyInSave) 394 { 395 alreadyInSave = true; 396 397 398 399 if (isModified()) 401 { 402 if (isNew()) 403 { 404 IssueVotePeer.doInsert((IssueVote)this, con); 405 setNew(false); 406 } 407 else 408 { 409 IssueVotePeer.doUpdate((IssueVote)this, con); 410 } 411 412 if (isCacheOnSave()) 413 { 414 IssueVoteManager.putInstance(this); 415 } 416 } 417 418 alreadyInSave = false; 419 } 420 } 421 422 426 protected boolean isCacheOnSave() 427 { 428 return true; 429 } 430 431 432 433 private final SimpleKey[] pks = new SimpleKey[2]; 434 private final ComboKey comboPK = new ComboKey(pks); 435 436 441 public void setPrimaryKey(ObjectKey key) throws TorqueException 442 { 443 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 444 SimpleKey tmpKey = null; 445 setIssueId(new Long (((NumberKey)keys[0]).longValue())); 446 setUserId(new Integer (((NumberKey)keys[1]).intValue())); 447 } 448 449 455 public void setPrimaryKey( Long issueId, Integer userId) 456 throws TorqueException 457 { 458 setIssueId(issueId); 459 setUserId(userId); 460 } 461 462 465 public void setPrimaryKey(String key) throws TorqueException 466 { 467 setPrimaryKey(new ComboKey(key)); 468 } 469 470 474 public ObjectKey getPrimaryKey() 475 { 476 pks[0] = SimpleKey.keyFor(getIssueId()); 477 pks[1] = SimpleKey.keyFor(getUserId()); 478 return comboPK; 479 } 480 481 485 public String getQueryKey() 486 { 487 if (getPrimaryKey() == null) 488 { 489 return ""; 490 } 491 else 492 { 493 return getPrimaryKey().toString(); 494 } 495 } 496 497 501 public void setQueryKey(String key) 502 throws TorqueException 503 { 504 setPrimaryKey(key); 505 } 506 507 513 public IssueVote copy() throws TorqueException 514 { 515 IssueVote copyObj = new IssueVote(); 516 copyObj.setIssueId(issueId); 517 copyObj.setUserId(userId); 518 copyObj.setVotes(votes); 519 520 copyObj.setIssueId((Long )null); 521 copyObj.setUserId((Integer )null); 522 523 return copyObj; 524 } 525 526 532 public IssueVotePeer getPeer() 533 { 534 return peer; 535 } 536 537 public String toString() 538 { 539 StringBuffer str = new StringBuffer (); 540 str.append("IssueVote:\n"); 541 str.append("IssueId = ") 542 .append(getIssueId()) 543 .append("\n"); 544 str.append("UserId = ") 545 .append(getUserId()) 546 .append("\n"); 547 str.append("Votes = ") 548 .append(getVotes()) 549 .append("\n"); 550 return(str.toString()); 551 } 552 } 553 | Popular Tags |