KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > workareas > WorkArea


1 /*
2   Copyright (C) 2003 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.workareas;
34
35 import java.io.IOException JavaDoc;
36
37 import java.sql.Connection JavaDoc;
38 import java.sql.Date JavaDoc;
39 import java.sql.ResultSet JavaDoc;
40 import java.sql.Statement JavaDoc;
41 import java.sql.PreparedStatement JavaDoc;
42 import java.sql.CallableStatement JavaDoc;
43 import java.sql.SQLException JavaDoc;
44 import java.sql.Types JavaDoc;
45
46 import com.knowgate.jdc.JDCConnection;
47 import com.knowgate.debug.DebugFile;
48 import com.knowgate.misc.Gadgets;
49 import com.knowgate.dataobjs.*;
50
51 import com.knowgate.addrbook.Room;
52 import com.knowgate.addrbook.Meeting;
53 import com.knowgate.addrbook.Fellow;
54
55 import com.knowgate.crm.Company;
56 import com.knowgate.crm.Contact;
57 import com.knowgate.crm.DistributionList;
58
59 import com.knowgate.projtrack.Project;
60
61 import com.knowgate.hipergate.Image;
62
63 import com.knowgate.dataxslt.db.*;
64
65 import com.knowgate.hipergate.QueryByForm;
66 import com.knowgate.hipergate.Shop;
67
68 import com.knowgate.scheduler.Job;
69
70 /**
71  * <p>WorkArea</p>
72  * @author Sergio Montoro Ten
73  * @version 2.0
74  */

75 public class WorkArea extends DBPersist {
76
77   /**
78    * Create empty WorkArea.
79    */

80   public WorkArea() {
81     super(DB.k_workareas, "WorkArea");
82   }
83
84   // ----------------------------------------------------------
85

86   /**
87    * Load WorkArea from database
88    * @param oConn Database Conenction
89    * @param sIdWorkArea GUID of WorkArea to be loaded
90    * @throws SQLException
91    */

92   public WorkArea(JDCConnection oConn, String JavaDoc sIdWorkArea) throws SQLException JavaDoc {
93     super(DB.k_workareas, "WorkArea");
94
95     Object JavaDoc aWrkA[] = { sIdWorkArea };
96
97     load (oConn,aWrkA);
98   }
99
100   // ----------------------------------------------------------
101

102   /**
103    * <p>Delete a WorkArea and all its associated data.</p>
104    * USE THIS METHOD WITH EXTREME CARE. AS IT WILL DELETE DATA FROM EVERY TABLE
105    * CONTAINING A gu_workarea COLUMN MATCHING THE DELETED WORKAREA GUID.<br><br>
106    * Deletion takes place by delegating it in other objects delete() method.
107    * @param oConn Database Connection
108    * @throws SQLException
109    */

110   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
111     return WorkArea.delete(oConn, getString(DB.gu_workarea));
112   }
113
114   // ----------------------------------------------------------
115

116   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
117
118     // Si no se especificó un identificador para el área de trabajo
119
// entonces añadirlo autimaticamente
120
if (!AllVals.containsKey(DB.gu_workarea))
121       put(DB.gu_workarea, Gadgets.generateUUID());
122
123     return super.store(oConn);
124   }
125
126   // ----------------------------------------------------------
127

128   public int getUserAppMask(JDCConnection oConn, String JavaDoc sUserId) throws SQLException JavaDoc {
129     return WorkArea.getUserAppMask(oConn, getString(DB.gu_workarea), sUserId);
130   }
131
132   // ----------------------------------------------------------
133

134   public DBSubset getUsers(JDCConnection oConn) throws SQLException JavaDoc {
135     Object JavaDoc oGroups[] = { get(DB.gu_admins), get(DB.gu_powusers), get(DB.gu_users), get(DB.gu_guests), get(DB.gu_other) };
136     DBSubset oUsers = new DBSubset(DB.k_users + " u",
137                                    "u." + DB.gu_user +",u." + DB.tx_nickname + ",u." + DB.nm_user + ",u." + DB.tx_surname1 + ",u." + DB.tx_surname2 + ",u." + DB.bo_searchable + ",u." + DB.tx_main_email,
138                                    "EXISTS (SELECT x." + DB.gu_user + " FROM " + DB.k_x_group_user + " x WHERE " + DB.gu_user + "=u." + DB.gu_user + " AND x." + DB.gu_acl_group + " IN (?,?,?,?,?)) ORDER BY 3,4,5", 4);
139     oUsers.load(oConn, oGroups);
140
141     return oUsers;
142   }
143
144   // **********************************************************
145
// Static Methods
146

147   /**
148    * <p>Delete a WorkArea and all its associated data.</p>
149    * USE THIS METHOD WITH EXTREME CARE. AS IT WILL DELETE DATA FROM EVERY TABLE
150    * CONTAINING A gu_workarea COLUMN MATCHING THE DELETED WORKAREA GUID.<br><br>
151    * Deletion takes place by delegating it in other objects delete() method.<br><br>
152    * In this order:<br>
153    * <table border=1 cellpadding=4>
154    * <tr><td>DELETE k_x_portlet_user</td></tr>
155    * <tr><td>QueryByForm.delete</td></tr>
156    * <tr><td>MicrositeDB.delete</td></tr>
157    * <tr><td>PageSetDB.delete</td></tr>
158    * <tr><td>DELETE k_images</td></tr>
159    * <tr><td>DistributionList.delete</td></tr>
160    * <tr><td>Meeting.delete</td></tr>
161    * <tr><td>Fellow.delete</td></tr>
162    * <tr><td>DELETE k_lu_fellow_titles</td></tr>
163    * <tr><td>DELETE k_fellows_lookup</td></tr>
164    * <tr><td>Room.delete</td></tr><tr>
165    * <tr><td>DELETE k_rooms_lookup</td></tr>
166    * <tr><td>DELETE k_to_do</td></tr>
167    * <tr><td>DELETE k_to_do_lookup</td></tr>
168    * <tr><td>DELETE k_phone_calls</td></tr>
169    * <tr><td>DELETE k_sales_men</td></tr>
170    * <tr><td>DELETE k_sales_men_lookup</td></tr>
171    * <tr><td>Company.delete</td></tr>
172    * <tr><td>DELETE k_companies_lookup</td></tr>
173    * <tr><td>DELETE k_contacts_lookup</td></tr>
174    * <tr><td>DELETE k_oportunities_lookup</td></tr>
175    * <tr><td>DELETE k_welcome_packs_lookup</td></tr>
176    * <tr><td>Project.delete</td></tr>
177    * <tr><td>DELETE k_projects_lookup</td></tr>
178    * <tr><td>DELETE k_duties_lookup </td></tr>
179    * <tr><td>DELETE k_bugs_lookup </td></tr>
180    * <tr><td>DELETE k_orders</td></tr>
181    * <tr><td>DELETE k_orders_lookup</td></tr>
182    * <tr><td>DELETE k_invoices</td></tr>
183    * <tr><td>DELETE k_invoices_lookup</td></tr>
184    * <tr><td>DELETE k_lu_business_states</td></tr>
185    * <tr><td>DELETE k_business_states</td></tr>
186    * <tr><td>Shop.delete</td></tr>
187    * <tr><td>Job.delete</td></tr>
188    * <tr><td>DELETE k_lu_meta_attrs</td></tr>
189    * <tr><td>DELETE k_addresses</td></tr>
190    * <tr><td>DELETE k_addresses_lookup</td></tr>
191    * <tr><td>DELETE k_thesauri_lookup</td></tr>
192    * <tr><td>DELETE k_bank_accounts</td></tr>
193    * <tr><td>DELETE k_bank_accounts_lookup</td></tr>
194    * <tr><td>DELETE k_x_app_workarea</td></tr>
195    * <tr><td>DELETE k_workareas</td></tr>
196    * </table>
197    * @param oConn Database Connection
198    * @param sWrkAreaGUID GUID of WorkArea to be deleted.
199    * @throws SQLException
200    */

