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