KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > plugin > GroupTable


1 package com.quikj.application.web.talk.plugin;
2
3 import com.quikj.server.framework.*;
4 import java.sql.*;
5 import java.util.*;
6
7 public class GroupTable
8 {
9     // database group table name constant
10
public static final String JavaDoc GROUP_TABLE_NAME = "group_tbl";
11     
12     // database group table column name constants
13
public static final String JavaDoc GROUPNAME = "groupid";
14     public static final String JavaDoc DOMAIN = "domain";
15     public static final String JavaDoc FLAGS = "flags";
16     public static final String JavaDoc MEMBERLOGIN_NOTIFICATION = "memberlogin_notif";
17     public static final String JavaDoc MEMBERBUSY_NOTIFICATION = "memberbusy_notif";
18     public static final String JavaDoc OWNERLOGIN_NOTIFICATION = "ownerlogin_notif";
19     public static final String JavaDoc OWNERBUSY_NOTIFICATION = "ownerbusy_notif";
20     
21     // database group owner table name constant
22
public static final String JavaDoc GROUP_OWNER_TABLE_NAME = "group_owner_tbl";
23     
24     // database group owner table column name constants
25
public static final String JavaDoc USERNAME = UserTable.USERNAME;
26     //public static final String GROUPNAME = "groupid";
27

28     // database group member table name constant
29
public static final String JavaDoc GROUP_MEMBER_TABLE_NAME = "group_member_tbl";
30     
31     // database group member table column name constants
32
//public static final String USERNAME = UserTable.USERNAME;
33
//public static final String GROUPNAME = "groupid";
34

35     
36     public static Statement getGroupElementQueryStatement(Connection c, String JavaDoc groupname)
37     throws SQLException
38     {
39         PreparedStatement ps = c.prepareStatement("select "
40         + MEMBERLOGIN_NOTIFICATION
41         + ", "
42         + MEMBERBUSY_NOTIFICATION
43         + ", "
44         + OWNERLOGIN_NOTIFICATION
45         + ", "
46         + OWNERBUSY_NOTIFICATION
47         + " from "
48         + GROUP_TABLE_NAME
49         + " where "
50         + GROUPNAME
51         + " = ?");
52         
53         ps.setString(1, groupname);
54         
55         return ps;
56     }
57     
58     public static void processGroupElementQueryResult(GroupElement groupdata,
59     ResultSet result)
60     throws SQLException
61     {
62         groupdata.setMemberLoginNotificationControl(result.getInt(1));
63         groupdata.setMemberBusyNotificationControl(result.getInt(2));
64         groupdata.setOwnerLoginNotificationControl(result.getInt(3));
65         groupdata.setOwnerBusyNotificationControl(result.getInt(4));
66     }
67     
68     public static String JavaDoc getListGroupQueryStatement()
69     {
70         return ("select "
71         + GROUPNAME
72         + " from "
73         + GROUP_TABLE_NAME
74         + ';');
75     }
76     
77     public static String JavaDoc[] processListGroupQueryResult(ResultSet result)
78     throws SQLException
79     {
80         return processStringsResult(result);
81     }
82     
83     public static Statement getGroupOwnerQueryStatement(Connection c, String JavaDoc groupname)
84     throws SQLException
85     {
86         PreparedStatement ps = c.prepareStatement("select "
87         + USERNAME
88         + " from "
89         + GROUP_OWNER_TABLE_NAME
90         + " where "
91         + GROUPNAME
92         + " = ?");
93         
94         ps.setString(1, groupname);
95         
96         return ps;
97     }
98     
99     public static String JavaDoc processGroupOwnerQueryResult(ResultSet result)
100     throws SQLException
101     {
102         String JavaDoc ret = null;
103         
104         if (result != null)
105         {
106             if (result.next() == true)
107             {
108                 ret = result.getString(1);
109             }
110         }
111         
112         return ret;
113     }
114     
115     public static Statement getGroupMemberQueryStatement(Connection c, String JavaDoc groupname)
116     throws SQLException
117     {
118         PreparedStatement ps = c.prepareStatement("select "
119         + USERNAME
120         + " from "
121         + GROUP_MEMBER_TABLE_NAME
122         + " where "
123         + GROUPNAME
124         + " = ?");
125         
126         ps.setString(1, groupname);
127         
128         return ps;
129     }
130     
131     public static String JavaDoc[] processGroupMemberQueryResult(ResultSet result)
132     throws SQLException
133     {
134         return processStringsResult(result);
135     }
136     
137     
138     public static Statement getGroupNamesByOwnerQueryStatement(Connection c, String JavaDoc username)
139     throws SQLException
140     {
141         PreparedStatement ps = c.prepareStatement("select "
142         + GROUPNAME
143         + " from "
144         + GROUP_OWNER_TABLE_NAME
145         + " where "
146         + USERNAME
147         + " = ?");
148         
149         ps.setString(1, username);
150         
151         return ps;
152     }
153     
154     public static String JavaDoc[] processGroupNamesByOwnerQueryResult(ResultSet result)
155     throws SQLException
156     {
157         return processStringsResult(result);
158     }
159     
160     public static String JavaDoc[] processStringsResult(ResultSet result)
161     throws SQLException
162     {
163         String JavaDoc[] list = null;
164         
165         ArrayList namelist = new ArrayList();
166         
167         if (result != null)
168         {
169             while (result.next() == true)
170             {
171                 namelist.add(result.getString(1));
172             }
173         }
174         
175         if (namelist.size() > 0)
176         {
177             String JavaDoc[] temp = new String JavaDoc[namelist.size()];
178             list = ((String JavaDoc[]) (namelist.toArray(temp)));
179         }
180         
181         return list;
182     }
183     
184     public static Statement getGroupNamesByMemberQueryStatement(Connection c, String JavaDoc username)
185     throws SQLException
186     {
187         PreparedStatement ps = c.prepareStatement("select "
188         + GROUPNAME
189         + " from "
190         + GROUP_MEMBER_TABLE_NAME
191         + " where "
192         + USERNAME
193         + " = ?");
194         
195         ps.setString(1, username);
196         
197         return ps;
198     }
199     
200     public static String JavaDoc[] processGroupNamesByMemberQueryResult(ResultSet result)
201     throws SQLException
202     {
203         return processStringsResult(result);
204     }
205     
206     public static Statement[] getGroupInfoByUserQueryStatements(Connection c, String JavaDoc username)
207     throws SQLException
208     // this returns the queries necessary to get all GroupInfos for groups that the
209
// given user owns as well as belongs to
210
{
211         Statement[] sql_statements = new Statement[4];
212         
213         // get groups info by owner (group name, notification controls)
214
PreparedStatement ps = c.prepareStatement("select g."
215         + GROUPNAME
216         + ",g."
217         + MEMBERLOGIN_NOTIFICATION
218         + ",g."
219         + MEMBERBUSY_NOTIFICATION
220         + ",g."
221         + OWNERLOGIN_NOTIFICATION
222         + ",g."
223         + OWNERBUSY_NOTIFICATION
224         + " from "
225         + GROUP_TABLE_NAME
226         + " as g inner join "
227         + GROUP_OWNER_TABLE_NAME
228         + " as o using ("
229         + GROUPNAME
230         + ") where o."
231         + USERNAME
232         + " = ?");
233         
234         ps.setString(1, username);
235         
236         sql_statements[0] = ps;
237         
238         // get groups members by owner
239
ps = c.prepareStatement("select m."
240         + GROUPNAME
241         + ",m."
242         + USERNAME
243         + " from "
244         + GROUP_MEMBER_TABLE_NAME
245         + " as m inner join "
246         + GROUP_OWNER_TABLE_NAME
247         + " as o using ("
248         + GROUPNAME
249         + ") where o."
250         + USERNAME
251         + " = ?");
252         
253         ps.setString(1, username);
254         
255         sql_statements[1] = ps;
256         
257         // get groups info by member (group name, notif, owner)
258
ps = c.prepareStatement("select g."
259         + GROUPNAME
260         + ",g."
261         + MEMBERLOGIN_NOTIFICATION
262         + ",g."
263         + MEMBERBUSY_NOTIFICATION
264         + ",g."
265         + OWNERLOGIN_NOTIFICATION
266         + ",g."
267         + OWNERBUSY_NOTIFICATION
268         + ",o."
269         + USERNAME
270         + " from "
271         + GROUP_TABLE_NAME
272         + " as g inner join "
273         + GROUP_OWNER_TABLE_NAME
274         + " as o using ("
275         + GROUPNAME
276         + ") inner join "
277         + GROUP_MEMBER_TABLE_NAME
278         + " as m using ("
279         + GROUPNAME
280         + ") where m."
281         + USERNAME
282         + " = ?");
283         
284         ps.setString(1, username);
285         
286         sql_statements[2] = ps;
287         
288         // get groups members by member
289
ps = c.prepareStatement("select m."
290         + GROUPNAME
291         + ",m."
292         + USERNAME
293         + " from "
294         + GROUP_MEMBER_TABLE_NAME
295         + " as m inner join "
296         + GROUP_MEMBER_TABLE_NAME
297         + " as m1 using ("
298         + GROUPNAME
299         + ") where m1."
300         + USERNAME
301         + " = ?");
302         
303         ps.setString(1, username);
304         
305         sql_statements[3] = ps;
306         
307         return sql_statements;
308     }
309     
310     public static GroupInfo[] processGroupInfoByUserQueryResult(String JavaDoc username,
311     ResultSet [] result)
312     throws SQLException
313     {
314         GroupInfo[] list = null;
315         
316         HashMap grouplist = new HashMap(); // key = group name, value = GroupInfo
317

318         // process getting groups info by owner (group name, notification controls)
319
if (result.length > 0)
320         {
321             if (result[0] != null)
322             {
323                 while (result[0].next() == true)
324                 {
325                     String JavaDoc groupname = result[0].getString(1);
326                     
327                     GroupInfo info = new GroupInfo(groupname);
328                     info.getGroupData().setMemberLoginNotificationControl(result[0].getInt(2));
329                     info.getGroupData().setMemberBusyNotificationControl(result[0].getInt(3));
330                     info.getGroupData().setOwnerLoginNotificationControl(result[0].getInt(4));
331                     info.getGroupData().setOwnerBusyNotificationControl(result[0].getInt(5));
332                     
333                     info.setOwner(username);
334                     
335                     grouplist.put(new String JavaDoc(groupname), info);
336                 }
337             }
338         }
339         
340         // process getting groups members by owner
341
if (result.length > 1)
342         {
343             if (result[1] != null)
344             {
345                 while (result[1].next() == true)
346                 {
347                     String JavaDoc groupname = result[1].getString(1);
348                     String JavaDoc member = result[1].getString(2);
349                     GroupInfo info = (GroupInfo) grouplist.get(groupname);
350                     if (info == null)
351                     {
352                         AceLogger.Instance().log(AceLogger.ERROR,
353                         AceLogger.SYSTEM_LOG,
354                         " GroupTable.processGroupInfoByUserQueryResult() -- Couldn't find group "
355                         + groupname
356                         + " in list, owned by user "
357                         + username
358                         + ", trying to add member "
359                         + member);
360                     }
361                     else
362                     {
363                         if (info.addMember(member) == false)
364                         {
365                             AceLogger.Instance().log(AceLogger.ERROR,
366                             AceLogger.SYSTEM_LOG,
367                             " GroupTable.processGroupInfoByUserQueryResult() -- Couldn't add member "
368                             + member
369                             + " to group "
370                             + groupname
371                             + " owned by "
372                             + username
373                             + ", probably duplicate error.");
374                         }
375                     }
376                 }
377             }
378         }
379         
380         // process getting groups info by member (group name, notif, owner)
381
if (result.length > 2)
382         {
383             if (result[2] != null)
384             {
385                 while (result[2].next() == true)
386                 {
387                     String JavaDoc groupname = result[2].getString(1);
388                     
389                     GroupInfo info = new GroupInfo(groupname);
390                     info.getGroupData().setMemberLoginNotificationControl(result[2].getInt(2));
391                     info.getGroupData().setMemberBusyNotificationControl(result[2].getInt(3));
392                     info.getGroupData().setOwnerLoginNotificationControl(result[2].getInt(4));
393                     info.getGroupData().setOwnerBusyNotificationControl(result[2].getInt(5));
394                     
395                     info.setOwner(result[2].getString(6));
396                     
397                     grouplist.put(new String JavaDoc(groupname), info);
398                 }
399             }
400         }
401         
402         // process getting groups members by member
403
if (result.length > 3)
404         {
405             if (result[3] != null)
406             {
407                 while (result[3].next() == true)
408                 {
409                     String JavaDoc groupname = result[3].getString(1);
410                     String JavaDoc member = result[3].getString(2);
411                     GroupInfo info = (GroupInfo) grouplist.get(groupname);
412                     if (info == null)
413                     {
414                         AceLogger.Instance().log(AceLogger.ERROR,
415                         AceLogger.SYSTEM_LOG,
416                         " GroupTable.processGroupInfoByUserQueryResult() -- Couldn't find group "
417                         + groupname
418                         + " in list, referenced by member user "
419                         + username
420                         + ", trying to add member "
421                         + member);
422                     }
423                     else
424                     {
425                         if (info.addMember(member) == false)
426                         {
427                             AceLogger.Instance().log(AceLogger.ERROR,
428                             AceLogger.SYSTEM_LOG,
429                             " GroupTable.processGroupInfoByUserQueryResult() -- Couldn't add member "
430                             + member
431                             + " to group "
432                             + groupname
433                             + " referenced by member "
434                             + username
435                             + ", probably duplicate error.");
436                         }
437                     }
438                 }
439             }
440         }
441         
442         if (grouplist.size() > 0)
443         {
444             GroupInfo[] temp = new GroupInfo[grouplist.size()];
445             list = ((GroupInfo[]) ((grouplist.values()).toArray(temp)));
446         }
447         
448         
449         return list;
450     }
451     
452 }
453
454
Popular Tags