201   public static boolean delete(JDCConnection oConn, String JavaDoc sWrkAreaGUID) throws SQLException JavaDoc {
202     CallableStatement JavaDoc oCall;
203     Statement JavaDoc oStmt;
204     PreparedStatement JavaDoc oPtmt;
205     ResultSet JavaDoc oRSet;
206     DBSubset oItems;
207     String JavaDoc sSQL;
208     int iItems;
209
210     if (DebugFile.trace) {
211       DebugFile.writeln("Begin WorkArea.delete([Connection], " + sWrkAreaGUID + ")");
212       DebugFile.incIdent();
213     }
214
215     // -----------------------------------------------------------------------------------
216
// Verificar que la WorkArea realmente existe antes de empezar a borrar y tambien
217
// evitar que una inyección maliciosa de SQL en el parámetro sWrkAreaGUID pudiera
218
// borrar más registros de los debidos
219

220     oPtmt = oConn.prepareStatement("SELECT "+DB.gu_workarea+" FROM "+DB.k_workareas+" WHERE "+DB.gu_workarea+"=?",
221                                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
222     oPtmt.setString(1, sWrkAreaGUID);
223     oRSet = oPtmt.executeQuery();
224     boolean bExists = oRSet.next();
225     oRSet.close();
226     oPtmt.close();
227
228     if (!bExists) {
229       if (DebugFile.trace) {
230         DebugFile.writeln("workarea " + sWrkAreaGUID + " not found");
231         DebugFile.decIdent();
232         DebugFile.writeln("End WorkArea.delete() : false");
233       }
234       return false;
235     }
236
237     // -----------------------------------------------------------------------------------
238
// Borrar los e-mails
239

240     if (DBBind.exists(oConn, DB.k_mime_msgs, "U")) {
241       oStmt = oConn.createStatement();
242
243       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_cat_objs + " WHERE " + DB.gu_object + " IN (SELECT " + DB.gu_mimemsg + " FROM k_mime_msgs WHERE gu_workarea='" + sWrkAreaGUID + "') AND " + DB.id_class + "=822)");
244
245       oStmt.executeUpdate("DELETE FROM " + DB.k_x_cat_objs + " WHERE " + DB.gu_object + " IN (SELECT " + DB.gu_mimemsg + " FROM k_mime_msgs WHERE gu_workarea='" + sWrkAreaGUID + "') AND " + DB.id_class + "=822");
246
247       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_inet_addrs + " WHERE " + DB.gu_mimemsg + " IN (SELECT " + DB.gu_mimemsg + " FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'))");
248
249       oStmt.executeUpdate("DELETE FROM " + DB.k_inet_addrs + " WHERE " + DB.gu_mimemsg + " IN (SELECT " + DB.gu_mimemsg + " FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')");
250
251       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_mime_parts + " WHERE " + DB.gu_mimemsg + " IN (SELECT " + DB.gu_mimemsg + " FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'))");
252
253       oStmt.executeUpdate("DELETE FROM " + DB.k_mime_parts + " WHERE " + DB.gu_mimemsg + " IN (SELECT " + DB.gu_mimemsg + " FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')");
254
255       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')");
256
257       oStmt.executeUpdate("DELETE FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'");
258
259       oStmt.close();
260     }
261
262     // -----------------------------------------------------------------------------------
263
// Borrar las preferencias de usuario para portlets
264

265     if (DBBind.exists(oConn, DB.k_x_portlet_user, "U")) {
266       oStmt = oConn.createStatement();
267
268       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')");
269
270       oStmt.executeUpdate("DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'");
271
272       oStmt.close();
273     }
274
275     // -----------------------------------------------------------------------------------
276
// Borrar las consultas
277

