001: /*
002: Copyright (C) 2003-2006 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.training;
034:
035: import java.sql.SQLException;
036:
037: import java.util.Comparator;
038: import java.util.HashMap;
039:
040: import com.knowgate.jdc.JDCConnection;
041: import com.knowgate.dataobjs.DB;
042: import com.knowgate.dataobjs.DBPersist;
043: import com.knowgate.dataobjs.DBSubset;
044: import com.knowgate.crm.Contact;
045:
046: /**
047: * Actual attendant to an academic course
048: * @author Sergio Montoro Ten
049: * @version 1.0
050: */
051: public class AcademicCourseAlumni extends DBPersist implements
052: Comparator {
053:
054: public AcademicCourseAlumni() {
055: super (DB.k_x_course_alumni, "AcademicCourseAlumni");
056: }
057:
058: // ---------------------------------------------------------------------------
059:
060: public AcademicCourseAlumni(String sAcademicCourseId,
061: String sContactId) {
062: super (DB.k_x_course_alumni, "AcademicCourseAlumni");
063: put(DB.gu_acourse, sAcademicCourseId);
064: put(DB.gu_contact, sContactId);
065: }
066:
067: // ---------------------------------------------------------------------------
068:
069: public AcademicCourseAlumni(JDCConnection oConn,
070: String sAcademicCourseId, String sContactId)
071: throws SQLException {
072: super (DB.k_x_course_alumni, "AcademicCourseAlumni");
073: load(oConn, new Object[] { sAcademicCourseId, sContactId });
074: }
075:
076: // ---------------------------------------------------------------------------
077:
078: public int compare(Object o1, Object o2) {
079: return ((AcademicCourseAlumni) o1).getString(DB.gu_alumni)
080: .compareTo(
081: ((AcademicCourseAlumni) o2)
082: .getString(DB.gu_alumni));
083: }
084:
085: // ---------------------------------------------------------------------------
086:
087: public boolean equals(AcademicCourseAlumni o2) {
088: return getString(DB.gu_acourse).equals(
089: o2.getString(DB.gu_acourse))
090: && getString(DB.gu_alumni).equals(
091: o2.getString(DB.gu_alumni));
092: }
093:
094: // ---------------------------------------------------------------------------
095:
096: public Contact getContact(JDCConnection oConn) throws SQLException,
097: IllegalStateException {
098: if (isNull(DB.gu_alumni))
099: throw new IllegalStateException(
100: "AcademicCourseAlumni.getContact() gu_alumni not set");
101: return new Contact(oConn, getString(DB.gu_alumni));
102: }
103:
104: // ---------------------------------------------------------------------------
105:
106: public HashMap getEvaluations(JDCConnection oConn)
107: throws SQLException, IllegalStateException {
108:
109: if (isNull(DB.gu_acourse))
110: throw new IllegalStateException(
111: "AcademicCourseAlumni.getEvaluations() gu_acourse not set");
112: if (isNull(DB.gu_alumni))
113: throw new IllegalStateException(
114: "AcademicCourseAlumni.getEvaluations() gu_alumni not set");
115:
116: DBSubset oEvals = new DBSubset(DB.k_evaluations,
117: new Evaluation().getTable(oConn).getColumnsStr(),
118: DB.gu_alumni + "=? AND " + DB.gu_acourse + "=?", 20);
119: int nEvals = oEvals.load(oConn, new Object[] {
120: get(DB.gu_alumni), get(DB.gu_acourse) });
121: HashMap mEvals = new HashMap();
122: for (int e = 0; e < nEvals; e++) {
123: Evaluation oEval = new Evaluation();
124: oEval.putAll(oEvals.getRowAsMap(e));
125: mEvals.put(oEvals.getString(DB.gu_subject, e), oEval);
126: } // next
127: return mEvals;
128: } // getEvaluations
129:
130: // ---------------------------------------------------------------------------
131:
132: public AcademicCourseBooking getBooking(JDCConnection oConn)
133: throws SQLException, IllegalStateException {
134: if (isNull(DB.gu_acourse))
135: throw new IllegalStateException(
136: "AcademicCourseAlumni.getBooking() gu_acourse not set");
137: if (isNull(DB.gu_alumni))
138: throw new IllegalStateException(
139: "AcademicCourseAlumni.getBooking() gu_alumni not set");
140: return new AcademicCourseBooking(oConn,
141: getString(DB.gu_acourse), getString(DB.gu_contact));
142: }
143:
144: }
|