KickJava   Java API By Example, From Geeks To Geeks.

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


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

32
33 package com.knowgate.training;
34
35 import java.sql.SQLException JavaDoc;
36 import java.sql.PreparedStatement JavaDoc;
37 import java.sql.ResultSet JavaDoc;
38
39 import java.math.BigDecimal JavaDoc;
40
41 import com.knowgate.jdc.JDCConnection;
42 import com.knowgate.dataobjs.DB;
43 import com.knowgate.dataobjs.DBPersist;
44 import com.knowgate.crm.Contact;
45
46 /**
47  * Booking for an academic course
48  * @author Sergio Montoro Ten
49  * @version 1.0
50  */

51 public class AcademicCourseBooking extends DBPersist {
52
53   public AcademicCourseBooking() {
54     super(DB.k_x_course_bookings, "AcademicCourseBooking");
55   }
56
57   // ---------------------------------------------------------------------------
58

59   public AcademicCourseBooking(String JavaDoc sAcademicCourseId, String JavaDoc sContactId) {
60     super(DB.k_x_course_bookings, "AcademicCourseBooking");
61     put (DB.gu_acourse, sAcademicCourseId);
62     put (DB.gu_contact, sContactId);
63   }
64
65   // ---------------------------------------------------------------------------
66

67   public AcademicCourseBooking(JDCConnection oConn,
68                                String JavaDoc sAcademicCourseId, String JavaDoc sContactId)
69     throws SQLException JavaDoc {
70     super(DB.k_x_course_bookings, "AcademicCourseBooking");
71     load(oConn, new Object JavaDoc[]{sAcademicCourseId, sContactId});
72   }
73
74   // ---------------------------------------------------------------------------
75

76   public boolean confirmed() {
77     boolean bRetVal;
78     if (isNull(DB.bo_confirmed))
79       bRetVal = false;
80     else
81       bRetVal = (getShort(DB.bo_confirmed)==(short) 1);
82     return bRetVal;
83   }
84
85   // ---------------------------------------------------------------------------
86

87   public boolean paid() {
88     boolean bRetVal;
89     if (isNull(DB.bo_paid))
90       bRetVal = false;
91     else
92       bRetVal = (getShort(DB.bo_paid)==(short) 1);
93     return bRetVal;
94   }
95
96   // ---------------------------------------------------------------------------
97

98   public BigDecimal JavaDoc amount() {
99     return getDecimal(DB.im_paid);
100   }
101
102   // ---------------------------------------------------------------------------
103

104   public boolean waiting() {
105     boolean bRetVal;
106     if (isNull(DB.bo_waiting))
107       bRetVal = false;
108     else
109       bRetVal = (getShort(DB.bo_waiting)==(short) 1);
110     return bRetVal;
111   }
112
113   // ---------------------------------------------------------------------------
114

115   public boolean canceled() {
116     boolean bRetVal;
117     if (isNull(DB.bo_canceled))
118       bRetVal = false;
119     else
120       bRetVal = (getShort(DB.bo_canceled)==(short) 1);
121     return bRetVal;
122   }
123
124   // ---------------------------------------------------------------------------
125

126   public AcademicCourseAlumni createAlumni(JDCConnection oConn)
127     throws SQLException JavaDoc {
128     AcademicCourseAlumni oAlmn = new AcademicCourseAlumni();
129     oAlmn.put(DB.gu_acourse, get(DB.gu_acourse));
130     oAlmn.put(DB.gu_alumni, get(DB.gu_contact));
131     if (!isNull(DB.tp_register))
132       oAlmn.put(DB.tp_register, get(DB.tp_register));
133     if (!isNull(DB.id_classroom))
134     oAlmn.put(DB.id_classroom, get(DB.id_classroom));
135     oAlmn.store(oConn);
136     return oAlmn;
137   } // createAlumni
138

139   // ---------------------------------------------------------------------------
140

141   public Contact getContact(JDCConnection oConn)
142     throws SQLException JavaDoc, IllegalStateException JavaDoc {
143     if (isNull(DB.gu_contact))
144       throw new IllegalStateException JavaDoc("AcademicCourseBooking.getContact() gu_contact not set");
145     return new Contact(oConn, getString(DB.gu_contact));
146   }
147
148   // ---------------------------------------------------------------------------
149

150   public AcademicCourseAlumni getAlumni(JDCConnection oConn)
151     throws SQLException JavaDoc, IllegalStateException JavaDoc {
152     if (isNull(DB.gu_acourse))
153       throw new IllegalStateException JavaDoc("AcademicCourseBooking.getAlumni() gu_acourse not set");
154     if (isNull(DB.gu_contact))
155       throw new IllegalStateException JavaDoc("AcademicCourseBooking.getAlumni() gu_contact not set");
156     return new AcademicCourseAlumni(oConn, getString(DB.gu_acourse), getString(DB.gu_contact));
157   }
158
159   // ---------------------------------------------------------------------------
160

161   public boolean isAlumni(JDCConnection oConn)
162     throws SQLException JavaDoc, IllegalStateException JavaDoc {
163     if (isNull(DB.gu_acourse))
164       throw new IllegalStateException JavaDoc("AcademicCourseBooking.getAlumni() gu_acourse not set");
165     if (isNull(DB.gu_contact))
166       throw new IllegalStateException JavaDoc("AcademicCourseBooking.getAlumni() gu_contact not set");
167     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT NULL FROM "+DB.k_x_course_alumni+" WHERE "+DB.gu_acourse+"=? AND "+DB.gu_alumni+"=?");
168     oStmt.setString(1, getString(DB.gu_acourse));
169     oStmt.setString(2, getString(DB.gu_contact));
170     ResultSet JavaDoc oRSet = oStmt.executeQuery();
171     boolean bIsAlumni = oRSet.next();
172     oRSet.close();
173     oStmt.close();
174     return bIsAlumni;
175   } // isAlumni
176

177   // **********************************************************
178
// Public Constants
179

180   public static final short ClassId = 65;
181 }
182
Popular Tags