1 package org.apache.jetspeed.om.security.turbine;
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.torque.TorqueException;
13 import org.apache.torque.om.BaseObject;
14 import org.apache.torque.om.ComboKey;
15 import org.apache.torque.om.DateKey;
16 import org.apache.torque.om.NumberKey;
17 import org.apache.torque.om.ObjectKey;
18 import org.apache.torque.om.SimpleKey;
19 import org.apache.torque.om.StringKey;
20 import org.apache.torque.om.Persistent;
21 import org.apache.torque.util.Criteria;
22 import org.apache.torque.util.Transaction;
23
24
25
26
27
28 /***
29 * This class was autogenerated by Torque on:
30 *
31 * [Thu Apr 22 23:12:36 EDT 2004]
32 *
33 * You should not use this class directly. It should not even be
34 * extended all references should be to TurbineUserGroupRole
35 */
36 public abstract class BaseTurbineUserGroupRole extends BaseObject
37 {
38 /*** The Peer class */
39 private static final TurbineUserGroupRolePeer peer =
40 new TurbineUserGroupRolePeer();
41
42
43 /*** The value for the userId field */
44 private int userId;
45
46 /*** The value for the groupId field */
47 private int groupId;
48
49 /*** The value for the roleId field */
50 private int roleId;
51
52
53 /***
54 * Get the UserId
55 * @return int
56 */
57 public int getUserId()
58 {
59 return userId;
60 }
61
62
63 /***
64 * Set the value of UserId
65 */
66 public void setUserId(int v ) throws TorqueException
67 {
68
69 if (this.userId != v)
70 {
71 this.userId = v;
72 setModified(true);
73 }
74
75
76 if (aTurbineUser != null && !(aTurbineUser.getUserId() == v))
77 {
78 aTurbineUser = null;
79 }
80
81 }
82
83
84 /***
85 * Get the GroupId
86 * @return int
87 */
88 public int getGroupId()
89 {
90 return groupId;
91 }
92
93
94 /***
95 * Set the value of GroupId
96 */
97 public void setGroupId(int v ) throws TorqueException
98 {
99
100 if (this.groupId != v)
101 {
102 this.groupId = v;
103 setModified(true);
104 }
105
106
107 if (aTurbineGroup != null && !(aTurbineGroup.getGroupId() == v))
108 {
109 aTurbineGroup = null;
110 }
111
112 }
113
114
115 /***
116 * Get the RoleId
117 * @return int
118 */
119 public int getRoleId()
120 {
121 return roleId;
122 }
123
124
125 /***
126 * Set the value of RoleId
127 */
128 public void setRoleId(int v ) throws TorqueException
129 {
130
131 if (this.roleId != v)
132 {
133 this.roleId = v;
134 setModified(true);
135 }
136
137
138 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
139 {
140 aTurbineRole = null;
141 }
142
143 }
144
145
146
147
148
149 private TurbineUser aTurbineUser;
150
151 /***
152 * Declares an association between this object and a TurbineUser object
153 *
154 * @param TurbineUser v
155 */
156 public void setTurbineUser(TurbineUser v) throws TorqueException
157 {
158 if (v == null)
159 {
160 setUserId(0);
161 }
162 else
163 {
164 setUserId(v.getUserId());
165 }
166 aTurbineUser = v;
167 }
168
169
170 public TurbineUser getTurbineUser() throws TorqueException
171 {
172 if ( getUserId()>0 )
173 {
174 return TurbineUserManager.getInstance(SimpleKey.keyFor(getUserId()));
175 }
176 return aTurbineUser;
177 }
178
179 /***
180 * Provides convenient way to set a relationship based on a
181 * ObjectKey. e.g.
182 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
183 *
184 */
185 public void setTurbineUserKey(ObjectKey key) throws TorqueException
186 {
187
188 setUserId(((NumberKey) key).intValue());
189 }
190
191
192
193
194 private TurbineGroup aTurbineGroup;
195
196 /***
197 * Declares an association between this object and a TurbineGroup object
198 *
199 * @param TurbineGroup v
200 */
201 public void setTurbineGroup(TurbineGroup v) throws TorqueException
202 {
203 if (v == null)
204 {
205 setGroupId(0);
206 }
207 else
208 {
209 setGroupId(v.getGroupId());
210 }
211 aTurbineGroup = v;
212 }
213
214
215 public TurbineGroup getTurbineGroup() throws TorqueException
216 {
217 if ( getGroupId()>0 )
218 {
219 return TurbineGroupManager.getInstance(SimpleKey.keyFor(getGroupId()));
220 }
221 return aTurbineGroup;
222 }
223
224 /***
225 * Provides convenient way to set a relationship based on a
226 * ObjectKey. e.g.
227 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
228 *
229 */
230 public void setTurbineGroupKey(ObjectKey key) throws TorqueException
231 {
232
233 setGroupId(((NumberKey) key).intValue());
234 }
235
236
237
238
239 private TurbineRole aTurbineRole;
240
241 /***
242 * Declares an association between this object and a TurbineRole object
243 *
244 * @param TurbineRole v
245 */
246 public void setTurbineRole(TurbineRole v) throws TorqueException
247 {
248 if (v == null)
249 {
250 setRoleId(0);
251 }
252 else
253 {
254 setRoleId(v.getRoleId());
255 }
256 aTurbineRole = v;
257 }
258
259
260 public TurbineRole getTurbineRole() throws TorqueException
261 {
262 if ( getRoleId()>0 )
263 {
264 return TurbineRoleManager.getInstance(SimpleKey.keyFor(getRoleId()));
265 }
266 return aTurbineRole;
267 }
268
269 /***
270 * Provides convenient way to set a relationship based on a
271 * ObjectKey. e.g.
272 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
273 *
274 */
275 public void setTurbineRoleKey(ObjectKey key) throws TorqueException
276 {
277
278 setRoleId(((NumberKey) key).intValue());
279 }
280
281
282
283 private static List fieldNames = null;
284
285 /***
286 * Generate a list of field names.
287 */
288 public static synchronized List getFieldNames()
289 {
290 if (fieldNames == null)
291 {
292 fieldNames = new ArrayList();
293 fieldNames.add("UserId");
294 fieldNames.add("GroupId");
295 fieldNames.add("RoleId");
296 fieldNames = Collections.unmodifiableList(fieldNames);
297 }
298 return fieldNames;
299 }
300
301 /***
302 * Retrieves a field from the object by name passed in
303 * as a String.
304 */
305 public Object getByName(String name)
306 {
307 if (name.equals("UserId"))
308 {
309 return new Integer(getUserId());
310 }
311 if (name.equals("GroupId"))
312 {
313 return new Integer(getGroupId());
314 }
315 if (name.equals("RoleId"))
316 {
317 return new Integer(getRoleId());
318 }
319 return null;
320 }
321
322 /***
323 * Retrieves a field from the object by name passed in
324 * as a String. The String must be one of the static
325 * Strings defined in this Class' Peer.
326 */
327 public Object getByPeerName(String name)
328 {
329 if (name.equals(TurbineUserGroupRolePeer.USER_ID ))
330 {
331 return new Integer(getUserId());
332 }
333 if (name.equals(TurbineUserGroupRolePeer.GROUP_ID ))
334 {
335 return new Integer(getGroupId());
336 }
337 if (name.equals(TurbineUserGroupRolePeer.ROLE_ID ))
338 {
339 return new Integer(getRoleId());
340 }
341 return null;
342 }
343
344 /***
345 * Retrieves a field from the object by Position as specified
346 * in the xml schema. Zero-based.
347 */
348 public Object getByPosition(int pos)
349 {
350 if ( pos == 0 )
351 {
352 return new Integer(getUserId());
353 }
354 if ( pos == 1 )
355 {
356 return new Integer(getGroupId());
357 }
358 if ( pos == 2 )
359 {
360 return new Integer(getRoleId());
361 }
362 return null;
363 }
364
365 /***
366 * Stores the object in the database. If the object is new,
367 * it inserts it; otherwise an update is performed.
368 */
369 public void save() throws Exception
370 {
371 save(TurbineUserGroupRolePeer.getMapBuilder()
372 .getDatabaseMap().getName());
373 }
374
375 /***
376 * Stores the object in the database. If the object is new,
377 * it inserts it; otherwise an update is performed.
378 * Note: this code is here because the method body is
379 * auto-generated conditionally and therefore needs to be
380 * in this file instead of in the super class, BaseObject.
381 */
382 public void save(String dbName) throws TorqueException
383 {
384 Connection con = null;
385 try
386 {
387 con = Transaction.begin(dbName);
388 save(con);
389 Transaction.commit(con);
390 }
391 catch(TorqueException e)
392 {
393 Transaction.safeRollback(con);
394 throw e;
395 }
396 }
397
398 /*** flag to prevent endless save loop, if this object is referenced
399 by another object which falls in this transaction. */
400 private boolean alreadyInSave = false;
401 /***
402 * Stores the object in the database. If the object is new,
403 * it inserts it; otherwise an update is performed. This method
404 * is meant to be used as part of a transaction, otherwise use
405 * the save() method and the connection details will be handled
406 * internally
407 */
408 public void save(Connection con) throws TorqueException
409 {
410 if (!alreadyInSave)
411 {
412 alreadyInSave = true;
413
414
415
416
417 if (isModified())
418 {
419 if (isNew())
420 {
421 TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole)this, con);
422 setNew(false);
423 }
424 else
425 {
426 TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole)this, con);
427 }
428
429 if (isCacheOnSave())
430 {
431 TurbineUserGroupRoleManager.putInstance(this);
432 }
433 }
434
435 alreadyInSave = false;
436 }
437 }
438
439 /***
440 * Specify whether to cache the object after saving to the db.
441 * This method returns false
442 */
443 protected boolean isCacheOnSave()
444 {
445 return true;
446 }
447
448
449
450 private final SimpleKey[] pks = new SimpleKey[3];
451 private final ComboKey comboPK = new ComboKey(pks);
452 /***
453 * Set the PrimaryKey with an ObjectKey
454 */
455 public void setPrimaryKey(ObjectKey key) throws TorqueException
456 {
457 SimpleKey[] keys = (SimpleKey[]) key.getValue();
458 SimpleKey tmpKey = null;
459 setUserId(((NumberKey)keys[0]).intValue());
460 setGroupId(((NumberKey)keys[1]).intValue());
461 setRoleId(((NumberKey)keys[2]).intValue());
462 }
463
464 /***
465 * Set the PrimaryKey using SimpleKeys.
466 *
467 * @param int userId
468 * @param int groupId
469 * @param int roleId
470 */
471 public void setPrimaryKey( int userId, int groupId, int roleId)
472 throws TorqueException
473 {
474 setUserId(userId);
475 setGroupId(groupId);
476 setRoleId(roleId);
477 }
478
479 /***
480 * Set the PrimaryKey using a String.
481 */
482 public void setPrimaryKey(String key) throws TorqueException
483 {
484 setPrimaryKey(new ComboKey(key));
485 }
486
487 /***
488 * returns an id that differentiates this object from others
489 * of its class.
490 */
491 public ObjectKey getPrimaryKey()
492 {
493 pks[0] = SimpleKey.keyFor(getUserId());
494 pks[1] = SimpleKey.keyFor(getGroupId());
495 pks[2] = SimpleKey.keyFor(getRoleId());
496 return comboPK;
497 }
498
499
500 /***
501 * Makes a copy of this object.
502 * It creates a new object filling in the simple attributes.
503 * It then fills all the association collections.
504 */
505 public TurbineUserGroupRole copy() throws TorqueException
506 {
507 TurbineUserGroupRole copyObj = new TurbineUserGroupRole();
508 copyObj.setUserId(userId);
509 copyObj.setGroupId(groupId);
510 copyObj.setRoleId(roleId);
511
512 copyObj.setUserId(0);
513 copyObj.setGroupId(0);
514 copyObj.setRoleId(0);
515
516 return copyObj;
517 }
518
519 /***
520 * returns a peer instance associated with this om. Since Peer classes
521 * are not to have any instance attributes, this method returns the
522 * same instance for all member of this class. The method could therefore
523 * be static, but this would prevent one from overriding the behavior.
524 */
525 public TurbineUserGroupRolePeer getPeer()
526 {
527 return peer;
528 }
529 }