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