KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > examples > DAOMember


1 // Data Access Object
2

3
4 package Jt.examples;
5
6 import Jt.*;
7
8
9 import java.util.*;
10 import java.text.*;
11
12 public class DAOMember extends JtDAO {
13 private String JavaDoc email;
14 private String JavaDoc firstname;
15 private String JavaDoc lastname;
16 private int status;
17 private String JavaDoc subject;
18 private String JavaDoc comments;
19 private Date tstamp;
20 private int email_flag;
21 private Date mdate;
22 private String JavaDoc location;
23 private boolean initted = false;
24
25   public DAOMember() {
26   }
27
28   public void setEmail_flag (int newEmail_flag) {
29     email_flag = newEmail_flag;
30   }
31
32   public int getEmail_flag () {
33     return (email_flag);
34   }
35
36   public int getStatus () {
37     return (status);
38   }
39
40
41   public void setStatus (int newStatus) {
42     status = newStatus;
43   }
44
45   public String JavaDoc getEmail() {
46     return email;
47   }
48
49   public void setEmail (String JavaDoc newEmail) {
50     email = newEmail;
51   }
52
53   public String JavaDoc getSubject() {
54     return subject;
55   }
56
57   public void setSubject (String JavaDoc newSubject) {
58     subject = newSubject;
59   }
60
61   public String JavaDoc getComments() {
62     return comments;
63   }
64
65   public void setComments (String JavaDoc newComments) {
66     comments = newComments;
67   }
68
69   public void setFirstname (String JavaDoc newFirstname) {
70     firstname = newFirstname;
71   }
72
73   public String JavaDoc getFirstname() {
74     return firstname;
75   }
76
77   public void setLastname (String JavaDoc newLastname) {
78     lastname = newLastname;
79   }
80
81   public String JavaDoc getLastname() {
82     return lastname;
83   }
84
85
86   public void setTstamp (Date tstamp) {
87     this.tstamp = tstamp;
88   }
89
90   public Date getTstamp () {
91     return tstamp;
92   }
93
94   public void setMdate (Date mdate) {
95     this.mdate = mdate;
96   }
97
98   public Date getMdate () {
99     return mdate;
100   }
101
102   public String JavaDoc getLocation() {
103     return location;
104   }
105
106   public void setLocation (String JavaDoc location) {
107     this.location = location;
108   }
109
110
111   public void mapAttributes () {
112
113     JtMessage msg;
114
115     msg = new JtMessage ();
116
117     // Set attribute/column mappings
118

119     if (getValue (this, "configFile") != null)
120       return;
121
122     // Use the following fallback mappings (attribute/column)
123
// if the config file is not present
124

125         setValue (msg, "msgContent", "email");
126         setValue (msg, "msgData", "email");
127         msg.setMsgId ("JtMAP_ATTRIBUTE");
128         processMessage (msg);
129
130         setValue (msg, "msgContent", "status");
131         setValue (msg, "msgData", "status");
132         processMessage (msg);
133
134         setValue (msg, "msgContent", "firstname");
135         setValue (msg, "msgData", "firstname");
136         processMessage (msg);
137
138         setValue (msg, "msgContent", "lastname");
139         setValue (msg, "msgData", "lastname");
140         processMessage (msg);
141
142
143         setValue (msg, "msgContent", "subject");
144         setValue (msg, "msgData", "subject");
145         processMessage (msg);
146
147
148         setValue (msg, "msgContent", "comments");
149         setValue (msg, "msgData", "comments");
150         processMessage (msg);
151
152
153         setValue (msg, "msgContent", "email_flag");
154         setValue (msg, "msgData", "email_flag");
155         processMessage (msg);
156
157
158         setValue (msg, "msgContent", "tstamp");
159         setValue (msg, "msgData", "tstamp");
160         processMessage (msg);
161
162
163         setValue (msg, "msgContent", "mdate");
164         setValue (msg, "msgData", "mdate");
165         processMessage (msg);
166
167
168         setValue (msg, "msgContent", "location");
169         setValue (msg, "msgData", "location");
170         processMessage (msg);
171
172
173   }
174   // processMessageEvent: process messages
175

176   public Object JavaDoc processMessage (Object JavaDoc event) {
177   String JavaDoc content;
178   String JavaDoc query;
179   JtMessage e = (JtMessage) event;
180
181    if (!initted) {
182      initted = true;
183      mapAttributes ();
184    }
185     // Let the superclass handle all the messages
186

187     return (super.processMessage (event));
188
189
190   }
191
192   // Test program
193

194   public static void main(String JavaDoc[] args) {
195
196     JtObject main = new JtObject ();
197     JtMessage msg, msg1;
198     Integer JavaDoc count;
199     Date date = new Date ();
200     DateFormat df = DateFormat.getDateInstance();
201     DAOMember tmp;
202     Exception JavaDoc ex;
203     Object JavaDoc tmp1;
204
205
206     //main.setObjTrace (1);
207
main.createObject ("Jt.examples.DAOMember", "member");
208     msg = (JtMessage) main.createObject ("Jt.JtMessage", "message");
209
210     main.setValue ("member", "key", "email");
211     main.setValue ("member", "table", "member");
212
213     //main.setValue ("member", "tstamp", "December 12, 2004");
214
//main.setValue ("member", "tstamp", df.format (date));
215

216     main.setValue ("member", "tstamp", new Date ());
217     main.setValue ("member", "email", "xxx@fsw.com");
218     main.setValue ("member", "status", "2005");
219     main.setValue ("member", "email_flag", "100");
220
221
222     //main.sendMessage ("member", "message");
223

224     main.setValue ("message", "msgId", "JtINSERT");
225     tmp1 = main.sendMessage ("member", "message");
226
227     if (tmp1 == null){
228       System.out.println ("JtINSERT: FAIL");
229     } else if (tmp1 instanceof Integer JavaDoc) {
230       if (((Integer JavaDoc) tmp1).intValue () != 1)
231         System.out.println ("JtINSERT: FAIL");
232       else
233         System.out.println ("JtINSERT: PASS");
234     } else {
235     ex = (Exception JavaDoc) main.getValue ("member", "objException");
236     if (ex == null) {
237       main.setValue ("member", "email", "xxx@fsw.com");
238       //main.setValue ("member", "key", "email");
239
//main.setValue ("member", "table", "members");
240

241       main.setValue ("message", "msgId", "JtFIND");
242       tmp = (DAOMember) main.sendMessage ("member", "message");
243
244       if (tmp == null) {
245         System.out.println ("JtINSERT: FAIL");
246       } else
247         System.out.println ("JtINSERT: PASS");
248
249     } else
250       System.out.println ("JtINSERT: FAIL");
251     }
252
253     main.setValue ("member", "email", "xxx@fsw.com");
254     main.setValue ("member", "key", "email");
255     main.setValue ("member", "table", "member");
256
257     main.setValue ("message", "msgId", "JtFIND");
258     tmp = (DAOMember) main.sendMessage ("member", "message");
259
260
261     ex = (Exception JavaDoc) main.getValue ("member", "objException");
262
263     if (ex != null) {
264         System.out.println ("JtFIND: FAIL");
265     } else
266       if (tmp != null)
267         System.out.println ("JtFIND: PASS");
268       else
269         System.out.println ("JtFIND: FAIL");
270
271
272     main.setValue ("message", "msgId", "JtPRINT");
273     main.sendMessage ("member", "message");
274
275
276     main.setValue ("message", "msgId", "JtCLEAR");
277     main.sendMessage ("member", "message");
278
279
280     main.setValue ("member", "status", "2006");
281     main.setValue ("member", "email_flag", "101");
282
283     main.setValue ("message", "msgId", "JtUPDATE");
284     tmp1 = main.sendMessage ("member", "message");
285
286     if (tmp1 == null){
287       System.out.println ("JtUPDATE: FAIL");
288     } else if (tmp1 instanceof Integer JavaDoc) {
289       if (((Integer JavaDoc) tmp1).intValue () != 1)
290         System.out.println ("JtUPDATE: FAIL");
291       else
292         System.out.println ("JtUPDATE: PASS");
293     } else {
294     ex = (Exception JavaDoc) main.getValue ("member", "objException");
295     if (ex == null)
296       System.out.println ("JtUPDATE: PASS");
297     else
298       System.out.println ("JtUPDATE: FAIL");
299     }
300
301     main.setValue ("member", "email", "xxx@fsw.com");
302     //main.setValue ("member", "status", "2005");
303
//main.setValue ("member", "email_flag", "100");
304

305     //main.sendMessage ("member", "message");
306

307     main.setValue ("message", "msgId", "JtDELETE");
308     tmp1 = main.sendMessage ("member", "message");
309
310     if (tmp1 == null){
311       System.out.println ("JtDELETE: FAIL");
312     } else if (tmp1 instanceof Integer JavaDoc) {
313       if (((Integer JavaDoc) tmp1).intValue () != 1)
314         System.out.println ("JtDELETE: FAIL");
315       else
316         System.out.println ("JtDELETE: PASS");
317     } else {
318
319     ex = (Exception JavaDoc) main.getValue ("member", "objException");
320     if (ex == null) {
321       main.setValue ("member", "email", "xxx@fsw.com");
322       //main.setValue ("member", "key", "email");
323
//main.setValue ("member", "table", "members");
324

325       main.setValue ("message", "msgId", "JtFIND");
326       tmp = (DAOMember) main.sendMessage ("member", "message");
327
328       if (tmp == null) {
329         System.out.println ("JtDELETE: PASS");
330       } else
331         System.out.println ("JtDELETE: FAIL");
332     } else
333       System.out.println ("JtDELETE: FAIL");
334     }
335
336
337   }
338
339
340 }
Popular Tags