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