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 31 public abstract class BaseUserPreference extends BaseObject 32 implements org.apache.fulcrum.intake.Retrievable 33 { 34 35 private static final UserPreferencePeer peer = 36 new UserPreferencePeer(); 37 38 39 40 private Integer userId; 41 42 43 private Date passwordExpire; 44 45 46 private int enterIssueRedirect; 47 48 49 private String homePage; 50 51 52 private String locale; 53 54 55 60 public Integer getUserId() 61 { 62 return userId; 63 } 64 65 66 71 public void setUserId(Integer v) throws TorqueException 72 { 73 74 if (!ObjectUtils.equals(this.userId, v)) 75 { 76 this.userId = v; 77 setModified(true); 78 } 79 80 81 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v)) 82 { 83 aScarabUser = null; 84 } 85 86 } 87 88 93 public Date getPasswordExpire() 94 { 95 return passwordExpire; 96 } 97 98 99 104 public void setPasswordExpire(Date v) 105 { 106 107 if (!ObjectUtils.equals(this.passwordExpire, v)) 108 { 109 this.passwordExpire = v; 110 setModified(true); 111 } 112 113 114 } 115 116 121 public int getEnterIssueRedirect() 122 { 123 return enterIssueRedirect; 124 } 125 126 127 132 public void setEnterIssueRedirect(int v) 133 { 134 135 if (this.enterIssueRedirect != v) 136 { 137 this.enterIssueRedirect = v; 138 setModified(true); 139 } 140 141 142 } 143 144 149 public String getHomePage() 150 { 151 return homePage; 152 } 153 154 155 160 public void setHomePage(String v) 161 { 162 163 if (!ObjectUtils.equals(this.homePage, v)) 164 { 165 this.homePage = v; 166 setModified(true); 167 } 168 169 170 } 171 172 177 public String getLocale() 178 { 179 return locale; 180 } 181 182 183 188 public void setLocale(String v) 189 { 190 191 if (!ObjectUtils.equals(this.locale, v)) 192 { 193 this.locale = v; 194 setModified(true); 195 } 196 197 198 } 199 200 201 202 203 private ScarabUser aScarabUser; 204 205 211 public void setScarabUser(ScarabUser v) throws TorqueException 212 { 213 if (v == null) 214 { 215 setUserId((Integer ) null); 216 } 217 else 218 { 219 setUserId(v.getUserId()); 220 } 221 aScarabUser = v; 222 } 223 224 225 231 public ScarabUser getScarabUser() throws TorqueException 232 { 233 if ( !ObjectUtils.equals(getUserId(), null) ) 234 { 235 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId())); 236 } 237 return aScarabUser; 238 } 239 240 246 public void setScarabUserKey(ObjectKey key) throws TorqueException 247 { 248 249 setUserId(new Integer (((NumberKey) key).intValue())); 250 } 251 252 253 private static List fieldNames = null; 254 255 260 public static synchronized List getFieldNames() 261 { 262 if (fieldNames == null) 263 { 264 fieldNames = new ArrayList (); 265 fieldNames.add("UserId"); 266 fieldNames.add("PasswordExpire"); 267 fieldNames.add("EnterIssueRedirect"); 268 fieldNames.add("HomePage"); 269 fieldNames.add("Locale"); 270 fieldNames = Collections.unmodifiableList(fieldNames); 271 } 272 return fieldNames; 273 } 274 275 281 public Object getByName(String name) 282 { 283 if (name.equals("UserId")) 284 { 285 return getUserId(); 286 } 287 if (name.equals("PasswordExpire")) 288 { 289 return getPasswordExpire(); 290 } 291 if (name.equals("EnterIssueRedirect")) 292 { 293 return new Integer (getEnterIssueRedirect()); 294 } 295 if (name.equals("HomePage")) 296 { 297 return getHomePage(); 298 } 299 if (name.equals("Locale")) 300 { 301 return getLocale(); 302 } 303 return null; 304 } 305 306 314 public Object getByPeerName(String name) 315 { 316 if (name.equals(UserPreferencePeer.USER_ID)) 317 { 318 return getUserId(); 319 } 320 if (name.equals(UserPreferencePeer.PASSWORD_EXPIRE)) 321 { 322 return getPasswordExpire(); 323 } 324 if (name.equals(UserPreferencePeer.ENTER_ISSUE_REDIRECT)) 325 { 326 return new Integer (getEnterIssueRedirect()); 327 } 328 if (name.equals(UserPreferencePeer.HOME_PAGE)) 329 { 330 return getHomePage(); 331 } 332 if (name.equals(UserPreferencePeer.LOCALE)) 333 { 334 return getLocale(); 335 } 336 return null; 337 } 338 339 346 public Object getByPosition(int pos) 347 { 348 if (pos == 0) 349 { 350 return getUserId(); 351 } 352 if (pos == 1) 353 { 354 return getPasswordExpire(); 355 } 356 if (pos == 2) 357 { 358 return new Integer (getEnterIssueRedirect()); 359 } 360 if (pos == 3) 361 { 362 return getHomePage(); 363 } 364 if (pos == 4) 365 { 366 return getLocale(); 367 } 368 return null; 369 } 370 371 377 public void save() throws Exception 378 { 379 save(UserPreferencePeer.getMapBuilder() 380 .getDatabaseMap().getName()); 381 } 382 383 393 public void save(String dbName) throws TorqueException 394 { 395 Connection con = null; 396 try 397 { 398 con = Transaction.begin(dbName); 399 save(con); 400 Transaction.commit(con); 401 } 402 catch(TorqueException e) 403 { 404 Transaction.safeRollback(con); 405 throw e; 406 } 407 } 408 409 411 private boolean alreadyInSave = false; 412 422 public void save(Connection con) throws TorqueException 423 { 424 if (!alreadyInSave) 425 { 426 alreadyInSave = true; 427 428 429 430 if (isModified()) 432 { 433 if (isNew()) 434 { 435 UserPreferencePeer.doInsert((UserPreference)this, con); 436 setNew(false); 437 } 438 else 439 { 440 UserPreferencePeer.doUpdate((UserPreference)this, con); 441 } 442 443 if (isCacheOnSave()) 444 { 445 UserPreferenceManager.putInstance(this); 446 } 447 } 448 449 alreadyInSave = false; 450 } 451 } 452 453 457 protected boolean isCacheOnSave() 458 { 459 return true; 460 } 461 462 463 468 public void setPrimaryKey(ObjectKey userId) 469 throws TorqueException { 470 setUserId(new Integer (((NumberKey)userId).intValue())); 471 } 472 473 478 public void setPrimaryKey(String key) throws TorqueException 479 { 480 setUserId(new Integer (key)); 481 } 482 483 484 488 public ObjectKey getPrimaryKey() 489 { 490 return SimpleKey.keyFor(getUserId()); 491 } 492 493 497 public String getQueryKey() 498 { 499 if (getPrimaryKey() == null) 500 { 501 return ""; 502 } 503 else 504 { 505 return getPrimaryKey().toString(); 506 } 507 } 508 509 513 public void setQueryKey(String key) 514 throws TorqueException 515 { 516 setPrimaryKey(key); 517 } 518 519 525 public UserPreference copy() throws TorqueException 526 { 527 UserPreference copyObj = new UserPreference(); 528 copyObj.setUserId(userId); 529 copyObj.setPasswordExpire(passwordExpire); 530 copyObj.setEnterIssueRedirect(enterIssueRedirect); 531 copyObj.setHomePage(homePage); 532 copyObj.setLocale(locale); 533 534 copyObj.setUserId((Integer )null); 535 536 return copyObj; 537 } 538 539 545 public UserPreferencePeer getPeer() 546 { 547 return peer; 548 } 549 550 public String toString() 551 { 552 StringBuffer str = new StringBuffer (); 553 str.append("UserPreference:\n"); 554 str.append("UserId = ") 555 .append(getUserId()) 556 .append("\n"); 557 str.append("PasswordExpire = ") 558 .append(getPasswordExpire()) 559 .append("\n"); 560 str.append("EnterIssueRedirect = ") 561 .append(getEnterIssueRedirect()) 562 .append("\n"); 563 str.append("HomePage = ") 564 .append(getHomePage()) 565 .append("\n"); 566 str.append("Locale = ") 567 .append(getLocale()) 568 .append("\n"); 569 return(str.toString()); 570 } 571 } 572 | Popular Tags |