001: package org.tigris.scarab.om;
002:
003: import java.math.BigDecimal;
004: import java.sql.Connection;
005: import java.util.ArrayList;
006: import java.util.Collections;
007: import java.util.Date;
008: import java.util.List;
009:
010: import org.apache.commons.lang.ObjectUtils;
011: import org.apache.fulcrum.intake.Retrievable;
012: import org.apache.torque.TorqueException;
013: import org.apache.torque.om.BaseObject;
014: import org.apache.torque.om.ComboKey;
015: import org.apache.torque.om.DateKey;
016: import org.apache.torque.om.NumberKey;
017: import org.apache.torque.om.ObjectKey;
018: import org.apache.torque.om.SimpleKey;
019: import org.apache.torque.om.StringKey;
020: import org.apache.torque.om.Persistent;
021: import org.apache.torque.util.Criteria;
022: import org.apache.torque.util.Transaction;
023:
024: /**
025: * You should not use this class directly. It should not even be
026: * extended all references should be to UserPreference
027: */
028: public abstract class BaseUserPreference extends BaseObject implements
029: org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final UserPreferencePeer peer = new UserPreferencePeer();
032:
033: /** The value for the userId field */
034: private Integer userId;
035:
036: /** The value for the passwordExpire field */
037: private Date passwordExpire;
038:
039: /** The value for the enterIssueRedirect field */
040: private int enterIssueRedirect;
041:
042: /** The value for the homePage field */
043: private String homePage;
044:
045: /** The value for the locale field */
046: private String locale;
047:
048: /**
049: * Get the UserId
050: *
051: * @return Integer
052: */
053: public Integer getUserId() {
054: return userId;
055: }
056:
057: /**
058: * Set the value of UserId
059: *
060: * @param v new value
061: */
062: public void setUserId(Integer v) throws TorqueException {
063:
064: if (!ObjectUtils.equals(this .userId, v)) {
065: this .userId = v;
066: setModified(true);
067: }
068:
069: if (aScarabUser != null
070: && !ObjectUtils.equals(aScarabUser.getUserId(), v)) {
071: aScarabUser = null;
072: }
073:
074: }
075:
076: /**
077: * Get the PasswordExpire
078: *
079: * @return Date
080: */
081: public Date getPasswordExpire() {
082: return passwordExpire;
083: }
084:
085: /**
086: * Set the value of PasswordExpire
087: *
088: * @param v new value
089: */
090: public void setPasswordExpire(Date v) {
091:
092: if (!ObjectUtils.equals(this .passwordExpire, v)) {
093: this .passwordExpire = v;
094: setModified(true);
095: }
096:
097: }
098:
099: /**
100: * Get the EnterIssueRedirect
101: *
102: * @return int
103: */
104: public int getEnterIssueRedirect() {
105: return enterIssueRedirect;
106: }
107:
108: /**
109: * Set the value of EnterIssueRedirect
110: *
111: * @param v new value
112: */
113: public void setEnterIssueRedirect(int v) {
114:
115: if (this .enterIssueRedirect != v) {
116: this .enterIssueRedirect = v;
117: setModified(true);
118: }
119:
120: }
121:
122: /**
123: * Get the HomePage
124: *
125: * @return String
126: */
127: public String getHomePage() {
128: return homePage;
129: }
130:
131: /**
132: * Set the value of HomePage
133: *
134: * @param v new value
135: */
136: public void setHomePage(String v) {
137:
138: if (!ObjectUtils.equals(this .homePage, v)) {
139: this .homePage = v;
140: setModified(true);
141: }
142:
143: }
144:
145: /**
146: * Get the Locale
147: *
148: * @return String
149: */
150: public String getLocale() {
151: return locale;
152: }
153:
154: /**
155: * Set the value of Locale
156: *
157: * @param v new value
158: */
159: public void setLocale(String v) {
160:
161: if (!ObjectUtils.equals(this .locale, v)) {
162: this .locale = v;
163: setModified(true);
164: }
165:
166: }
167:
168: private ScarabUser aScarabUser;
169:
170: /**
171: * Declares an association between this object and a ScarabUser object
172: *
173: * @param v ScarabUser
174: * @throws TorqueException
175: */
176: public void setScarabUser(ScarabUser v) throws TorqueException {
177: if (v == null) {
178: setUserId((Integer) null);
179: } else {
180: setUserId(v.getUserId());
181: }
182: aScarabUser = v;
183: }
184:
185: /**
186: * Returns the associated ScarabUser object.
187: * If it was not retrieved before, the object is retrieved from
188: * the database
189: *
190: * @return the associated ScarabUser object
191: * @throws TorqueException
192: */
193: public ScarabUser getScarabUser() throws TorqueException {
194: if (aScarabUser == null
195: && (!ObjectUtils.equals(this .userId, null))) {
196: aScarabUser = ScarabUserManager.getInstance(SimpleKey
197: .keyFor(this .userId));
198: }
199: return aScarabUser;
200: }
201:
202: /**
203: * Return the associated ScarabUser object
204: * If it was not retrieved before, the object is retrieved from
205: * the database using the passed connection
206: *
207: * @param connection the connection used to retrieve the associated object
208: * from the database, if it was not retrieved before
209: * @return the associated ScarabUser object
210: * @throws TorqueException
211: */
212: public ScarabUser getScarabUser(Connection connection)
213: throws TorqueException {
214: if (aScarabUser == null
215: && (!ObjectUtils.equals(this .userId, null))) {
216: aScarabUser = ScarabUserManager.getCachedInstance(SimpleKey
217: .keyFor(this .userId));
218: if (aScarabUser == null) {
219: aScarabUser = ScarabUserImplPeer
220: .retrieveScarabUserImplByPK(SimpleKey
221: .keyFor(this .userId), connection);
222: ScarabUserManager.putInstance(aScarabUser);
223: }
224: }
225: return aScarabUser;
226: }
227:
228: /**
229: * Provides convenient way to set a relationship based on a
230: * ObjectKey, for example
231: * <code>bar.setFooKey(foo.getPrimaryKey())</code>
232: *
233: */
234: public void setScarabUserKey(ObjectKey key) throws TorqueException {
235:
236: setUserId(new Integer(((NumberKey) key).intValue()));
237: }
238:
239: private static List fieldNames = null;
240:
241: /**
242: * Generate a list of field names.
243: *
244: * @return a list of field names
245: */
246: public static synchronized List getFieldNames() {
247: if (fieldNames == null) {
248: fieldNames = new ArrayList();
249: fieldNames.add("UserId");
250: fieldNames.add("PasswordExpire");
251: fieldNames.add("EnterIssueRedirect");
252: fieldNames.add("HomePage");
253: fieldNames.add("Locale");
254: fieldNames = Collections.unmodifiableList(fieldNames);
255: }
256: return fieldNames;
257: }
258:
259: /**
260: * Retrieves a field from the object by name passed in as a String.
261: *
262: * @param name field name
263: * @return value
264: */
265: public Object getByName(String name) {
266: if (name.equals("UserId")) {
267: return getUserId();
268: }
269: if (name.equals("PasswordExpire")) {
270: return getPasswordExpire();
271: }
272: if (name.equals("EnterIssueRedirect")) {
273: return new Integer(getEnterIssueRedirect());
274: }
275: if (name.equals("HomePage")) {
276: return getHomePage();
277: }
278: if (name.equals("Locale")) {
279: return getLocale();
280: }
281: return null;
282: }
283:
284: /**
285: * Retrieves a field from the object by name passed in
286: * as a String. The String must be one of the static
287: * Strings defined in this Class' Peer.
288: *
289: * @param name peer name
290: * @return value
291: */
292: public Object getByPeerName(String name) {
293: if (name.equals(UserPreferencePeer.USER_ID)) {
294: return getUserId();
295: }
296: if (name.equals(UserPreferencePeer.PASSWORD_EXPIRE)) {
297: return getPasswordExpire();
298: }
299: if (name.equals(UserPreferencePeer.ENTER_ISSUE_REDIRECT)) {
300: return new Integer(getEnterIssueRedirect());
301: }
302: if (name.equals(UserPreferencePeer.HOME_PAGE)) {
303: return getHomePage();
304: }
305: if (name.equals(UserPreferencePeer.LOCALE)) {
306: return getLocale();
307: }
308: return null;
309: }
310:
311: /**
312: * Retrieves a field from the object by Position as specified
313: * in the xml schema. Zero-based.
314: *
315: * @param pos position in xml schema
316: * @return value
317: */
318: public Object getByPosition(int pos) {
319: if (pos == 0) {
320: return getUserId();
321: }
322: if (pos == 1) {
323: return getPasswordExpire();
324: }
325: if (pos == 2) {
326: return new Integer(getEnterIssueRedirect());
327: }
328: if (pos == 3) {
329: return getHomePage();
330: }
331: if (pos == 4) {
332: return getLocale();
333: }
334: return null;
335: }
336:
337: /**
338: * Stores the object in the database. If the object is new,
339: * it inserts it; otherwise an update is performed.
340: *
341: * @throws TorqueException
342: */
343: public void save() throws TorqueException {
344: save(UserPreferencePeer.getMapBuilder().getDatabaseMap()
345: .getName());
346: }
347:
348: /**
349: * Stores the object in the database. If the object is new,
350: * it inserts it; otherwise an update is performed.
351: * Note: this code is here because the method body is
352: * auto-generated conditionally and therefore needs to be
353: * in this file instead of in the super class, BaseObject.
354: *
355: * @param dbName
356: * @throws TorqueException
357: */
358: public void save(String dbName) throws TorqueException {
359: Connection con = null;
360: try {
361: con = Transaction.begin(dbName);
362: save(con);
363: Transaction.commit(con);
364: } catch (TorqueException e) {
365: Transaction.safeRollback(con);
366: throw e;
367: }
368: }
369:
370: /** flag to prevent endless save loop, if this object is referenced
371: by another object which falls in this transaction. */
372: private boolean alreadyInSave = false;
373:
374: /**
375: * Stores the object in the database. If the object is new,
376: * it inserts it; otherwise an update is performed. This method
377: * is meant to be used as part of a transaction, otherwise use
378: * the save() method and the connection details will be handled
379: * internally
380: *
381: * @param con
382: * @throws TorqueException
383: */
384: public void save(Connection con) throws TorqueException {
385: if (!alreadyInSave) {
386: alreadyInSave = true;
387:
388: // If this object has been modified, then save it to the database.
389: if (isModified()) {
390: if (isNew()) {
391: UserPreferencePeer.doInsert((UserPreference) this ,
392: con);
393: setNew(false);
394: } else {
395: UserPreferencePeer.doUpdate((UserPreference) this ,
396: con);
397: }
398:
399: if (isCacheOnSave()) {
400: UserPreferenceManager.putInstance(this );
401: }
402: }
403:
404: alreadyInSave = false;
405: }
406: }
407:
408: /**
409: * Specify whether to cache the object after saving to the db.
410: * This method returns true
411: */
412: protected boolean isCacheOnSave() {
413: return true;
414: }
415:
416: /**
417: * Set the PrimaryKey using ObjectKey.
418: *
419: * @param key userId ObjectKey
420: */
421: public void setPrimaryKey(ObjectKey key) throws TorqueException {
422: setUserId(new Integer(((NumberKey) key).intValue()));
423: }
424:
425: /**
426: * Set the PrimaryKey using a String.
427: *
428: * @param key
429: */
430: public void setPrimaryKey(String key) throws TorqueException {
431: setUserId(new Integer(key));
432: }
433:
434: /**
435: * returns an id that differentiates this object from others
436: * of its class.
437: */
438: public ObjectKey getPrimaryKey() {
439: return SimpleKey.keyFor(getUserId());
440: }
441:
442: /**
443: * get an id that differentiates this object from others
444: * of its class.
445: */
446: public String getQueryKey() {
447: if (getPrimaryKey() == null) {
448: return "";
449: } else {
450: return getPrimaryKey().toString();
451: }
452: }
453:
454: /**
455: * set an id that differentiates this object from others
456: * of its class.
457: */
458: public void setQueryKey(String key) throws TorqueException {
459: setPrimaryKey(key);
460: }
461:
462: /**
463: * Makes a copy of this object.
464: * It creates a new object filling in the simple attributes.
465: * It then fills all the association collections and sets the
466: * related objects to isNew=true.
467: */
468: public UserPreference copy() throws TorqueException {
469: return copyInto(new UserPreference());
470: }
471:
472: protected UserPreference copyInto(UserPreference copyObj)
473: throws TorqueException {
474: copyObj.setUserId(userId);
475: copyObj.setPasswordExpire(passwordExpire);
476: copyObj.setEnterIssueRedirect(enterIssueRedirect);
477: copyObj.setHomePage(homePage);
478: copyObj.setLocale(locale);
479:
480: copyObj.setUserId((Integer) null);
481:
482: return copyObj;
483: }
484:
485: /**
486: * returns a peer instance associated with this om. Since Peer classes
487: * are not to have any instance attributes, this method returns the
488: * same instance for all member of this class. The method could therefore
489: * be static, but this would prevent one from overriding the behavior.
490: */
491: public UserPreferencePeer getPeer() {
492: return peer;
493: }
494:
495: public String toString() {
496: StringBuffer str = new StringBuffer();
497: str.append("UserPreference:\n");
498: str.append("UserId = ").append(getUserId()).append("\n");
499: str.append("PasswordExpire = ").append(getPasswordExpire())
500: .append("\n");
501: str.append("EnterIssueRedirect = ").append(
502: getEnterIssueRedirect()).append("\n");
503: str.append("HomePage = ").append(getHomePage()).append("\n");
504: str.append("Locale = ").append(getLocale()).append("\n");
505: return (str.toString());
506: }
507: }
|