278     if (DBBind.exists(oConn, DB.k_queries, "U")) {
279       oItems = new DBSubset (DB.k_queries, DB.gu_query, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
280       iItems = oItems.load(oConn);
281
282       for (int p=0;p<iItems; p++)
283         QueryByForm.delete(oConn, oItems.getString(0, p));
284     }
285     // -----------------------------------------------------------------------------------
286

287     // Borrar los pagesets
288
if (DBBind.exists(oConn, DB.k_pagesets, "U")) {
289       oItems = new DBSubset (DB.k_pagesets, DB.gu_pageset, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
290       iItems = oItems.load(oConn);
291       for (int p=0;p<iItems; p++)
292         PageSetDB.delete(oConn, oItems.getString(0,p));
293     }
294
295     // -----------------------------------------------------------------------------------
296

297     // Borrar los microsites
298
if (DBBind.exists(oConn, DB.k_microsites, "U")) {
299       oItems = new DBSubset (DB.k_microsites, DB.gu_microsite, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
300       iItems = oItems.load(oConn);
301       for (int p=0;p<iItems; p++)
302         new MicrositeDB(oConn, oItems.getString(0,p)).delete(oConn);
303     }
304
305     // -----------------------------------------------------------------------------------
306
// Nuevo para la v2.1
307
// Borrar las imagenes
308

309     if (DBBind.exists(oConn, DB.k_images, "U")) {
310       oItems = new DBSubset (DB.k_images, DB.gu_image, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
311       iItems = oItems.load(oConn);
312       for (int p=0;p<iItems; p++)
313         new Image(oConn, oItems.getString(0,p)).delete(oConn);
314     }
315
316     // -----------------------------------------------------------------------------------
317
// Borrar las listas
318
if (DBBind.exists(oConn, DB.k_lists, "U")) {
319       oItems = new DBSubset (DB.k_lists, DB.gu_list, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
320       iItems = oItems.load(oConn);
321       for (int p=0;p<iItems; p++)
322         DistributionList.delete(oConn, oItems.getString(0,p));
323     }
324     // -----------------------------------------------------------------------------------
325

326     // Borrar actividades, compañeros y salas
327

328     if (DBBind.exists(oConn, DB.k_meetings, "U")) {
329       oItems = new DBSubset (DB.k_meetings, DB.gu_meeting, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
330       iItems = oItems.load(oConn);
331       for (int c=0;c<iItems; c++)
332         Meeting.delete(oConn, oItems.getString(0,c));
333     }
334
335     if (DBBind.exists(oConn, DB.k_fellows, "U")) {
336       oItems = new DBSubset (DB.k_fellows, DB.gu_fellow, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
337       iItems = oItems.load(oConn);
338       for (int c=0;c<iItems; c++)
339         Fellow.delete(oConn, oItems.getString(0,c));
340     }
341
342     if (DBBind.exists(oConn, DB.k_lu_fellow_titles, "U")) {
343       oStmt = oConn.createStatement();
344       sSQL = "DELETE FROM " + DB.k_lu_fellow_titles + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
345       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
346       oStmt.execute(sSQL);
347       oStmt.close();
348     }
349
350     if (DBBind.exists(oConn, DB.k_fellows_lookup, "U")) {
351       oStmt = oConn.createStatement();
352       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
353       sSQL = "DELETE FROM " + DB.k_fellows_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
354       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
355       oStmt.execute(sSQL);
356       oStmt.close();
357     }
358
359     if (DBBind.exists(oConn, DB.k_rooms, "U")) {
360       oItems = new DBSubset (DB.k_rooms, DB.nm_room, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
361       iItems = oItems.load(oConn);
362       for (int c=0;c<iItems; c++)
363         Room.delete(oConn, oItems.getString(0,c), sWrkAreaGUID);
364     }
365
366     if (DBBind.exists(oConn, DB.k_rooms_lookup, "U")) {
367       oStmt = oConn.createStatement();
368       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
369       sSQL = "DELETE FROM " + DB.k_rooms_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
370       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
371       oStmt.execute(sSQL);
372       oStmt.close();
373     }
374
375     // -----------------------------------------------------------------------------------
376
// Borrar ToDo Lists
377

378     if (DBBind.exists(oConn, DB.k_to_do, "U")) {
379       oStmt = oConn.createStatement();
380       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
381       sSQL = "DELETE FROM " + DB.k_to_do + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
382       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
383       oStmt.execute(sSQL);
384       oStmt.close();
385     }
386
387     if (DBBind.exists(oConn, DB.k_to_do_lookup, "U")) {
388       oStmt = oConn.createStatement();
389       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
390       sSQL = "DELETE FROM " + DB.k_to_do_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
391       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
392       oStmt.execute(sSQL);
393       oStmt.close();
394     }
395
396     // -----------------------------------------------------------------------------------
397
// Borrar llamadas de teléfono
398

399     if (DBBind.exists(oConn, DB.k_phone_calls, "U")) {
400       oStmt = oConn.createStatement();
401       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
402       sSQL = "DELETE FROM " + DB.k_phone_calls + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
403       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
404       oStmt.execute(sSQL);
405       oStmt.close();
406     }
407
408     // -----------------------------------------------------------------------------------
409
// Borrar el datawarehouse de direcciones
410

411     if (DBBind.exists(oConn, DB.k_member_address, "U")) {
412
413       oStmt = oConn.createStatement();
414       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
415
416       sSQL = "DELETE FROM " + DB.k_member_address + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
417       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")");
418       oStmt.executeUpdate(sSQL);
419
420       oStmt.close();
421     }
422
423     // -----------------------------------------------------------------------------------
424

425     // Borrar los Vendedores
426
if (DBBind.exists(oConn, DB.k_sales_men, "U")) {
427       oItems = new DBSubset (DB.k_sales_men, DB.gu_sales_man, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
428       iItems = oItems.load(oConn);
429
430       if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
431         if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT k_sp_del_sales_man (?))");
432          oPtmt = oConn.prepareStatement("SELECT k_sp_del_sales_man (?)");
433          for (int c=0;c<iItems; c++) {
434            oPtmt.setString(1, oItems.getString(0,c));
435            oPtmt.executeQuery();
436          } // next
437
oPtmt.close();
438       }
439       else {
440         if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_sales_man (?) })");
441          oCall = oConn.prepareCall("{call k_sp_del_sales_man (?)}");
442          for (int c=0;c<iItems; c++) {
443            oCall.setString(1, oItems.getString(0,c));
444            oCall.execute();
445          } // next
446
oCall.close();
447       }
448     } // fi (DBMS_POSTGRESQL)
449

450     if (DBBind.exists(oConn, DB.k_sales_men_lookup, "U")) {
451       oStmt = oConn.createStatement();
452       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
453       sSQL = "DELETE FROM " + DB.k_sales_men_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
454       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
455       oStmt.execute(sSQL);
456       oStmt.close();
457     }
458
459     // -----------------------------------------------------------------------------------
460

461     // Borrar las compañías, cada compañía borrará en cascada sus individuos asociados
462
if (DBBind.exists(oConn, DB.k_companies, "U")) {
463       oItems = new DBSubset (DB.k_companies, DB.gu_company, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
464       iItems = oItems.load(oConn);
465       for (int c=0;c<iItems; c++)
466         Company.delete(oConn, oItems.getString(0,c));
467     }
468
469     // Borrar los contactos, puede haber contactos individuales no asociados a ninguna compañia
470
if (DBBind.exists(oConn, DB.k_contacts, "U")) {
471       oItems = new DBSubset (DB.k_contacts, DB.gu_contact, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
472       iItems = oItems.load(oConn);
473       for (int c=0;c<iItems; c++)
474         Contact.delete(oConn, oItems.getString(0,c));
475     }
476
477     if (DBBind.exists(oConn, DB.k_companies_lookup, "U")) {
478       oStmt = oConn.createStatement();
479       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
480       sSQL = "DELETE FROM " + DB.k_companies_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
481       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
482       oStmt.execute(sSQL);
483       oStmt.close();
484     }
485
486     if (DBBind.exists(oConn, DB.k_contacts_lookup, "U")) {
487       oStmt = oConn.createStatement();
488       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
489       sSQL = "DELETE FROM " + DB.k_contacts_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
490       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
491       oStmt.execute(sSQL);
492       oStmt.close();
493     }
494
495     if (DBBind.exists(oConn, DB.k_oportunities_lookup, "U")) {
496       oStmt = oConn.createStatement();
497       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
498       sSQL = "DELETE FROM " + DB.k_oportunities_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
499       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
500       oStmt.execute(sSQL);
501       oStmt.close();
502     }
503
504     if (DBBind.exists(oConn, DB.k_welcome_packs_lookup, "U")) {
505       oStmt = oConn.createStatement();
506       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
507       sSQL = "DELETE FROM " + DB.k_welcome_packs_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
508       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
509       oStmt.execute(sSQL);
510       oStmt.close();
511     }
512
513     // -----------------------------------------------------------------------------------
514

515     // Borrar los proyectos, cada proyecto borrará en cascada sus incidencias y tareas
516
if (DBBind.exists(oConn, DB.k_projects, "U")) {
517       oItems = new DBSubset (DB.k_projects, DB.gu_project, DB.gu_owner + "='" + sWrkAreaGUID + "'", 100);
518       iItems = oItems.load(oConn);
519       for (int p=0;p<iItems; p++)
520         Project.delete(oConn, oItems.getString(0,p));
521     }
522
523     if (DBBind.exists(oConn, DB.k_projects_lookup, "U")) {
524       oStmt = oConn.createStatement();
525       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
526       sSQL = "DELETE FROM " + DB.k_projects_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
527       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
528       oStmt.execute(sSQL);
529       oStmt.close();
530     }
531
532     if (DBBind.exists(oConn, DB.k_duties_lookup, "U")) {
533       oStmt = oConn.createStatement();
534       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
535       sSQL = "DELETE FROM " + DB.k_duties_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
536       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
537       oStmt.execute(sSQL);
538       oStmt.close();
539     }
540
541     if (DBBind.exists(oConn, DB.k_bugs_lookup, "U")) {
542       oStmt = oConn.createStatement();
543       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
544       sSQL = "DELETE FROM " + DB.k_bugs_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
545       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
546       oStmt.execute(sSQL);
547       oStmt.close();
548     }
549
550     // -----------------------------------------------------------------------------------
551
// Borrar las tiendas, cada tienda borrará en cascada sus categorías y productos
552

553     if (DBBind.exists(oConn, DB.k_invoices, "U")) {
554       oStmt = oConn.createStatement();
555       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
556
557       sSQL = "DELETE FROM " + DB.k_x_orders_invoices + " WHERE " + DB.gu_order + " IN (SELECT "+DB.gu_order+" FROM "+DB.k_orders+" WHERE "+DB.gu_workarea+"='"+sWrkAreaGUID + "')";
558       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
559       oStmt.execute(sSQL);
560
561       sSQL = "DELETE FROM " + DB.k_invoice_lines + " WHERE " + DB.gu_invoice + " IN (SELECT "+DB.gu_invoice+" FROM "+DB.k_invoices+" WHERE "+DB.gu_workarea+"='"+sWrkAreaGUID + "')";
562       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
563       oStmt.execute(sSQL);
564
565       sSQL = "DELETE FROM " + DB.k_invoice_schedules + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
566       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
567       oStmt.execute(sSQL);
568
569       sSQL = "DELETE FROM " + DB.k_invoices + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
570       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
571       oStmt.execute(sSQL);
572
573       sSQL = "DELETE FROM " + DB.k_invoices_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
574       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
575       oStmt.execute(sSQL);
576
577       oStmt.close();
578     }
579
580     if (DBBind.exists(oConn, DB.k_invoices_next, "U")) {
581       oStmt = oConn.createStatement();
582       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
583       sSQL = "DELETE FROM " + DB.k_invoices_next + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
584       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
585       oStmt.execute(sSQL);
586       oStmt.close();
587     }
588
589     if (DBBind.exists(oConn, DB.k_orders, "U")) {
590       oStmt = oConn.createStatement();
591       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
592
593       sSQL = "DELETE FROM " + DB.k_order_lines + " WHERE " + DB.gu_order + " IN (SELECT "+DB.gu_order+" FROM "+DB.k_orders+" WHERE "+DB.gu_workarea+"='"+sWrkAreaGUID + "')";
594       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
595       oStmt.execute(sSQL);
596
597       sSQL = "DELETE FROM " + DB.k_orders + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
598       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
599       oStmt.execute(sSQL);
600
601       sSQL = "DELETE FROM " + DB.k_orders_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
602       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
603       oStmt.execute(sSQL);
604       oStmt.close();
605     }
606
607     if (DBBind.exists(oConn, DB.k_business_states, "U")) {
608       oStmt = oConn.createStatement();
609       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
610
611       sSQL = "DELETE FROM " + DB.k_business_states + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
612       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
613       oStmt.execute(sSQL);
614
615       sSQL = "DELETE FROM " + DB.k_lu_business_states + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
616       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
617       oStmt.execute(sSQL);
618
619       oStmt.close();
620     }
621
622     if (DBBind.exists(oConn, DB.k_shops, "U")) {
623       oItems = new DBSubset (DB.k_shops, DB.gu_shop, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
624       iItems = oItems.load(oConn);
625       for (int s=0;s<iItems; s++)
626         new Shop(oConn, oItems.getString(0,s)).delete(oConn);
627     }
628
629     // -----------------------------------------------------------------------------------
630
// Borrar los jobs
631

632     if (DBBind.exists(oConn, DB.k_jobs, "U")) {
633       oItems = new DBSubset (DB.k_jobs, DB.gu_job, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
634       iItems = oItems.load(oConn);
635       for (int s=0;s<iItems; s++)
636         Job.delete(oConn, oItems.getString(0,s));
637     }
638
639     // -----------------------------------------------------------------------------------
640

641     // Borrar campos definidos por los usuarios
642
if (DBBind.exists(oConn, DB.k_lu_meta_attrs, "U")) {
643       oStmt = oConn.createStatement();
644       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
645       sSQL = "DELETE FROM " + DB.k_lu_meta_attrs + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
646       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
647       oStmt.execute(sSQL);
648       oStmt.close();
649     }
650
651     // -----------------------------------------------------------------------------------
652
// Borrar las direcciones
653

654     oStmt = oConn.createStatement();
655     try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
656
657     sSQL = "UPDATE " + DB.k_orders + " SET " + DB.gu_ship_addr + "=NULL WHERE " + DB.gu_ship_addr + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
658     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
659     oStmt.execute(sSQL);
660
661     sSQL = "UPDATE " + DB.k_orders + " SET " + DB.gu_bill_addr + "=NULL WHERE " + DB.gu_bill_addr + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
662     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
663     oStmt.execute(sSQL);
664
665     sSQL = "DELETE FROM " + DB.k_x_contact_addr + " WHERE " + DB.gu_address + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
666     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
667     oStmt.execute(sSQL);
668
669     sSQL = "DELETE FROM " + DB.k_x_company_addr + " WHERE " + DB.gu_address + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
670     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
671     oStmt.execute(sSQL);
672
673     sSQL = "DELETE FROM " + DB.k_addresses + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
674     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
675     oStmt.execute(sSQL);
676
677     sSQL = "DELETE FROM " + DB.k_addresses_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
678     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
679     oStmt.execute(sSQL);
680
681     oStmt.close();
682
683     // -----------------------------------------------------------------------------------
684

685     // Borrar las entradas del tesauro
686
if (DBBind.exists(oConn, DB.k_thesauri, "U")) {
687       oStmt = oConn.createStatement();
688       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
689
690       // Primero los sinonimos
691
sSQL = "DELETE FROM " + DB.k_thesauri + " WHERE " + DB.bo_mainterm + "=0 AND " + DB.gu_rootterm + " IN (SELECT " + DB.gu_rootterm + " FROM " + DB.k_thesauri_root + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
692
693       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")");
694       oStmt.executeUpdate(sSQL);
695
696       // Luego los términos principales
697
sSQL = "DELETE FROM " + DB.k_thesauri + " WHERE " + DB.gu_rootterm + " IN (SELECT " + DB.gu_rootterm + " FROM " + DB.k_thesauri_root + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "')";
698
699       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")");
700       oStmt.executeUpdate(sSQL);
701
702       // Finalmente los terminos raiz
703
sSQL = "DELETE FROM " + DB.k_thesauri_root + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
704
705       if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")");
706       oStmt.executeUpdate(sSQL);
707
708       oStmt.close();
709     }
710
711     // Borrar los lookups del tesauro
712
if (DBBind.exists(oConn, DB.k_thesauri_lookup, "U")) {
713       oStmt = oConn.createStatement();
714       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
715       sSQL = "DELETE FROM " + DB.k_thesauri_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
716       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
717       oStmt.execute(sSQL);
718       oStmt.close();
719     }
720
721     // -----------------------------------------------------------------------------------
722
// Borrar las cuentas bancarias
723

724     if (DBBind.exists(oConn, DB.k_bank_accounts, "U")) {
725       oStmt = oConn.createStatement();
726       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
727       sSQL = "DELETE FROM " + DB.k_bank_accounts + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
728       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
729       oStmt.execute(sSQL);
730       oStmt.close();
731     }
732
733     if (DBBind.exists(oConn, DB.k_bank_accounts_lookup, "U")) {
734       oStmt = oConn.createStatement();
735       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
736       sSQL = "DELETE FROM " + DB.k_bank_accounts_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
737       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
738       oStmt.execute(sSQL);
739       oStmt.close();
740     }
741
742     // -----------------------------------------------------------------------------------
743
// Borrar los cursos
744
// nuevo v2.2
745

746     if (DBBind.exists(oConn, DB.k_absentisms_lookup, "U")) {
747       oStmt = oConn.createStatement();
748       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
749       sSQL = "DELETE FROM " + DB.k_absentisms_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
750       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
751       oStmt.execute(sSQL);
752       oStmt.close();
753     }
754
755     if (DBBind.exists(oConn, DB.k_subjects, "U")) {
756       oStmt = oConn.createStatement();
757       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
758       sSQL = "DELETE FROM " + DB.k_subjects_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
759       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
760       oStmt.execute(sSQL);
761       sSQL = "DELETE FROM " + DB.k_subjects + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
762       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
763       oStmt.execute(sSQL);
764       oStmt.close();
765     }
766
767     if (DBBind.exists(oConn, DB.k_courses, "U")) {
768       oStmt = oConn.createStatement();
769       try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
770       sSQL = "DELETE FROM " + DB.k_courses_lookup + " WHERE " + DB.gu_owner + "='" + sWrkAreaGUID + "'";
771       if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
772       oStmt.execute(sSQL);
773       oStmt.close();
774
775       oItems = new DBSubset (DB.k_courses, DB.gu_course, DB.gu_workarea + "='" + sWrkAreaGUID + "'", 100);
776       iItems = oItems.load(oConn);
777       if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
778         oPtmt = oConn.prepareStatement("SELECT k_sp_del_course(?)");
779         for (int c=0; c<iItems; c++) {
780           oPtmt.setString(1, oItems.getString(0,c));
781           oPtmt.executeQuery();
782         }
783         oPtmt.close();
784       }
785       else {
786         oCall = oConn.prepareCall("{call k_sp_del_course (?)}");
787        for (int c=0;c<iItems; c++) {
788          oCall.setString(1, oItems.getString(0,c));
789          oCall.execute();
790        }
791        oCall.close();
792       } // fi (DBMS_POSTGRESQL)
793
} // fi (exists(DB.k_courses))
794

795
796     // -----------------------------------------------------------------------------------
797
// Borrar la workarea en si misma
798
oStmt = oConn.createStatement();
799     try { oStmt.setQueryTimeout(30); } catch (SQLException JavaDoc sqle) {}
800
801     sSQL = "DELETE FROM " + DB.k_x_app_workarea + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
802     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
803     oStmt.execute(sSQL);
804
805     sSQL = "DELETE FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'";
806     if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")");
807     oStmt.execute(sSQL);
808     oStmt.close();
809
810     if (DebugFile.trace) {
811       DebugFile.decIdent();
812       DebugFile.writeln("End WorkArea.delete() : true");
813     }
814
815     return true;
816   } // delete()
817

818   // ----------------------------------------------------------
819

820   /**
821    * <p>Delete a WorkArea, its associated data and working directories.</p>
822    * USE THIS METHOD WITH EXTREME CARE. AS IT WILL DELETE DATA FROM EVERY TABLE
823    * CONTAINING A gu_workarea COLUMN MATCHING THE DELETED WORKAREA GUID.<br><br>
824    * @param oConn Database Connection
825    * @param sWrkAreaGUID GUID of WorkArea to be deleted
826    * @param oProps Properties Colection containing "storage" and "workareasput" properties.<br>
827    * /storage/domains/<i>nnnn</i>/workareas/<i>sWrkAreaGUID</i> and
828    * /workareasput/<i>sWrkAreaGUID</i> will be taken as base directories for deleting
829    * WorkArea files.<br>
830    * javamode property will determine whether directories shall be deleted witha tomic operating
831    * systems calls or by Pure Java functions.
832    * @return <b>true</b> if specified WorkArea GUID was found and deleted at k_workareas,
833    * <b>false</b> if specified WorkArea GUID was not found.
834    * @throws IOException
835    * @throws SQLException
836    * @see com.knowgate.dfs.FileSystem.delete(String)
837    */

838   public static boolean delete (JDCConnection oConn,
839                                 String JavaDoc sWrkAreaGUID,
840                                 java.util.Properties JavaDoc oProps) throws Exception JavaDoc, IOException JavaDoc, SQLException JavaDoc {
841
842     final String JavaDoc s = System.getProperty("file.separator");
843
844     if (DebugFile.trace) {
845       DebugFile.writeln("Begin WorkArea.delete([Connection], " + sWrkAreaGUID + ", " + "[Properties])");
846       DebugFile.incIdent();
847     }
848
849     int iDomainId = 0;
850
851     if (DebugFile.trace)
852       DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.id_domain + " FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "='" + sWrkAreaGUID + "'");
853
854     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT " + DB.id_domain + " FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
855     oStmt.setString(1, sWrkAreaGUID);
856     ResultSet JavaDoc oRSet = oStmt.executeQuery();
857     if (oRSet.next())
858       iDomainId = oRSet.getInt(1);
859     oRSet.close();
860     oStmt.close();
861
862     boolean bRetVal = false;
863
864     if (0!=iDomainId) {
865       FileSystemWorkArea oFS = new FileSystemWorkArea(oProps);
866
867       bRetVal = delete(oConn, sWrkAreaGUID);
868
869       if (bRetVal) {
870         if (null != oProps.getProperty("workareasput"))
871           oFS.rmworkpath(sWrkAreaGUID);
872
873         if (null != oProps.getProperty("storage"))
874           oFS.rmstorpath(iDomainId, sWrkAreaGUID);
875
876       } // fi (bRetVal)
877
} // fi(0!=iDomainId)
878

879     if (DebugFile.trace) {
880       DebugFile.decIdent();
881       DebugFile.writeln("End WorkArea.delete() : " + String.valueOf(bRetVal));
882     }
883
884     return bRetVal;
885   } // delete
886

887   // ----------------------------------------------------------
888

889   /**
890    * Get path_logo field from k_workareas table
891    * @param oConn JDCConnection
892    * @param sWrkAId String GUID of WorkArea
893    * @return String Value of field path_logo
894    * @throws SQLException
895    */

896   public static String JavaDoc getPath (JDCConnection oConn, String JavaDoc sWrkAId) throws SQLException JavaDoc {
897     String JavaDoc sWrkAPath;
898
899     if (DebugFile.trace) {
900       DebugFile.writeln("Begin WorkArea.getPath([Connection], " + sWrkAId + ")");
901       DebugFile.incIdent();
902     }
903
904     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT " + DB.path_logo + " FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
905     oStmt.setString(1, sWrkAId);
906     ResultSet JavaDoc oRSet = oStmt.executeQuery();
907     if (oRSet.next())
908       sWrkAPath = oRSet.getString(1);
909     else
910       sWrkAPath = null;
911     oRSet.close();
912     oRSet = null;
913     oStmt.close();
914
915     if (DebugFile.trace) {
916       DebugFile.decIdent();
917       DebugFile.writeln("End WorkArea.getPath() : " + (sWrkAPath!=null ? sWrkAPath : "null"));
918     }
919
920     return sWrkAPath;
921   } // getPath
922

923   // ----------------------------------------------------------
924

925   public static boolean isAdmin(JDCConnection oConn, String JavaDoc guWorkArea, String JavaDoc sUserId) throws SQLException JavaDoc {
926     int iIsAdmin;
927     CallableStatement JavaDoc oCall;
928     PreparedStatement JavaDoc oStmt;
929     ResultSet JavaDoc oRSet;
930
931     if (DebugFile.trace) {
932       DebugFile.writeln("Begin WorkArea.isAdmin([Connection], " + guWorkArea + "," + sUserId + ")");
933       DebugFile.incIdent();
934     }
935
936     switch (oConn.getDataBaseProduct()) {
937
938       case JDCConnection.DBMS_MSSQL:
939       case JDCConnection.DBMS_ORACLE:
940
941         if (DebugFile.trace)
942           DebugFile.writeln("Connection.prepareCall({ call k_is_workarea_admin ('" + guWorkArea + "','" + sUserId + "',?)})");
943
944         oCall = oConn.prepareCall("{ call k_is_workarea_admin (?,?,?)}");
945
946         oCall.setString(1, guWorkArea);
947         oCall.setString(2, sUserId);
948         oCall.registerOutParameter(3, Types.INTEGER);
949         oCall.execute();
950         iIsAdmin = oCall.getInt(3);
951         oCall.close();
952         break;
953
954       default:
955
956         if (DebugFile.trace)
957           DebugFile.writeln("Connection.prepareStatement(SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_admins + " AND x." + DB.gu_user + "='" + sUserId + "' AND w." + DB.gu_workarea + "='" + guWorkArea + "')");
958
959         oStmt = oConn.prepareStatement("SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_admins + " AND x." + DB.gu_user + "=? AND w." + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
960         oStmt.setString(1, sUserId);
961         oStmt.setString(2, guWorkArea);
962         oRSet = oStmt.executeQuery();
963         if (oRSet.next())
964           iIsAdmin = 1;
965         else
966           iIsAdmin = 0;
967         oRSet.close();
968         oStmt.close();
969         break;
970     } // end switch
971

972     if (DebugFile.trace) {
973       DebugFile.decIdent();
974       DebugFile.writeln("End WorkArea.isAdmin() : " + String.valueOf(0!=iIsAdmin));
975     }
976
977     return (0!=iIsAdmin);
978   } // isAdmin()
979

980   // ----------------------------------------------------------
981

982   public static boolean isPowerUser(JDCConnection oConn, String JavaDoc guWorkArea, String JavaDoc sUserId) throws SQLException JavaDoc {
983     int iIsPowerUser;
984     CallableStatement JavaDoc oCall;
985     PreparedStatement JavaDoc oStmt;
986     ResultSet JavaDoc oRSet;
987
988     if (DebugFile.trace) {
989       DebugFile.writeln("Begin WorkArea.isPowerUser([Connection], " + guWorkArea + "," + sUserId + ")");
990       DebugFile.incIdent();
991     }
992
993     switch (oConn.getDataBaseProduct()) {
994
995       case JDCConnection.DBMS_MSSQL:
996       case JDCConnection.DBMS_ORACLE:
997
998         if (DebugFile.trace)
999           DebugFile.writeln("Connection.prepareCall({ call k_is_workarea_poweruser ('" + guWorkArea + "','" + sUserId + "',?)})");
1000
1001        oCall = oConn.prepareCall("{ call k_is_workarea_poweruser (?,?,?)}");
1002
1003        oCall.setString(1, guWorkArea);
1004        oCall.setString(2, sUserId);
1005        oCall.registerOutParameter(3, Types.INTEGER);
1006        oCall.execute();
1007        iIsPowerUser = oCall.getInt(3);
1008        oCall.close();
1009        break;
1010
1011      default:
1012
1013        if (DebugFile.trace)
1014          DebugFile.writeln("Connection.prepareStatement(SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_powusers + " AND x." + DB.gu_user + "='" + sUserId + "' AND w." + DB.gu_workarea + "='" + guWorkArea + "')");
1015
1016        oStmt = oConn.prepareStatement("SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_powusers + " AND x." + DB.gu_user + "=? AND w." + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
1017        oStmt.setString(1, sUserId);
1018        oStmt.setString(2, guWorkArea);
1019        oRSet = oStmt.executeQuery();
1020        if (oRSet.next())
1021          iIsPowerUser = 1;
1022        else
1023          iIsPowerUser = 0;
1024        oRSet.close();
1025        oStmt.close();
1026        break;
1027    } // end switch
1028

1029    if (DebugFile.trace) {
1030      DebugFile.decIdent();
1031      DebugFile.writeln("End WorkArea.isPowerUser() : " + String.valueOf(0!=iIsPowerUser));
1032    }
1033
1034    return (0!=iIsPowerUser);
1035
1036  } // isPowerUser()
1037

1038  // ----------------------------------------------------------
1039

1040  public static boolean isUser(JDCConnection oConn, String JavaDoc guWorkArea, String JavaDoc sUserId) throws SQLException JavaDoc {
1041    int iIsUser;
1042    CallableStatement JavaDoc oCall;
1043    PreparedStatement JavaDoc oStmt;
1044    ResultSet JavaDoc oRSet;
1045
1046    if (DebugFile.trace) {
1047      DebugFile.writeln("Begin WorkArea.isUser([Connection], " + guWorkArea + "," + sUserId + ")");
1048      DebugFile.incIdent();
1049    }
1050
1051    switch (oConn.getDataBaseProduct()) {
1052
1053      case JDCConnection.DBMS_MSSQL:
1054      case JDCConnection.DBMS_ORACLE:
1055
1056        oCall = oConn.prepareCall("{ call k_is_workarea_user (?,?,?)}");
1057
1058        oCall.setString(1, guWorkArea);
1059        oCall.setString(2, sUserId);
1060        oCall.registerOutParameter(3, Types.INTEGER);
1061        oCall.execute();
1062        iIsUser = oCall.getInt(3);
1063        oCall.close();
1064        break;
1065      default:
1066        oStmt = oConn.prepareStatement("SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_users + " AND x." + DB.gu_user + "=? AND w." + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
1067        oStmt.setString(1, sUserId);
1068        oStmt.setString(2, guWorkArea);
1069        oRSet = oStmt.executeQuery();
1070        if (oRSet.next())
1071          iIsUser = 1;
1072        else
1073          iIsUser = 0;
1074        oRSet.close();
1075        oStmt.close();
1076        break;
1077    } // end switch
1078

1079    if (DebugFile.trace) {
1080      DebugFile.decIdent();
1081      DebugFile.writeln("End WorkArea.isUser() : " + String.valueOf(0!=iIsUser));
1082    }
1083
1084    return (0!=iIsUser);
1085  } // iIsUser()
1086

1087  // ----------------------------------------------------------
1088

1089  public static boolean isGuest(JDCConnection oConn, String JavaDoc guWorkArea, String JavaDoc sUserId) throws SQLException JavaDoc {
1090    int iIsGuest;
1091    CallableStatement JavaDoc oCall;
1092    PreparedStatement JavaDoc oStmt;
1093    ResultSet JavaDoc oRSet;
1094
1095    if (DebugFile.trace) {
1096      DebugFile.writeln("Begin WorkArea.isGuest([Connection], " + guWorkArea + "," + sUserId + ")");
1097      DebugFile.incIdent();
1098    }
1099
1100    switch (oConn.getDataBaseProduct()) {
1101
1102      case JDCConnection.DBMS_ORACLE:
1103
1104        if (DebugFile.trace)
1105          DebugFile.writeln("Connection.prepareCall({ call k_is_workarea_guest ('" + guWorkArea + "','" + sUserId + "',?)})");
1106
1107        oCall = oConn.prepareCall("{ call k_is_workarea_guest (?,?,?)}");
1108
1109        oCall.setString(1, guWorkArea);
1110        oCall.setString(2, sUserId);
1111        oCall.registerOutParameter(3, Types.DECIMAL);
1112        oCall.execute();
1113        iIsGuest = oCall.getBigDecimal(3).intValue();
1114        oCall.close();
1115        break;
1116
1117      case JDCConnection.DBMS_MSSQL:
1118
1119        if (DebugFile.trace)
1120          DebugFile.writeln("Connection.prepareCall({ call k_is_workarea_guest ('" + guWorkArea + "','" + sUserId + "',?)})");
1121
1122        oCall = oConn.prepareCall("{ call k_is_workarea_guest (?,?,?)}");
1123
1124        oCall.setString(1, guWorkArea);
1125        oCall.setString(2, sUserId);
1126        oCall.registerOutParameter(3, Types.INTEGER);
1127        oCall.execute();
1128        iIsGuest = oCall.getInt(3);
1129        oCall.close();
1130        break;
1131
1132      default:
1133
1134        if (DebugFile.trace)
1135          DebugFile.writeln("Connection.prepareStatement(SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_guests + " AND x." + DB.gu_user + "='" + sUserId + "' AND w." + DB.gu_workarea + "='" + guWorkArea + "')");
1136
1137        oStmt = oConn.prepareStatement("SELECT x." + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " x, " + DB.k_x_app_workarea + " w WHERE x." + DB.gu_acl_group + "=w." + DB.gu_guests + " AND x." + DB.gu_user + "=? AND w." + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
1138        oStmt.setString(1, sUserId);
1139        oStmt.setString(2, guWorkArea);
1140        oRSet = oStmt.executeQuery();
1141        if (oRSet.next())
1142          iIsGuest = 1;
1143        else
1144          iIsGuest = 0;
1145        oRSet.close();
1146        oStmt.close();
1147        break;
1148    } // end switch
1149

1150    if (DebugFile.trace) {
1151      DebugFile.decIdent();
1152      DebugFile.writeln("End WorkArea.isGuest() : " + String.valueOf(0!=iIsGuest));
1153    }
1154
1155    return (0!=iIsGuest);
1156  } // iIsGuest()
1157

1158  // ----------------------------------------------------------
1159

1160  public static int getUserAppMask(JDCConnection oConn, String JavaDoc guWorkArea, String JavaDoc sUserId) throws SQLException JavaDoc {
1161
1162    if (DebugFile.trace) {
1163      DebugFile.writeln("Begin WorkArea.getUserAppMask([Connection], " + guWorkArea + "," + sUserId + ")");
1164      DebugFile.incIdent();
1165    }
1166
1167    DBSubset oApps = new DBSubset(DB.k_x_app_workarea,
1168                                  DB.id_app + "," + DB.gu_admins + "," + DB.gu_powusers + "," + DB.gu_users + "," + DB.gu_guests + "," + DB.gu_other,
1169                                  DB.gu_workarea + "=?", 30);
1170    int iApps = oApps.load(oConn, new Object JavaDoc[] { guWorkArea });
1171    int iAppMask = 0;
1172    String JavaDoc sGrp;
1173
1174    if (DebugFile.trace)
1175      DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + sUserId + "')");
1176
1177    PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT " + DB.gu_acl_group + " FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
1178
1179    try { oStmt.setQueryTimeout(10); } catch (SQLException JavaDoc sqle) {}
1180
1181    oStmt.setString(1, sUserId);
1182
1183    ResultSet JavaDoc oRSet = oStmt.executeQuery();
1184
1185    while (oRSet.next()) {
1186      sGrp = oRSet.getString(1);
1187      for (int a=0; a<iApps; a++)
1188        if (sGrp.equals(oApps.get(1,a)) || sGrp.equals(oApps.get(2,a)) || sGrp.equals(oApps.get(3,a)) || sGrp.equals(oApps.get(4,a)) || sGrp.equals(oApps.get(5,a)))
1189          iAppMask |= (1<<oApps.getInt(0,a));
1190    } // wend
1191
oRSet.close();
1192    oStmt.close();
1193
1194    if (DebugFile.trace) {
1195      DebugFile.decIdent();
1196      DebugFile.writeln("End WorkArea.getUserAppMask() : " + String.valueOf(iAppMask));
1197    }
1198
1199    return iAppMask;
1200  } // getUserAppMask()
1201

1202  // ----------------------------------------------------------
1203

1204  public static String JavaDoc getIdFromName(JDCConnection oConn, int iDomainId, String JavaDoc sWorkAreaNm) throws SQLException JavaDoc {
1205    PreparedStatement JavaDoc oStmt;
1206    ResultSet JavaDoc oRSet;
1207    String JavaDoc sRetVal;
1208
1209    if (DebugFile.trace) {
1210      DebugFile.writeln("Begin WorkArea.getIdFromName([Connection], " + String.valueOf(iDomainId) + "," + sWorkAreaNm + ")");
1211      DebugFile.incIdent();
1212    }
1213
1214    switch (oConn.getDataBaseProduct()) {
1215
1216      case JDCConnection.DBMS_MSSQL:
1217      case JDCConnection.DBMS_ORACLE:
1218        sRetVal = getUIdFromName(oConn, new Integer JavaDoc(iDomainId), sWorkAreaNm, "k_get_workarea_id");
1219        break;
1220
1221      default:
1222        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_workarea+ " FROM " + DB.k_workareas + " WHERE " + DB.nm_workarea + "='" + sWorkAreaNm + "' AND " + DB.id_domain + "=" + String.valueOf(iDomainId) +" AND " + DB.bo_active + "<>0)");
1223
1224        oStmt = oConn.prepareStatement("SELECT " + DB.gu_workarea+ " FROM " + DB.k_workareas + " WHERE " + DB.nm_workarea + "=? AND " + DB.id_domain + "=? AND " + DB.bo_active + "<>0", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
1225        oStmt.setString(1, sWorkAreaNm);
1226        oStmt.setInt(2, iDomainId);
1227        oRSet = oStmt.executeQuery();
1228        if (oRSet.next())
1229          sRetVal = oRSet.getString(1);
1230        else
1231          sRetVal = null;
1232        oRSet.close();
1233        oStmt.close();
1234        break;
1235    }
1236
1237    if (DebugFile.trace) {
1238      DebugFile.decIdent();
1239      DebugFile.writeln("End WorkArea.getIdFromName() : " + sRetVal);
1240    }
1241
1242    return sRetVal;
1243  } // getIdFromName
1244

1245  // ----------------------------------------------------------
1246

1247  public static final short ClassId = 5;
1248}
1249
Popular Tags