1 package com.knowgate.training; 2 3 34 35 import java.util.Date ; 36 import java.sql.SQLException ; 37 import java.sql.PreparedStatement ; 38 import java.sql.CallableStatement ; 39 import java.sql.ResultSet ; 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 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 sGuCourse) 61 throws SQLException { 62 super(DB.k_courses, "Course"); 63 load(oConn, new Object []{sGuCourse}); 64 } 65 66 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 } 77 79 public boolean store(JDCConnection oConn) throws SQLException { 80 if (!AllVals.containsKey(DB.dt_modified)) 81 AllVals.put(DB.dt_modified, new Date ()); 82 if (!AllVals.containsKey(DB.gu_course)) 83 AllVals.put(DB.gu_course, Gadgets.generateUUID()); 84 return super.store(oConn); 85 } 86 87 89 public boolean delete (JDCConnection oConn) throws SQLException { 90 return Course.delete(oConn, getString(DB.gu_course)); 91 } 92 93 95 public AcademicCourse[] getAcademicCourses(JDCConnection oConn) 96 throws SQLException { 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 []{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 } } return aACrss; 110 } 112 114 public Subject[] getSubjects(JDCConnection oConn) throws SQLException { 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 []{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 } } return aSubjs; 129 } 131 133 public static boolean delete (JDCConnection oConn, String sGuCourse) throws SQLException { 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 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 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 164 public static final short ClassId = 60; 165 166 } 167 | Popular Tags |