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 29 33 public abstract class BaseRQueryUser extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final RQueryUserPeer peer = 38 new RQueryUserPeer(); 39 40 41 42 private Long queryId; 43 44 45 private Integer userId; 46 47 48 private boolean isSubscribed = false; 49 50 51 private Integer subscriptionFrequency; 52 53 54 private boolean isdefault = false; 55 56 57 62 public Long getQueryId() 63 { 64 return queryId; 65 } 66 67 68 73 public void setQueryId(Long v) throws TorqueException 74 { 75 76 if (!ObjectUtils.equals(this.queryId, v)) 77 { 78 this.queryId = v; 79 setModified(true); 80 } 81 82 83 if (aQuery != null && !ObjectUtils.equals(aQuery.getQueryId(), v)) 84 { 85 aQuery = null; 86 } 87 88 } 89 90 95 public Integer getUserId() 96 { 97 return userId; 98 } 99 100 101 106 public void setUserId(Integer v) throws TorqueException 107 { 108 109 if (!ObjectUtils.equals(this.userId, v)) 110 { 111 this.userId = v; 112 setModified(true); 113 } 114 115 116 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v)) 117 { 118 aScarabUser = null; 119 } 120 121 } 122 123 128 public boolean getIsSubscribed() 129 { 130 return isSubscribed; 131 } 132 133 134 139 public void setIsSubscribed(boolean v) 140 { 141 142 if (this.isSubscribed != v) 143 { 144 this.isSubscribed = v; 145 setModified(true); 146 } 147 148 149 } 150 151 156 public Integer getSubscriptionFrequency() 157 { 158 return subscriptionFrequency; 159 } 160 161 162 167 public void setSubscriptionFrequency(Integer v) throws TorqueException 168 { 169 170 if (!ObjectUtils.equals(this.subscriptionFrequency, v)) 171 { 172 this.subscriptionFrequency = v; 173 setModified(true); 174 } 175 176 177 if (aFrequency != null && !ObjectUtils.equals(aFrequency.getFrequencyId(), v)) 178 { 179 aFrequency = null; 180 } 181 182 } 183 184 189 public boolean getIsdefault() 190 { 191 return isdefault; 192 } 193 194 195 200 public void setIsdefault(boolean v) 201 { 202 203 if (this.isdefault != v) 204 { 205 this.isdefault = v; 206 setModified(true); 207 } 208 209 210 } 211 212 213 214 215 private Query aQuery; 216 217 223 public void setQuery(Query v) throws TorqueException 224 { 225 if (v == null) 226 { 227 setQueryId((Long ) null); 228 } 229 else 230 { 231 setQueryId(v.getQueryId()); 232 } 233 aQuery = v; 234 } 235 236 237 243 public Query getQuery() throws TorqueException 244 { 245 if ( !ObjectUtils.equals(getQueryId(), null) ) 246 { 247 return QueryManager.getInstance(SimpleKey.keyFor(getQueryId())); 248 } 249 return aQuery; 250 } 251 252 258 public void setQueryKey(ObjectKey key) throws TorqueException 259 { 260 261 setQueryId(new Long (((NumberKey) key).longValue())); 262 } 263 264 265 266 private ScarabUser aScarabUser; 267 268 274 public void setScarabUser(ScarabUser v) throws TorqueException 275 { 276 if (v == null) 277 { 278 setUserId((Integer ) null); 279 } 280 else 281 { 282 setUserId(v.getUserId()); 283 } 284 aScarabUser = v; 285 } 286 287 288 294 public ScarabUser getScarabUser() throws TorqueException 295 { 296 if ( !ObjectUtils.equals(getUserId(), null) ) 297 { 298 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId())); 299 } 300 return aScarabUser; 301 } 302 303 309 public void setScarabUserKey(ObjectKey key) throws TorqueException 310 { 311 312 setUserId(new Integer (((NumberKey) key).intValue())); 313 } 314 315 316 317 private Frequency aFrequency; 318 319 325 public void setFrequency(Frequency v) throws TorqueException 326 { 327 if (v == null) 328 { 329 setSubscriptionFrequency((Integer ) null); 330 } 331 else 332 { 333 setSubscriptionFrequency(v.getFrequencyId()); 334 } 335 aFrequency = v; 336 } 337 338 339 345 public Frequency getFrequency() throws TorqueException 346 { 347 if ( !ObjectUtils.equals(getSubscriptionFrequency(), null) ) 348 { 349 return FrequencyManager.getInstance(SimpleKey.keyFor(getSubscriptionFrequency())); 350 } 351 return aFrequency; 352 } 353 354 360 public void setFrequencyKey(ObjectKey key) throws TorqueException 361 { 362 363 setSubscriptionFrequency(new Integer (((NumberKey) key).intValue())); 364 } 365 366 367 private static List fieldNames = null; 368 369 374 public static synchronized List getFieldNames() 375 { 376 if (fieldNames == null) 377 { 378 fieldNames = new ArrayList (); 379 fieldNames.add("QueryId"); 380 fieldNames.add("UserId"); 381 fieldNames.add("IsSubscribed"); 382 fieldNames.add("SubscriptionFrequency"); 383 fieldNames.add("Isdefault"); 384 fieldNames = Collections.unmodifiableList(fieldNames); 385 } 386 return fieldNames; 387 } 388 389 395 public Object getByName(String name) 396 { 397 if (name.equals("QueryId")) 398 { 399 return getQueryId(); 400 } 401 if (name.equals("UserId")) 402 { 403 return getUserId(); 404 } 405 if (name.equals("IsSubscribed")) 406 { 407 return Boolean.valueOf(getIsSubscribed()); 408 } 409 if (name.equals("SubscriptionFrequency")) 410 { 411 return getSubscriptionFrequency(); 412 } 413 if (name.equals("Isdefault")) 414 { 415 return Boolean.valueOf(getIsdefault()); 416 } 417 return null; 418 } 419 420 428 public Object getByPeerName(String name) 429 { 430 if (name.equals(RQueryUserPeer.QUERY_ID)) 431 { 432 return getQueryId(); 433 } 434 if (name.equals(RQueryUserPeer.USER_ID)) 435 { 436 return getUserId(); 437 } 438 if (name.equals(RQueryUserPeer.IS_SUBSCRIBED)) 439 { 440 return Boolean.valueOf(getIsSubscribed()); 441 } 442 if (name.equals(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID)) 443 { 444 return getSubscriptionFrequency(); 445 } 446 if (name.equals(RQueryUserPeer.ISDEFAULT)) 447 { 448 return Boolean.valueOf(getIsdefault()); 449 } 450 return null; 451 } 452 453 460 public Object getByPosition(int pos) 461 { 462 if (pos == 0) 463 { 464 return getQueryId(); 465 } 466 if (pos == 1) 467 { 468 return getUserId(); 469 } 470 if (pos == 2) 471 { 472 return Boolean.valueOf(getIsSubscribed()); 473 } 474 if (pos == 3) 475 { 476 return getSubscriptionFrequency(); 477 } 478 if (pos == 4) 479 { 480 return Boolean.valueOf(getIsdefault()); 481 } 482 return null; 483 } 484 485 491 public void save() throws Exception 492 { 493 save(RQueryUserPeer.getMapBuilder() 494 .getDatabaseMap().getName()); 495 } 496 497 507 public void save(String dbName) throws TorqueException 508 { 509 Connection con = null; 510 try 511 { 512 con = Transaction.begin(dbName); 513 save(con); 514 Transaction.commit(con); 515 } 516 catch(TorqueException e) 517 { 518 Transaction.safeRollback(con); 519 throw e; 520 } 521 } 522 523 525 private boolean alreadyInSave = false; 526 536 public void save(Connection con) throws TorqueException 537 { 538 if (!alreadyInSave) 539 { 540 alreadyInSave = true; 541 542 543 544 if (isModified()) 546 { 547 if (isNew()) 548 { 549 RQueryUserPeer.doInsert((RQueryUser)this, con); 550 setNew(false); 551 } 552 else 553 { 554 RQueryUserPeer.doUpdate((RQueryUser)this, con); 555 } 556 557 if (isCacheOnSave()) 558 { 559 RQueryUserManager.putInstance(this); 560 } 561 } 562 563 alreadyInSave = false; 564 } 565 } 566 567 571 protected boolean isCacheOnSave() 572 { 573 return true; 574 } 575 576 577 578 private final SimpleKey[] pks = new SimpleKey[2]; 579 private final ComboKey comboPK = new ComboKey(pks); 580 581 586 public void setPrimaryKey(ObjectKey key) throws TorqueException 587 { 588 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 589 SimpleKey tmpKey = null; 590 setQueryId(new Long (((NumberKey)keys[0]).longValue())); 591 setUserId(new Integer (((NumberKey)keys[1]).intValue())); 592 } 593 594 600 public void setPrimaryKey( Long queryId, Integer userId) 601 throws TorqueException 602 { 603 setQueryId(queryId); 604 setUserId(userId); 605 } 606 607 610 public void setPrimaryKey(String key) throws TorqueException 611 { 612 setPrimaryKey(new ComboKey(key)); 613 } 614 615 619 public ObjectKey getPrimaryKey() 620 { 621 pks[0] = SimpleKey.keyFor(getQueryId()); 622 pks[1] = SimpleKey.keyFor(getUserId()); 623 return comboPK; 624 } 625 626 630 public String getQueryKey() 631 { 632 if (getPrimaryKey() == null) 633 { 634 return ""; 635 } 636 else 637 { 638 return getPrimaryKey().toString(); 639 } 640 } 641 642 646 public void setQueryKey(String key) 647 throws TorqueException 648 { 649 setPrimaryKey(key); 650 } 651 652 658 public RQueryUser copy() throws TorqueException 659 { 660 RQueryUser copyObj = new RQueryUser(); 661 copyObj.setQueryId(queryId); 662 copyObj.setUserId(userId); 663 copyObj.setIsSubscribed(isSubscribed); 664 copyObj.setSubscriptionFrequency(subscriptionFrequency); 665 copyObj.setIsdefault(isdefault); 666 667 copyObj.setQueryId((Long )null); 668 copyObj.setUserId((Integer )null); 669 670 return copyObj; 671 } 672 673 679 public RQueryUserPeer getPeer() 680 { 681 return peer; 682 } 683 684 public String toString() 685 { 686 StringBuffer str = new StringBuffer (); 687 str.append("RQueryUser:\n"); 688 str.append("QueryId = ") 689 .append(getQueryId()) 690 .append("\n"); 691 str.append("UserId = ") 692 .append(getUserId()) 693 .append("\n"); 694 str.append("IsSubscribed = ") 695 .append(getIsSubscribed()) 696 .append("\n"); 697 str.append("SubscriptionFrequency = ") 698 .append(getSubscriptionFrequency()) 699 .append("\n"); 700 str.append("Isdefault = ") 701 .append(getIsdefault()) 702 .append("\n"); 703 return(str.toString()); 704 } 705 } 706 | Popular Tags |