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.NumberKey;
14 import org.apache.torque.om.ObjectKey;
15 import org.apache.torque.om.SimpleKey;
16 import org.apache.torque.util.Criteria;
17 import org.apache.torque.util.Transaction;
18
19
20
21 /***
22 * This class was autogenerated by Torque on:
23 *
24 * [Tue Jul 13 14:47:47 CEST 2004]
25 *
26 * You should not use this class directly. It should not even be
27 * extended all references should be to RdfLiteral
28 */
29 public abstract class BaseRdfLiteral extends BaseObject
30 {
31 /*** The Peer class */
32 private static final RdfLiteralPeer peer =
33 new RdfLiteralPeer();
34
35
36 /*** The value for the id field */
37 private int id;
38
39 /*** The value for the literal field */
40 private String literal;
41
42 /*** The value for the usr field */
43 private int usr;
44
45 /*** The value for the modified field */
46 private Date modified;
47
48 /*** The value for the garbage field */
49 private int garbage = 0;
50
51
52 /***
53 * Get the Id
54 *
55 * @return int
56 */
57 public int getId()
58 {
59 return id;
60 }
61
62
63 /***
64 * Set the value of Id
65 *
66 * @param v new value
67 */
68 public void setId(int v) throws TorqueException
69 {
70
71 if (this.id != v)
72 {
73 this.id = v;
74 setModified(true);
75 }
76
77
78
79
80 if (collRdfStatements != null)
81 {
82 for (int i = 0; i < collRdfStatements.size(); i++)
83 {
84 ((RdfStatement) collRdfStatements.get(i))
85 .setObjLiteral(v);
86 }
87 }
88 }
89
90 /***
91 * Get the Literal
92 *
93 * @return String
94 */
95 public String getLiteral()
96 {
97 return literal;
98 }
99
100
101 /***
102 * Set the value of Literal
103 *
104 * @param v new value
105 */
106 public void setLiteral(String v)
107 {
108
109 if (!ObjectUtils.equals(this.literal, v))
110 {
111 this.literal = v;
112 setModified(true);
113 }
114
115
116 }
117
118 /***
119 * Get the Usr
120 *
121 * @return int
122 */
123 public int getUsr()
124 {
125 return usr;
126 }
127
128
129 /***
130 * Set the value of Usr
131 *
132 * @param v new value
133 */
134 public void setUsr(int v) throws TorqueException
135 {
136
137 if (this.usr != v)
138 {
139 this.usr = v;
140 setModified(true);
141 }
142
143
144 if (aRdfUser != null && !(aRdfUser.getId() == v))
145 {
146 aRdfUser = null;
147 }
148
149 }
150
151 /***
152 * Get the Modified
153 *
154 * @return Date
155 */
156 public Date getModified()
157 {
158 return modified;
159 }
160
161
162 /***
163 * Set the value of Modified
164 *
165 * @param v new value
166 */
167 public void setModified(Date v)
168 {
169
170 if (!ObjectUtils.equals(this.modified, v))
171 {
172 this.modified = v;
173 setModified(true);
174 }
175
176
177 }
178
179 /***
180 * Get the Garbage
181 *
182 * @return int
183 */
184 public int getGarbage()
185 {
186 return garbage;
187 }
188
189
190 /***
191 * Set the value of Garbage
192 *
193 * @param v new value
194 */
195 public void setGarbage(int v)
196 {
197
198 if (this.garbage != v)
199 {
200 this.garbage = v;
201 setModified(true);
202 }
203
204
205 }
206
207
208
209
210
211 private RdfUser aRdfUser;
212
213 /***
214 * Declares an association between this object and a RdfUser object
215 *
216 * @param v RdfUser
217 * @throws TorqueException
218 */
219 public void setRdfUser(RdfUser v) throws TorqueException
220 {
221 if (v == null)
222 {
223 setUsr(0);
224 }
225 else
226 {
227 setUsr(v.getId());
228 }
229 aRdfUser = v;
230 }
231
232
233 /***
234 * Get the associated RdfUser object
235 *
236 * @return the associated RdfUser object
237 * @throws TorqueException
238 */
239 public RdfUser getRdfUser() throws TorqueException
240 {
241 if (aRdfUser == null && (this.usr > 0))
242 {
243 aRdfUser = RdfUserPeer.retrieveByPK(SimpleKey.keyFor(this.usr));
244
245
246
247
248
249
250
251
252
253
254 }
255 return aRdfUser;
256 }
257
258 /***
259 * Provides convenient way to set a relationship based on a
260 * ObjectKey. e.g.
261 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
262 *
263 */
264 public void setRdfUserKey(ObjectKey key) throws TorqueException
265 {
266
267 setUsr(((NumberKey) key).intValue());
268 }
269
270
271
272 /***
273 * Collection to store aggregation of collRdfStatements
274 */
275 protected List collRdfStatements;
276
277 /***
278 * Temporary storage of collRdfStatements to save a possible db hit in
279 * the event objects are add to the collection, but the
280 * complete collection is never requested.
281 */
282 protected void initRdfStatements()
283 {
284 if (collRdfStatements == null)
285 {
286 collRdfStatements = new ArrayList();
287 }
288 }
289
290 /***
291 * Method called to associate a RdfStatement object to this object
292 * through the RdfStatement foreign key attribute
293 *
294 * @param l RdfStatement
295 * @throws TorqueException
296 */
297 public void addRdfStatement(RdfStatement l) throws TorqueException
298 {
299 getRdfStatements().add(l);
300 l.setRdfLiteral((RdfLiteral) this);
301 }
302
303 /***
304 * The criteria used to select the current contents of collRdfStatements
305 */
306 private Criteria lastRdfStatementsCriteria = null;
307
308 /***
309 * If this collection has already been initialized, returns
310 * the collection. Otherwise returns the results of
311 * getRdfStatements(new Criteria())
312 *
313 * @throws TorqueException
314 */
315 public List getRdfStatements() throws TorqueException
316 {
317 if (collRdfStatements == null)
318 {
319 collRdfStatements = getRdfStatements(new Criteria(10));
320 }
321 return collRdfStatements;
322 }
323
324 /***
325 * If this collection has already been initialized with
326 * an identical criteria, it returns the collection.
327 * Otherwise if this RdfLiteral has previously
328 * been saved, it will retrieve related RdfStatements from storage.
329 * If this RdfLiteral is new, it will return
330 * an empty collection or the current collection, the criteria
331 * is ignored on a new object.
332 *
333 * @throws TorqueException
334 */
335 public List getRdfStatements(Criteria criteria) throws TorqueException
336 {
337 if (collRdfStatements == null)
338 {
339 if (isNew())
340 {
341 collRdfStatements = new ArrayList();
342 }
343 else
344 {
345 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId() );
346 collRdfStatements = RdfStatementPeer.doSelect(criteria);
347 }
348 }
349 else
350 {
351
352 if (!isNew())
353 {
354
355
356
357 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
358 if (!lastRdfStatementsCriteria.equals(criteria))
359 {
360 collRdfStatements = RdfStatementPeer.doSelect(criteria);
361 }
362 }
363 }
364 lastRdfStatementsCriteria = criteria;
365
366 return collRdfStatements;
367 }
368
369 /***
370 * If this collection has already been initialized, returns
371 * the collection. Otherwise returns the results of
372 * getRdfStatements(new Criteria(),Connection)
373 * This method takes in the Connection also as input so that
374 * referenced objects can also be obtained using a Connection
375 * that is taken as input
376 */
377 public List getRdfStatements(Connection con) throws TorqueException
378 {
379 if (collRdfStatements == null)
380 {
381 collRdfStatements = getRdfStatements(new Criteria(10), con);
382 }
383 return collRdfStatements;
384 }
385
386 /***
387 * If this collection has already been initialized with
388 * an identical criteria, it returns the collection.
389 * Otherwise if this RdfLiteral has previously
390 * been saved, it will retrieve related RdfStatements from storage.
391 * If this RdfLiteral is new, it will return
392 * an empty collection or the current collection, the criteria
393 * is ignored on a new object.
394 * This method takes in the Connection also as input so that
395 * referenced objects can also be obtained using a Connection
396 * that is taken as input
397 */
398 public List getRdfStatements(Criteria criteria, Connection con)
399 throws TorqueException
400 {
401 if (collRdfStatements == null)
402 {
403 if (isNew())
404 {
405 collRdfStatements = new ArrayList();
406 }
407 else
408 {
409 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
410 collRdfStatements = RdfStatementPeer.doSelect(criteria, con);
411 }
412 }
413 else
414 {
415
416 if (!isNew())
417 {
418
419
420
421 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
422 if (!lastRdfStatementsCriteria.equals(criteria))
423 {
424 collRdfStatements = RdfStatementPeer.doSelect(criteria, con);
425 }
426 }
427 }
428 lastRdfStatementsCriteria = criteria;
429
430 return collRdfStatements;
431 }
432
433
434
435
436
437
438
439
440
441
442
443 /***
444 * If this collection has already been initialized with
445 * an identical criteria, it returns the collection.
446 * Otherwise if this RdfLiteral is new, it will return
447 * an empty collection; or if this RdfLiteral has previously
448 * been saved, it will retrieve related RdfStatements from storage.
449 *
450 * This method is protected by default in order to keep the public
451 * api reasonable. You can provide public methods for those you
452 * actually need in RdfLiteral.
453 */
454 protected List getRdfStatementsJoinRdfUser(Criteria criteria)
455 throws TorqueException
456 {
457 if (collRdfStatements == null)
458 {
459 if (isNew())
460 {
461 collRdfStatements = new ArrayList();
462 }
463 else
464 {
465 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
466 collRdfStatements = RdfStatementPeer.doSelectJoinRdfUser(criteria);
467 }
468 }
469 else
470 {
471
472
473
474 boolean newCriteria = true;
475 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
476 if (!lastRdfStatementsCriteria.equals(criteria))
477 {
478 collRdfStatements = RdfStatementPeer.doSelectJoinRdfUser(criteria);
479 }
480 }
481 lastRdfStatementsCriteria = criteria;
482
483 return collRdfStatements;
484 }
485
486
487
488
489
490
491
492
493
494 /***
495 * If this collection has already been initialized with
496 * an identical criteria, it returns the collection.
497 * Otherwise if this RdfLiteral is new, it will return
498 * an empty collection; or if this RdfLiteral has previously
499 * been saved, it will retrieve related RdfStatements from storage.
500 *
501 * This method is protected by default in order to keep the public
502 * api reasonable. You can provide public methods for those you
503 * actually need in RdfLiteral.
504 */
505 protected List getRdfStatementsJoinRdfResourceRelatedByPredicate(Criteria criteria)
506 throws TorqueException
507 {
508 if (collRdfStatements == null)
509 {
510 if (isNew())
511 {
512 collRdfStatements = new ArrayList();
513 }
514 else
515 {
516 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
517 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedByPredicate(criteria);
518 }
519 }
520 else
521 {
522
523
524
525 boolean newCriteria = true;
526 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
527 if (!lastRdfStatementsCriteria.equals(criteria))
528 {
529 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedByPredicate(criteria);
530 }
531 }
532 lastRdfStatementsCriteria = criteria;
533
534 return collRdfStatements;
535 }
536
537
538
539
540
541
542
543
544
545 /***
546 * If this collection has already been initialized with
547 * an identical criteria, it returns the collection.
548 * Otherwise if this RdfLiteral is new, it will return
549 * an empty collection; or if this RdfLiteral has previously
550 * been saved, it will retrieve related RdfStatements from storage.
551 *
552 * This method is protected by default in order to keep the public
553 * api reasonable. You can provide public methods for those you
554 * actually need in RdfLiteral.
555 */
556 protected List getRdfStatementsJoinRdfResourceRelatedByObjResource(Criteria criteria)
557 throws TorqueException
558 {
559 if (collRdfStatements == null)
560 {
561 if (isNew())
562 {
563 collRdfStatements = new ArrayList();
564 }
565 else
566 {
567 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
568 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedByObjResource(criteria);
569 }
570 }
571 else
572 {
573
574
575
576 boolean newCriteria = true;
577 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
578 if (!lastRdfStatementsCriteria.equals(criteria))
579 {
580 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedByObjResource(criteria);
581 }
582 }
583 lastRdfStatementsCriteria = criteria;
584
585 return collRdfStatements;
586 }
587
588
589
590
591
592
593
594
595
596 /***
597 * If this collection has already been initialized with
598 * an identical criteria, it returns the collection.
599 * Otherwise if this RdfLiteral is new, it will return
600 * an empty collection; or if this RdfLiteral has previously
601 * been saved, it will retrieve related RdfStatements from storage.
602 *
603 * This method is protected by default in order to keep the public
604 * api reasonable. You can provide public methods for those you
605 * actually need in RdfLiteral.
606 */
607 protected List getRdfStatementsJoinRdfResourceRelatedBySubject(Criteria criteria)
608 throws TorqueException
609 {
610 if (collRdfStatements == null)
611 {
612 if (isNew())
613 {
614 collRdfStatements = new ArrayList();
615 }
616 else
617 {
618 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
619 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedBySubject(criteria);
620 }
621 }
622 else
623 {
624
625
626
627 boolean newCriteria = true;
628 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
629 if (!lastRdfStatementsCriteria.equals(criteria))
630 {
631 collRdfStatements = RdfStatementPeer.doSelectJoinRdfResourceRelatedBySubject(criteria);
632 }
633 }
634 lastRdfStatementsCriteria = criteria;
635
636 return collRdfStatements;
637 }
638
639
640
641
642
643
644
645
646
647 /***
648 * If this collection has already been initialized with
649 * an identical criteria, it returns the collection.
650 * Otherwise if this RdfLiteral is new, it will return
651 * an empty collection; or if this RdfLiteral has previously
652 * been saved, it will retrieve related RdfStatements from storage.
653 *
654 * This method is protected by default in order to keep the public
655 * api reasonable. You can provide public methods for those you
656 * actually need in RdfLiteral.
657 */
658 protected List getRdfStatementsJoinRdfLiteral(Criteria criteria)
659 throws TorqueException
660 {
661 if (collRdfStatements == null)
662 {
663 if (isNew())
664 {
665 collRdfStatements = new ArrayList();
666 }
667 else
668 {
669 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
670 collRdfStatements = RdfStatementPeer.doSelectJoinRdfLiteral(criteria);
671 }
672 }
673 else
674 {
675
676
677
678 boolean newCriteria = true;
679 criteria.add(RdfStatementPeer.OBJ_LITERAL, getId());
680 if (!lastRdfStatementsCriteria.equals(criteria))
681 {
682 collRdfStatements = RdfStatementPeer.doSelectJoinRdfLiteral(criteria);
683 }
684 }
685 lastRdfStatementsCriteria = criteria;
686
687 return collRdfStatements;
688 }
689
690
691
692
693 private static List fieldNames = null;
694
695 /***
696 * Generate a list of field names.
697 *
698 * @return a list of field names
699 */
700 public static synchronized List getFieldNames()
701 {
702 if (fieldNames == null)
703 {
704 fieldNames = new ArrayList();
705 fieldNames.add("Id");
706 fieldNames.add("Literal");
707 fieldNames.add("Usr");
708 fieldNames.add("Modified");
709 fieldNames.add("Garbage");
710 fieldNames = Collections.unmodifiableList(fieldNames);
711 }
712 return fieldNames;
713 }
714
715 /***
716 * Retrieves a field from the object by name passed in as a String.
717 *
718 * @param name field name
719 * @return value
720 */
721 public Object getByName(String name)
722 {
723 if (name.equals("Id"))
724 {
725 return new Integer(getId());
726 }
727 if (name.equals("Literal"))
728 {
729 return getLiteral();
730 }
731 if (name.equals("Usr"))
732 {
733 return new Integer(getUsr());
734 }
735 if (name.equals("Modified"))
736 {
737 return getModified();
738 }
739 if (name.equals("Garbage"))
740 {
741 return new Integer(getGarbage());
742 }
743 return null;
744 }
745
746 /***
747 * Retrieves a field from the object by name passed in
748 * as a String. The String must be one of the static
749 * Strings defined in this Class' Peer.
750 *
751 * @param name peer name
752 * @return value
753 */
754 public Object getByPeerName(String name)
755 {
756 if (name.equals(RdfLiteralPeer.ID))
757 {
758 return new Integer(getId());
759 }
760 if (name.equals(RdfLiteralPeer.LITERAL))
761 {
762 return getLiteral();
763 }
764 if (name.equals(RdfLiteralPeer.USR))
765 {
766 return new Integer(getUsr());
767 }
768 if (name.equals(RdfLiteralPeer.MODIFIED))
769 {
770 return getModified();
771 }
772 if (name.equals(RdfLiteralPeer.GARBAGE))
773 {
774 return new Integer(getGarbage());
775 }
776 return null;
777 }
778
779 /***
780 * Retrieves a field from the object by Position as specified
781 * in the xml schema. Zero-based.
782 *
783 * @param pos position in xml schema
784 * @return value
785 */
786 public Object getByPosition(int pos)
787 {
788 if (pos == 0)
789 {
790 return new Integer(getId());
791 }
792 if (pos == 1)
793 {
794 return getLiteral();
795 }
796 if (pos == 2)
797 {
798 return new Integer(getUsr());
799 }
800 if (pos == 3)
801 {
802 return getModified();
803 }
804 if (pos == 4)
805 {
806 return new Integer(getGarbage());
807 }
808 return null;
809 }
810
811 /***
812 * Stores the object in the database. If the object is new,
813 * it inserts it; otherwise an update is performed.
814 *
815 * @throws Exception
816 */
817 public void save() throws Exception
818 {
819 save(RdfLiteralPeer.getMapBuilder()
820 .getDatabaseMap().getName());
821 }
822
823 /***
824 * Stores the object in the database. If the object is new,
825 * it inserts it; otherwise an update is performed.
826 * Note: this code is here because the method body is
827 * auto-generated conditionally and therefore needs to be
828 * in this file instead of in the super class, BaseObject.
829 *
830 * @param dbName
831 * @throws TorqueException
832 */
833 public void save(String dbName) throws TorqueException
834 {
835 Connection con = null;
836 try
837 {
838 con = Transaction.begin(dbName);
839 save(con);
840 Transaction.commit(con);
841 }
842 catch(TorqueException e)
843 {
844 Transaction.safeRollback(con);
845 throw e;
846 }
847 }
848
849 /*** flag to prevent endless save loop, if this object is referenced
850 by another object which falls in this transaction. */
851 private boolean alreadyInSave = false;
852 /***
853 * Stores the object in the database. If the object is new,
854 * it inserts it; otherwise an update is performed. This method
855 * is meant to be used as part of a transaction, otherwise use
856 * the save() method and the connection details will be handled
857 * internally
858 *
859 * @param con
860 * @throws TorqueException
861 */
862 public void save(Connection con) throws TorqueException
863 {
864 if (!alreadyInSave)
865 {
866 alreadyInSave = true;
867
868
869
870
871 if (isModified())
872 {
873 if (isNew())
874 {
875 RdfLiteralPeer.doInsert((RdfLiteral) this, con);
876 setNew(false);
877 }
878 else
879 {
880 RdfLiteralPeer.doUpdate((RdfLiteral) this, con);
881 }
882 }
883
884
885
886 if (collRdfStatements != null)
887 {
888 for (int i = 0; i < collRdfStatements.size(); i++)
889 {
890 ((RdfStatement) collRdfStatements.get(i)).save(con);
891 }
892 }
893 alreadyInSave = false;
894 }
895 }
896
897
898
899 /***
900 * Set the PrimaryKey using ObjectKey.
901 *
902 * @param id ObjectKey
903 */
904 public void setPrimaryKey(ObjectKey key)
905 throws TorqueException
906 {
907 setId(((NumberKey) key).intValue());
908 }
909
910 /***
911 * Set the PrimaryKey using a String.
912 *
913 * @param key
914 */
915 public void setPrimaryKey(String key) throws TorqueException
916 {
917 setId(Integer.parseInt(key));
918 }
919
920
921 /***
922 * returns an id that differentiates this object from others
923 * of its class.
924 */
925 public ObjectKey getPrimaryKey()
926 {
927 return SimpleKey.keyFor(getId());
928 }
929
930
931
932 /***
933 * Makes a copy of this object.
934 * It creates a new object filling in the simple attributes.
935 * It then fills all the association collections and sets the
936 * related objects to isNew=true.
937 */
938 public RdfLiteral copy() throws TorqueException
939 {
940 return copyInto(new RdfLiteral());
941 }
942
943 protected RdfLiteral copyInto(RdfLiteral copyObj) throws TorqueException
944 {
945 copyObj.setId(id);
946 copyObj.setLiteral(literal);
947 copyObj.setUsr(usr);
948 copyObj.setModified(modified);
949 copyObj.setGarbage(garbage);
950
951 copyObj.setId(0);
952
953
954
955 List v = getRdfStatements();
956 for (int i = 0; i < v.size(); i++)
957 {
958 RdfStatement obj = (RdfStatement) v.get(i);
959 copyObj.addRdfStatement(obj.copy());
960 }
961
962 return copyObj;
963 }
964
965 /***
966 * returns a peer instance associated with this om. Since Peer classes
967 * are not to have any instance attributes, this method returns the
968 * same instance for all member of this class. The method could therefore
969 * be static, but this would prevent one from overriding the behavior.
970 */
971 public RdfLiteralPeer getPeer()
972 {
973 return peer;
974 }
975
976 public String toString()
977 {
978 StringBuffer str = new StringBuffer();
979 str.append("RdfLiteral:\n");
980 str.append("Id = ")
981 .append(getId())
982 .append("\n");
983 str.append("Literal = ")
984 .append(getLiteral())
985 .append("\n");
986 str.append("Usr = ")
987 .append(getUsr())
988 .append("\n");
989 str.append("Modified = ")
990 .append(getModified())
991 .append("\n");
992 str.append("Garbage = ")
993 .append(getGarbage())
994 .append("\n");
995 return(str.toString());
996 }
997 }