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