001: package com.knowgate.training;
002:
003: /*
004: Copyright (C) 2003-2005 Know Gate S.L. All rights reserved.
005: C/Oņa, 107 1š2 28050 Madrid (Spain)
006:
007: Redistribution and use in source and binary forms, with or without
008: modification, are permitted provided that the following conditions
009: are met:
010:
011: 1. Redistributions of source code must retain the above copyright
012: notice, this list of conditions and the following disclaimer.
013:
014: 2. The end-user documentation included with the redistribution,
015: if any, must include the following acknowledgment:
016: "This product includes software parts from hipergate
017: (http://www.hipergate.org/)."
018: Alternately, this acknowledgment may appear in the software itself,
019: if and wherever such third-party acknowledgments normally appear.
020:
021: 3. The name hipergate must not be used to endorse or promote products
022: derived from this software without prior written permission.
023: Products derived from this software may not be called hipergate,
024: nor may hipergate appear in their name, without prior written
025: permission.
026:
027: This library is distributed in the hope that it will be useful,
028: but WITHOUT ANY WARRANTY; without even the implied warranty of
029: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
030:
031: You should have received a copy of hipergate License with this code;
032: if not, visit http://www.hipergate.org or mail to info@hipergate.org
033: */
034:
035: import java.util.Date;
036: import java.sql.SQLException;
037: import java.sql.PreparedStatement;
038: import java.sql.CallableStatement;
039: import java.sql.ResultSet;
040:
041: import com.knowgate.debug.DebugFile;
042: import com.knowgate.jdc.JDCConnection;
043: import com.knowgate.dataobjs.DB;
044: import com.knowgate.dataobjs.DBPersist;
045:
046: import com.knowgate.misc.Gadgets;
047: import com.knowgate.dataobjs.DBSubset;
048:
049: /**
050: * @author Sergio Montoro Ten
051: * @version 2.2
052: */
053:
054: public class Course extends DBPersist {
055:
056: public Course() {
057: super (DB.k_courses, "Course");
058: }
059:
060: public Course(JDCConnection oConn, String sGuCourse)
061: throws SQLException {
062: super (DB.k_courses, "Course");
063: load(oConn, new Object[] { sGuCourse });
064: }
065:
066: // ---------------------------------------------------------------------------
067:
068: public boolean active() {
069: boolean bRetVal;
070: if (isNull(DB.bo_active))
071: bRetVal = false;
072: else
073: bRetVal = (getShort(DB.bo_active) == (short) 1);
074: return bRetVal;
075: } // active
076:
077: // ---------------------------------------------------------------------------
078:
079: public boolean store(JDCConnection oConn) throws SQLException {
080: if (!AllVals.containsKey(DB.dt_modified))
081: AllVals.put(DB.dt_modified, new Date());
082: if (!AllVals.containsKey(DB.gu_course))
083: AllVals.put(DB.gu_course, Gadgets.generateUUID());
084: return super .store(oConn);
085: }
086:
087: // ---------------------------------------------------------------------------
088:
089: public boolean delete(JDCConnection oConn) throws SQLException {
090: return Course.delete(oConn, getString(DB.gu_course));
091: }
092:
093: // ---------------------------------------------------------------------------
094:
095: public AcademicCourse[] getAcademicCourses(JDCConnection oConn)
096: throws SQLException {
097: AcademicCourse[] aACrss = null;
098: DBSubset oACrss = new DBSubset(DB.k_academic_courses,
099: new AcademicCourse().getTable(oConn).getColumnsStr(),
100: DB.gu_course + "=? ORDER BY " + DB.dt_created, 10);
101: int nACrss = oACrss.load(oConn,
102: new Object[] { get(DB.gu_course) });
103: if (nACrss > 0) {
104: aACrss = new AcademicCourse[nACrss];
105: for (int a = 0; a < nACrss; a++) {
106: aACrss[a] = new AcademicCourse();
107: aACrss[a].putAll(oACrss.getRowAsMap(a));
108: } // next
109: } // fi
110: return aACrss;
111: } // getAcademicCourses
112:
113: // ---------------------------------------------------------------------------
114:
115: public Subject[] getSubjects(JDCConnection oConn)
116: throws SQLException {
117: Subject[] aSubjs = null;
118: DBSubset oSubjs = new DBSubset(DB.k_subjects, new Subject()
119: .getTable(oConn).getColumnsStr(), DB.gu_workarea
120: + "=? AND " + DB.gu_course + "=? ORDER BY "
121: + DB.nm_subject, 50);
122: int nSubjs = oSubjs.load(oConn, new Object[] {
123: get(DB.gu_workarea), get(DB.gu_course) });
124: if (nSubjs > 0) {
125: aSubjs = new Subject[nSubjs];
126: for (int s = 0; s < nSubjs; s++) {
127: aSubjs[s] = new Subject();
128: aSubjs[s].putAll(oSubjs.getRowAsMap(s));
129: } // next
130: } // fi
131: return aSubjs;
132: } // getSubjects
133:
134: // ---------------------------------------------------------------------------
135:
136: public static boolean delete(JDCConnection oConn, String sGuCourse)
137: throws SQLException {
138: if (DebugFile.trace) {
139: DebugFile.writeln("Begin Course.delete([JDCConnection],"
140: + sGuCourse + ")");
141: DebugFile.incIdent();
142: }
143: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
144: if (DebugFile.trace)
145: DebugFile
146: .writeln("Connection.prepareStatement(SELECT k_sp_del_course('"
147: + sGuCourse + "'))");
148: PreparedStatement oStmt = oConn
149: .prepareStatement("SELECT k_sp_del_course(?)");
150: oStmt.setString(1, sGuCourse);
151: oStmt.executeQuery();
152: oStmt.close();
153: } else {
154: if (DebugFile.trace)
155: DebugFile
156: .writeln("Connection.prepareCall({ call k_sp_del_course('"
157: + sGuCourse + "') })");
158: CallableStatement oCall = oConn
159: .prepareCall("{ call k_sp_del_course(?) }");
160: oCall.setString(1, sGuCourse);
161: oCall.execute();
162: oCall.close();
163: }
164: if (DebugFile.trace) {
165: DebugFile.decIdent();
166: DebugFile.writeln("End Course.delete()");
167: }
168: return true;
169: }
170:
171: // **********************************************************
172: // Public Constants
173:
174: public static final short ClassId = 60;
175:
176: }
|