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.util.HashMap;
037: import java.sql.SQLException;
038: import java.sql.PreparedStatement;
039: import java.sql.CallableStatement;
040: import java.sql.ResultSet;
041:
042: import com.knowgate.debug.DebugFile;
043: import com.knowgate.jdc.JDCConnection;
044: import com.knowgate.dataobjs.DB;
045: import com.knowgate.dataobjs.DBPersist;
046:
047: import com.knowgate.misc.Gadgets;
048:
049: /**
050: * @author Sergio Montoro Ten
051: * @version 2.2
052: */
053:
054: public class Subject extends DBPersist {
055:
056: // ---------------------------------------------------------------------------
057:
058: private class SubjectCourse extends DBPersist {
059: public SubjectCourse() {
060: super (DB.k_x_course_subject, "SubjectCourse");
061: }
062:
063: public boolean store(JDCConnection oConn, HashMap oValues)
064: throws SQLException {
065: boolean bRetVal;
066: if (DebugFile.trace) {
067: DebugFile
068: .writeln("Begin SubjectCourse.store([JDCConnection],[HashMap])");
069: DebugFile.incIdent();
070: }
071: AllVals.putAll(oValues);
072: bRetVal = super .store(oConn);
073: if (DebugFile.trace) {
074: DebugFile.decIdent();
075: DebugFile.writeln("End SubjectCourse.store()");
076: }
077: return bRetVal;
078: }
079: } // SubjectCourse
080:
081: // ---------------------------------------------------------------------------
082:
083: public Subject() {
084: super (DB.k_subjects, "Subject");
085: }
086:
087: // ---------------------------------------------------------------------------
088:
089: public boolean store(JDCConnection oConn) throws SQLException {
090: boolean bRetVal;
091:
092: if (DebugFile.trace) {
093: DebugFile.writeln("Begin Subject.store([JDCConnection])");
094: DebugFile.incIdent();
095: }
096:
097: if (!AllVals.containsKey(DB.dt_modified))
098: AllVals.put(DB.dt_modified, new Date());
099: if (!AllVals.containsKey(DB.gu_subject))
100: AllVals.put(DB.gu_subject, Gadgets.generateUUID());
101: bRetVal = super .store(oConn);
102:
103: if (AllVals.containsKey(DB.gu_course)) {
104: bRetVal = new SubjectCourse().store(oConn, AllVals);
105: }
106:
107: if (DebugFile.trace) {
108: DebugFile.decIdent();
109: DebugFile.writeln("End Subject.store() : "
110: + AllVals.get(DB.gu_subject));
111: }
112:
113: return bRetVal;
114: } // store
115:
116: // ---------------------------------------------------------------------------
117:
118: public boolean delete(JDCConnection oConn) throws SQLException {
119: return Subject.delete(oConn, getString(DB.gu_acourse));
120: }
121:
122: // ---------------------------------------------------------------------------
123:
124: public static boolean delete(JDCConnection oConn, String sGuACourse)
125: throws SQLException {
126: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
127: PreparedStatement oStmt = oConn
128: .prepareStatement("SELECT k_sp_del_subject(?)");
129: oStmt.setString(1, sGuACourse);
130: oStmt.executeQuery();
131: oStmt.close();
132: } else {
133: CallableStatement oCall = oConn
134: .prepareCall("{ call k_sp_del_subject(?) }");
135: oCall.setString(1, sGuACourse);
136: oCall.execute();
137: oCall.close();
138: }
139: return true;
140: }
141:
142: // **********************************************************
143: // Public Constants
144:
145: public static final short ClassId = 62;
146:
147: }
|