KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashMap JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.sql.PreparedStatement JavaDoc;
39 import java.sql.CallableStatement JavaDoc;
40 import java.sql.ResultSet JavaDoc;
41
42 import com.knowgate.debug.DebugFile;
43 import com.knowgate.jdc.JDCConnection;
44 import com.knowgate.dataobjs.DB;
45 import com.knowgate.dataobjs.DBPersist;
46
47 import com.knowgate.misc.Gadgets;
48
49 /**
50  * @author Sergio Montoro Ten
51  * @version 2.2
52  */

53
54 public class Subject extends DBPersist {
55
56   // ---------------------------------------------------------------------------
57

58   private class SubjectCourse extends DBPersist {
59     public SubjectCourse() {
60        super(DB.k_x_course_subject, "SubjectCourse");
61     }
62
63     public boolean store(JDCConnection oConn, HashMap JavaDoc oValues) throws SQLException JavaDoc {
64       boolean bRetVal;
65       if (DebugFile.trace) {
66         DebugFile.writeln("Begin SubjectCourse.store([JDCConnection],[HashMap])");
67         DebugFile.incIdent();
68       }
69       AllVals.putAll(oValues);
70       bRetVal = super.store(oConn);
71       if (DebugFile.trace) {
72         DebugFile.decIdent();
73         DebugFile.writeln("End SubjectCourse.store()");
74       }
75       return bRetVal;
76     }
77   } // SubjectCourse
78

79   // ---------------------------------------------------------------------------
80

81   public Subject() {
82      super(DB.k_subjects, "Subject");
83   }
84
85   // ---------------------------------------------------------------------------
86

87   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
88     boolean bRetVal;
89
90     if (DebugFile.trace) {
91       DebugFile.writeln("Begin Subject.store([JDCConnection])");
92       DebugFile.incIdent();
93     }
94
95     if (!AllVals.containsKey(DB.dt_modified))
96       AllVals.put(DB.dt_modified, new Date JavaDoc());
97     if (!AllVals.containsKey(DB.gu_subject))
98       AllVals.put(DB.gu_subject, Gadgets.generateUUID());
99     bRetVal = super.store(oConn);
100
101     if (AllVals.containsKey(DB.gu_course)) {
102       bRetVal = new SubjectCourse().store(oConn, AllVals);
103     }
104
105     if (DebugFile.trace) {
106       DebugFile.decIdent();
107       DebugFile.writeln("End Subject.store() : " + AllVals.get(DB.gu_subject));
108     }
109
110     return bRetVal;
111   } // store
112

113   // ---------------------------------------------------------------------------
114

115   public boolean delete (JDCConnection oConn) throws SQLException JavaDoc {
116     return Subject.delete(oConn, getString(DB.gu_acourse));
117   }
118
119   // ---------------------------------------------------------------------------
120

121   public static boolean delete (JDCConnection oConn, String JavaDoc sGuACourse) throws SQLException JavaDoc {
122     if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
123       PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT k_sp_del_subject(?)");
124       oStmt.setString(1, sGuACourse);
125       oStmt.executeQuery();
126       oStmt.close();
127     }
128     else {
129       CallableStatement JavaDoc oCall = oConn.prepareCall("{ call k_sp_del_subject(?) }");
130       oCall.setString(1, sGuACourse);
131       oCall.execute();
132       oCall.close();
133     }
134     return true;
135   }
136
137   // **********************************************************
138
// Public Constants
139

140   public static final short ClassId = 62;
141
142 }
143
Popular Tags