KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > training > AcademicCourseAlumni


1 /*
2   Copyright (C) 2003-2006 Know Gate S.L. All rights reserved.
3                            C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.training;
34
35 import java.sql.SQLException JavaDoc;
36
37 import java.util.Comparator JavaDoc;
38 import java.util.HashMap JavaDoc;
39
40 import com.knowgate.jdc.JDCConnection;
41 import com.knowgate.dataobjs.DB;
42 import com.knowgate.dataobjs.DBPersist;
43 import com.knowgate.dataobjs.DBSubset;
44 import com.knowgate.crm.Contact;
45
46 /**
47  * Actual attendant to an academic course
48  * @author Sergio Montoro Ten
49  * @version 1.0
50  */

51 public class AcademicCourseAlumni extends DBPersist implements Comparator JavaDoc {
52
53   public AcademicCourseAlumni() {
54     super(DB.k_x_course_alumni, "AcademicCourseAlumni");
55   }
56
57   // ---------------------------------------------------------------------------
58

59   public AcademicCourseAlumni(String JavaDoc sAcademicCourseId, String JavaDoc sContactId) {
60     super(DB.k_x_course_alumni, "AcademicCourseAlumni");
61     put (DB.gu_acourse, sAcademicCourseId);
62     put (DB.gu_contact, sContactId);
63   }
64
65   // ---------------------------------------------------------------------------
66

67   public AcademicCourseAlumni(JDCConnection oConn,
68                                String JavaDoc sAcademicCourseId, String JavaDoc sContactId)
69     throws SQLException JavaDoc {
70     super(DB.k_x_course_alumni, "AcademicCourseAlumni");
71     load(oConn, new Object JavaDoc[]{sAcademicCourseId, sContactId});
72   }
73
74   // ---------------------------------------------------------------------------
75

76   public int compare(Object JavaDoc o1, Object JavaDoc o2) {
77     return ((AcademicCourseAlumni)o1).getString(DB.gu_alumni).compareTo(((AcademicCourseAlumni)o2).getString(DB.gu_alumni));
78   }
79
80   // ---------------------------------------------------------------------------
81

82   public boolean equals(AcademicCourseAlumni o2) {
83     return getString(DB.gu_acourse).equals(o2.getString(DB.gu_acourse)) && getString(DB.gu_alumni).equals(o2.getString(DB.gu_alumni));
84   }
85
86   // ---------------------------------------------------------------------------
87

88   public Contact getContact(JDCConnection oConn)
89     throws SQLException JavaDoc, IllegalStateException JavaDoc {
90     if (isNull(DB.gu_alumni))
91       throw new IllegalStateException JavaDoc("AcademicCourseAlumni.getContact() gu_alumni not set");
92     return new Contact(oConn, getString(DB.gu_alumni));
93   }
94
95   // ---------------------------------------------------------------------------
96

97   public HashMap JavaDoc getEvaluations(JDCConnection oConn)
98     throws SQLException JavaDoc, IllegalStateException JavaDoc {
99
100   if (isNull(DB.gu_acourse))
101     throw new IllegalStateException JavaDoc("AcademicCourseAlumni.getEvaluations() gu_acourse not set");
102     if (isNull(DB.gu_alumni))
103       throw new IllegalStateException JavaDoc("AcademicCourseAlumni.getEvaluations() gu_alumni not set");
104
105
106     DBSubset oEvals = new DBSubset(DB.k_evaluations,
107                                    new Evaluation().getTable(oConn).getColumnsStr(),
108                                    DB.gu_alumni+"=? AND "+DB.gu_acourse+"=?", 20);
109     int nEvals = oEvals.load(oConn, new Object JavaDoc[]{get(DB.gu_alumni),get(DB.gu_acourse)});
110     HashMap JavaDoc mEvals = new HashMap JavaDoc();
111     for (int e=0; e<nEvals; e++) {
112       Evaluation oEval = new Evaluation();
113       oEval.putAll(oEvals.getRowAsMap(e));
114       mEvals.put(oEvals.getString(DB.gu_subject, e), oEval);
115     } // next
116
return mEvals;
117   } // getEvaluations
118

119   // ---------------------------------------------------------------------------
120

121   public AcademicCourseBooking getBooking(JDCConnection oConn)
122     throws SQLException JavaDoc, IllegalStateException JavaDoc {
123   if (isNull(DB.gu_acourse))
124     throw new IllegalStateException JavaDoc("AcademicCourseAlumni.getBooking() gu_acourse not set");
125     if (isNull(DB.gu_alumni))
126       throw new IllegalStateException JavaDoc("AcademicCourseAlumni.getBooking() gu_alumni not set");
127     return new AcademicCourseBooking(oConn, getString(DB.gu_acourse), getString(DB.gu_contact));
128   }
129
130 }
131
Popular Tags