KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 import java.util.Date JavaDoc;
36 import java.sql.SQLException JavaDoc;
37 import java.sql.PreparedStatement JavaDoc;
38 import java.sql.CallableStatement JavaDoc;
39 import java.sql.ResultSet JavaDoc;
40
41 import com.knowgate.debug.DebugFile;
42 import com.knowgate.jdc.JDCConnection;
43 import com.knowgate.dataobjs.DB;
44 import com.knowgate.dataobjs.DBPersist;
45
46 import com.knowgate.misc.Gadgets;
47 import com.knowgate.dataobjs.DBSubset;
48
49 /**
50  * @author Sergio Montoro Ten
51  * @version 2.2
52  */

53
54 public class Course extends DBPersist {
55
56   public Course() {
57      super(DB.k_courses, "Course");
58   }
59
60   public Course(JDCConnection oConn, String JavaDoc sGuCourse)
61     throws SQLException JavaDoc {
62     super(DB.k_courses, "Course");
63     load(oConn, new Object JavaDoc[]{sGuCourse});
64   }
65
66   // ---------------------------------------------------------------------------
67

68   public boolean active() {
69     boolean bRetVal;
70     if (isNull(DB.bo_active))
71       bRetVal = false;
72     else
73       bRetVal = (getShort(DB.bo_active)==(short) 1);
74     return bRetVal;
75   } // active
76

77   // ---------------------------------------------------------------------------
78

79   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
80     if (!AllVals.containsKey(DB.dt_modified))
81       AllVals.put(DB.dt_modified, new Date JavaDoc());
82     if (!AllVals.containsKey(DB.gu_course))
83       AllVals.put(DB.gu_course, Gadgets.generateUUID());
84     return super.store(oConn);
85   }
86
87   // ---------------------------------------------------------------------------
88

89   public boolean delete (JDCConnection oConn) throws SQLException JavaDoc {
90     return Course.delete(oConn, getString(DB.gu_course));
91   }
92
93   // ---------------------------------------------------------------------------
94

95   public AcademicCourse[] getAcademicCourses(JDCConnection oConn)
96     throws SQLException JavaDoc {
97     AcademicCourse[] aACrss = null;
98     DBSubset oACrss = new DBSubset(DB.k_academic_courses,
99                                    new AcademicCourse().getTable(oConn).getColumnsStr(),
100                                    DB.gu_course+"=? ORDER BY "+DB.dt_created,10);
101     int nACrss = oACrss.load(oConn, new Object JavaDoc[]{get(DB.gu_course)});
102     if (nACrss>0) {
103       aACrss = new AcademicCourse[nACrss];
104       for (int a=0; a<nACrss; a++) {
105         aACrss[a] = new AcademicCourse();
106         aACrss[a].putAll(oACrss.getRowAsMap(a));
107       } // next
108
} // fi
109
return aACrss;
110   } // getAcademicCourses
111

112   // ---------------------------------------------------------------------------
113

114   public Subject[] getSubjects(JDCConnection oConn) throws SQLException JavaDoc {
115     Subject[] aSubjs = null;
116     DBSubset oSubjs = new DBSubset(DB.k_subjects,
117                                    new Subject().getTable(oConn).getColumnsStr(),
118                                    DB.gu_workarea+"=? AND "+
119                                    DB.gu_course+"=? ORDER BY "+DB.nm_subject,50);
120     int nSubjs = oSubjs.load(oConn, new Object JavaDoc[]{get(DB.gu_workarea),get(DB.gu_course)});
121     if (nSubjs>0) {
122       aSubjs = new Subject[nSubjs];
123       for (int s=0; s<nSubjs; s++) {
124         aSubjs[s] = new Subject();
125         aSubjs[s].putAll(oSubjs.getRowAsMap(s));
126       } // next
127
} // fi
128
return aSubjs;
129   } // getSubjects
130

131   // ---------------------------------------------------------------------------
132

133   public static boolean delete (JDCConnection oConn, String JavaDoc sGuCourse) throws SQLException JavaDoc {
134     if (DebugFile.trace) {
135       DebugFile.writeln("Begin Course.delete([JDCConnection],"+sGuCourse+")");
136       DebugFile.incIdent();
137     }
138     if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
139       if (DebugFile.trace)
140         DebugFile.writeln("Connection.prepareStatement(SELECT k_sp_del_course('"+sGuCourse+"'))");
141       PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT k_sp_del_course(?)");
142       oStmt.setString(1, sGuCourse);
143       oStmt.executeQuery();
144       oStmt.close();
145     }
146     else {
147       if (DebugFile.trace)
148         DebugFile.writeln("Connection.prepareCall({ call k_sp_del_course('"+sGuCourse+"') })");
149       CallableStatement JavaDoc oCall = oConn.prepareCall("{ call k_sp_del_course(?) }");
150       oCall.setString(1, sGuCourse);
151       oCall.execute();
152       oCall.close();
153     }
154     if (DebugFile.trace) {
155       DebugFile.decIdent();
156       DebugFile.writeln("End Course.delete()");
157     }
158     return true;
159   }
160
161   // **********************************************************
162
// Public Constants
163

164   public static final short ClassId = 60;
165
166 }
167
Popular Tags