KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > hipergate > QueryByForm


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.hipergate;
34
35 import java.io.OutputStream JavaDoc;
36 import java.io.UnsupportedEncodingException JavaDoc;
37
38 import java.sql.Connection JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.sql.Types JavaDoc;
41
42 import java.util.Vector JavaDoc;
43 import java.lang.StringBuffer JavaDoc;
44
45 import org.w3c.dom.Node JavaDoc;
46 import org.w3c.dom.Element JavaDoc;
47 import dom.DOMDocument;
48
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50
51 import com.knowgate.jdc.JDCConnection;
52 import com.knowgate.dataobjs.DBSubset;
53 import com.knowgate.debug.DebugFile;
54
55 import com.knowgate.dataobjs.DB;
56 import com.knowgate.dataobjs.DBTable;
57 import com.knowgate.dataobjs.DBColumn;
58 import com.knowgate.dataobjs.DBPersist;
59
60 import com.knowgate.http.Cookies;
61
62 import com.knowgate.crm.DistributionList;
63
64 /**
65  * <p>Query By Form XML parser and SQL composer.</p>
66  * @author Sergio Montoro Ten
67  * @version 3.0
68  */

69
70 public class QueryByForm extends DBPersist {
71
72   private DBTable oBaseTable;
73   String JavaDoc sAlias;
74   DOMDocument oXMLDoc;
75
76
77   // ----------------------------------------------------------
78

79   /**
80    * <p>Create an empty query by parsing an XML definition file.</p>
81    * Input file must be encoded as ISO-8859-1
82    * @param sQBFURI URI for query specification XML file (ej. file:///opt/storage/qbf/duties.xml)
83    * @throws ClassNotFoundException
84    * @throws IllegalAccessException
85    */

86
87   public QueryByForm(String JavaDoc sQBFURI)
88     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, Exception JavaDoc {
89     super(DB.k_queries, "QueryByForm");
90     parseURI(sQBFURI);
91   }
92
93   // ----------------------------------------------------------
94

95   /**
96    * <p>Create an empty query by parsing an XML definition file.</p>
97    * Input file must be encoded as ISO-8859-1
98    * @param sQBFURI URI for query specification XML file (ej. file:///opt/storage/qbf/duties.xml)
99    * @throws ClassNotFoundException
100    * @throws IllegalAccessException
101    * @throws UnsupportedEncodingException
102    * @since 3.0
103    */

104
105   public QueryByForm(String JavaDoc sQBFURI, String JavaDoc sEncoding)
106     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc,
107            UnsupportedEncodingException JavaDoc, Exception JavaDoc {
108     super(DB.k_queries, "QueryByForm");
109     parseURI(sQBFURI, sEncoding);
110   }
111
112   /**
113    * <p>Load a query from k_queries table.</p>
114    * @param oConn Database Connection
115    * @param sBaseTable Query base table or view &lt;baseobject&gt; tag from XML query specification.
116    * @param sTableAlias A base table alias for SQL fields
117    * @param sQueryGUID Query GUID at k_queries table
118    * @throws SQLException
119    */

120   public QueryByForm(JDCConnection oConn, String JavaDoc sBaseTable, String JavaDoc sTableAlias, String JavaDoc sQueryGUID) throws SQLException JavaDoc {
121     super(DB.k_queries, "QueryByForm");
122
123     oBaseTable = new DBTable(oConn.getCatalog(), "dbo", sBaseTable, 1);
124     oBaseTable.readColumns(oConn, oConn.getMetaData());
125     sAlias = sTableAlias;
126
127     Object JavaDoc aQry[] = { sQueryGUID };
128
129     load(oConn, aQry);
130   }
131
132   // ----------------------------------------------------------
133

134   /**
135    * <p>Parse query XML specification file.</p>
136    * @param sURI URI for query specification XML file
137    * @param sEncoding Character encoding used by XML input file
138    * @throws ClassNotFoundException
139    * @throws IllegalAccessException
140    * @throws UnsupportedEncodingException
141    * @since 3.0
142    */

143   public void parseURI(String JavaDoc sURI, String JavaDoc sEncoding)
144     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, Exception JavaDoc {
145
146     if (DebugFile.trace) {
147       DebugFile.writeln("Begin QueryByForm.parseURI(" + sURI + "," + sEncoding + ")");
148       DebugFile.incIdent();
149     }
150
151     oXMLDoc = new DOMDocument();
152     try {
153       oXMLDoc.parseURI(sURI, sEncoding);
154     }
155     catch (Exception JavaDoc xcpt) {
156       oXMLDoc = null;
157       throw new Exception JavaDoc(xcpt.getMessage(), xcpt.getCause());
158     }
159
160     if (DebugFile.trace) {
161       DebugFile.decIdent();
162       DebugFile.writeln("End QueryByForm.parseURI()");
163     }
164   } // parseURI()
165

166   // ----------------------------------------------------------
167

168   /**
169    * <p>Parse query XML specification file.</p>
170    * @param sURI URI for query specification XML file
171    * @throws ClassNotFoundException
172    * @throws IllegalAccessException
173    */

174   public void parseURI(String JavaDoc sURI)
175     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, Exception JavaDoc {
176     parseURI(sURI, null);
177   }
178
179   // ----------------------------------------------------------
180

181   /**
182    * @return DOMDocument object for parsed XML file.
183    */

184   public DOMDocument getDocument() {
185     return oXMLDoc;
186   }
187
188   // ----------------------------------------------------------
189

190   /**
191    * @return &lt;action&gt; tag from XML query specification.
192    * If tag &lt;action&gt; is not found then <b>null</b> is returned.
193    */

194   public String JavaDoc getAction() {
195     if (DebugFile.trace) {
196       DebugFile.writeln("Begin QueryByForm.getAction()");
197       DebugFile.incIdent();
198     }
199
200     String JavaDoc sAction;
201
202     // Obtener una referencia al nodo raiz del arbol DOM
203
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
204     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
205
206     Element JavaDoc oAction = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "action");
207
208     if (null==oAction)
209       sAction = null;
210     else
211       sAction = oXMLDoc.getTextValue(oAction);
212
213     if (DebugFile.trace) {
214       DebugFile.decIdent();
215       DebugFile.writeln("End QueryByForm.getAction() : " + (sAction!=null ? sAction : "null"));
216     }
217
218     return sAction;
219   } // getAction()
220

221   // ----------------------------------------------------------
222

223   /**
224    * @return &lt;baseobject&gt; node contents.<br>
225    * If tag &lt;baseobject&gt; is not found then <b>null</b> is returned.
226    */

227   public String JavaDoc getBaseObject() {
228     if (DebugFile.trace) {
229       DebugFile.writeln("Begin QueryByForm.getBaseObject()");
230       DebugFile.incIdent();
231     }
232
233     String JavaDoc sBaseObj;
234
235     // Obtener una referencia al nodo raiz del arbol DOM
236
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
237     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
238
239     Element JavaDoc oBaseObject = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "baseobject");
240
241     if (null==oBaseObject)
242       sBaseObj = null;
243     else
244       sBaseObj = oXMLDoc.getTextValue(oBaseObject);
245
246     if (DebugFile.trace) {
247       DebugFile.decIdent();
248       DebugFile.writeln("End QueryByForm.getBaseObject() : " + (sBaseObj!=null ? sBaseObj : "null"));
249     }
250
251     return sBaseObj;
252   } // getBaseObject()
253

254   // ----------------------------------------------------------
255

256   /**
257    * <p>Get query base filter instantiated for given HttpServletRequest parameters.</p>
258    * <p>Base filters are neccesary for separating data belonging to an specific
259    * workarea for data belonging to other workareas.<br>
260    * Typically every query specification have a base filter.<br>
261    * The base filter may contain to types of wildcards ${cookie.<i>name</i>} and ${param.<i>name</i>}<br>
262    * When one of this wildcards in encountered at base filter specification it is substituded at runtime
263    * by the matching HttpServletRequest Cookie or Parameter value.</p>
264    * @param oReq HttpServletRequest containing Cookies and Parameters to be substituted at base filter.
265    * @return &lt;basefilter&gt; tag from XML query specification with
266    * ${cookie.<i>name</i>} and ${param.<i>name</i>} wildcards substituded by
267    * HttpServletRequest getCookies and getParameters values.
268    */

269   public String JavaDoc getBaseFilter(HttpServletRequest JavaDoc oReq) {
270     if (DebugFile.trace) {
271       DebugFile.writeln("Begin QueryByForm.getBaseFilter([HttpServletRequest])");
272       DebugFile.incIdent();
273     }
274
275     // Obtener una referencia al nodo raiz del arbol DOM
276
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
277     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
278
279     Element JavaDoc oBaseObject = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "basefilter");
280     String JavaDoc sFilter = oXMLDoc.getTextValue(oBaseObject);
281
282     int iLength = sFilter.length();
283     StringBuffer JavaDoc oFilter = new StringBuffer JavaDoc(iLength);
284     int iClose;
285     int iDot;
286     String JavaDoc sItem;
287
288     for (int c=0; c<iLength; c++) {
289       if (sFilter.charAt(c)=='$' && c<iLength-1) {
290         if (sFilter.charAt(c+1)=='{') {
291           iDot = sFilter.indexOf('.', c);
292           iClose = sFilter.indexOf('}', iDot);
293           sItem = sFilter.substring(iDot+1, iClose);
294
295           if (sFilter.substring(c+2,iDot).equals("cookie"))
296             oFilter.append(Cookies.getCookie(oReq, sItem, ""));
297           else if (sFilter.substring(c+2,iDot).equals("param"))
298             oFilter.append(oReq.getParameter(sItem));
299
300           c = iClose;
301         }
302       } // fi(sFilter[c]=='{')
303
else
304         oFilter.append(sFilter.charAt(c));
305       } // next (c)
306

307     if (DebugFile.trace) {
308       DebugFile.decIdent();
309       DebugFile.writeln("End QueryByForm.getBaseFilter() : " + oFilter.toString());
310     }
311
312     return oFilter.toString();
313   } // getBaseFilter()
314

315   // ----------------------------------------------------------
316

317   /**
318    * @return &lt;method&gt; tag from XML query specification.<br>
319    * If tag &lt;method&gt; is not found then <b>null</b> is returned.
320    * @throws NullPointerException if XML document was not previously set on the constructor or by calling parseURI()
321    */

322   public String JavaDoc getMethod() {
323     if (DebugFile.trace) {
324       DebugFile.writeln("Begin QueryByForm.getMethod()");
325       DebugFile.incIdent();
326     }
327
328     if (null==oXMLDoc) {
329       if (DebugFile.trace) DebugFile.decIdent();
330       throw new NullPointerException JavaDoc("QueryByForm.getMethod() - XML document not set");
331     }
332
333     String JavaDoc sMethod;
334
335     // Obtener una referencia al nodo raiz del arbol DOM
336
Node JavaDoc oRootNode= oXMLDoc.getRootNode();
337     Node JavaDoc oTopNode = oRootNode.getFirstChild();
338     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
339
340     Element JavaDoc oMethod = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "method");
341
342     if (null==oMethod)
343       sMethod = null;
344     else
345       sMethod = oXMLDoc.getTextValue(oMethod);
346
347     if (DebugFile.trace) {
348       DebugFile.decIdent();
349       DebugFile.writeln("End QueryByForm.getMethod() : " + (sMethod!=null ? sMethod : "null"));
350     }
351
352     return sMethod;
353   } // getMethod()
354

355   // ----------------------------------------------------------
356

357   /**
358    * @return &lt;title_<i>xx</i>&gt; tag from XML query specification, where xx==sLanguage<br>
359    * If not title is found for given language then "Query" text is returned.
360    * @throws NullPointerException if XML document was not previously set on the constructor or by calling parseURI()
361    */

362   public String JavaDoc getTitle(String JavaDoc sLanguage)
363     throws NullPointerException JavaDoc {
364     if (DebugFile.trace) {
365       DebugFile.writeln("Begin QueryByForm.getTitle(" + sLanguage + ")");
366       DebugFile.incIdent();
367     }
368
369     if (null==oXMLDoc) {
370       if (DebugFile.trace) DebugFile.decIdent();
371       throw new NullPointerException JavaDoc("QueryByForm.getTitle() - XML document not set");
372     }
373
374     String JavaDoc sTitle;
375
376     // Obtener una referencia al nodo raiz del arbol DOM
377
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
378     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
379
380     Element JavaDoc oTitleNode = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "title_" + sLanguage);
381
382     if (null!=oTitleNode)
383       sTitle = oXMLDoc.getTextValue(oTitleNode);
384     else
385       sTitle = "Query";
386
387     if (DebugFile.trace) {
388       DebugFile.decIdent();
389       DebugFile.writeln("End QueryByForm.getTitle() : " + sTitle);
390     }
391
392     return sTitle;
393   } // getTitle()
394

395   // ----------------------------------------------------------
396

397   /**
398    * @return Vector of org.w3c.dom.Element objects, one for each &lt;field&gt; tag
399    */

400   public Vector JavaDoc getFields() {
401     // Obtener una referencia al nodo raiz del arbol DOM
402
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
403     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
404
405     Element JavaDoc oFieldsNode = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "fields");
406
407     if (null==oFieldsNode)
408       return new Vector JavaDoc();
409     else
410       return oXMLDoc.filterChildsByName(oFieldsNode, "field");
411   } // getFields()
412

413   // ----------------------------------------------------------
414

415   /**
416    * @return Vector of org.w3c.dom.Element objects, one for each &lt;sortable&gt; tag
417    * if &lt;sortable&gt; tag is not found an empty vector is returned and no exception
418    * is thrown.
419    */

420   public Vector JavaDoc getSortable() {
421     // Obtener una referencia al nodo raiz del arbol DOM
422
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
423     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
424
425     Element JavaDoc oFieldsNode = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "sortable");
426
427     if (null==oFieldsNode)
428       return new Vector JavaDoc();
429     else
430       return oXMLDoc.filterChildsByName(oFieldsNode, "by");
431   } // getSortable()
432

433   // ----------------------------------------------------------
434

435   /**
436    * @return Vector of org.w3c.dom.Element objects, one for each &lt;column&gt; tag
437    * @throws NullPointerException If tag &lt;columns&gt; is not found
438    */

439   public Vector JavaDoc getColumns() throws NullPointerException JavaDoc {
440     // Obtener una referencia al nodo raiz del arbol DOM
441
Node JavaDoc oTopNode = oXMLDoc.getRootNode().getFirstChild();
442     if (oTopNode.getNodeName().equals("xml-stylesheet")) oTopNode = oTopNode.getNextSibling();
443
444     Element JavaDoc oFieldsNode = (Element JavaDoc) oXMLDoc.seekChildByName(oTopNode, "columns");
445
446     if (null==oFieldsNode)
447       throw new NullPointerException JavaDoc("Cannot find <columns> tag");
448
449     return oXMLDoc.filterChildsByName(oFieldsNode, "column");
450   } // getSortable()
451

452   // ----------------------------------------------------------
453

454   /**
455    * <p>Get SQL clause for a given field, comparison operator and value</p>
456    * <p>The SQL clause is composed taking into account the operator and the value type.<br>
457    * Base Object Alias is appended to each field name.<br>
458    * For strings single quotes are added (ej. alias.de_duty='Walkthrought').<br>
459    * Dates are escaped (ej. alias.dt_start>{d '2003-08-15'})</p>
460    * @param fld Field Name
461    * @param opr Comparison Operator, one of { =, <>, >, <, S, C, N, M }<br>
462    * Operators S, C, N and M are translated as follows:<br>
463    * S - alias.tx_job LIKE '%' + vle (field starts with)<br>
464    * C - alias.tx_job LIKE '%' + vle + '%' (field contains)<br>
465    * N - alias.tx_job IS NULL<br>
466    * M - alias.tx_job IS NOT NULL<br>
467    * @param vle Value for field
468    * @return SQL clause for a given field, comparison operator and value.
469    * @throws NullPointerException If field fld is not found at base table
470    */

471   private String JavaDoc getClause(String JavaDoc fld, String JavaDoc opr, String JavaDoc vle)
472     throws NullPointerException JavaDoc {
473
474   String JavaDoc ret;
475     short type;
476     DBColumn col;
477
478     col = oBaseTable.getColumnByName(fld.toLowerCase());
479
480     if (null==col)
481       throw new NullPointerException JavaDoc("Cannot find column " + fld + " on " + oBaseTable.getName());
482
483     type = col.getSqlType();
484
485     if (type==Types.VARCHAR || type==Types.CHAR || type==Types.LONGVARCHAR || type==Types.CLOB) {
486       if (opr.equals("S"))
487         ret = sAlias + "." + fld + " LIKE '" + vle + "%' ";
488       else if (opr.equals("C"))
489         ret = sAlias + "." + fld + " LIKE '%" + vle + "%' ";
490       else if (opr.equals("N"))
491         ret = sAlias + "." + fld + " IS NULL ";
492       else if (opr.equals("M"))
493         ret = sAlias + "." + fld + " IS NOT NULL ";
494       else
495         ret = sAlias + "." + fld + " " + opr + " '" + vle + "' ";
496     }
497     else if (type==Types.DATE || type==Types.TIMESTAMP) {
498       ret = sAlias + "." + fld + opr + "{ d '" + vle + "'}" + " ";
499     }
500     else {
501       ret = sAlias + "." + fld + opr + vle + " ";
502     }
503     return ret;
504   } // getClause()
505

506   // ----------------------------------------------------------
507

508   /**
509    * <p>Compose SQL WHERE clause by concatenating single clauses for each field</p>
510    * <p>&lt;basefilter&gt; clause is not included in returned String.</p>
511    * @return getClause("field1",...) [+ getClause("field2", ...) + [+ getClause("field3", ...)]]
512    * @throws NullPointerException
513    */

514
515   public String JavaDoc composeSQL() throws NullPointerException JavaDoc {
516
517     if (DebugFile.trace) {
518       DebugFile.writeln("Begin QueryByForm.composeSQL()");
519       DebugFile.incIdent();
520     }
521
522     String JavaDoc fld, opr, val, cod, qry = "";
523
524     fld = getStringNull("nm_field1","");
525     opr = getStringNull("nm_operator1","");
526     val = getStringNull("tx_value1","");
527     cod = getStringNull("vl_code1","");
528
529    if (val.length()>0 || opr.equals("N") || opr.equals("M")) {
530      qry = getClause(fld, opr, cod.length() > 0 ? cod : val);
531
532      if (!isNull("tx_condition1")) {
533        qry += " " + getString("tx_condition1") + " ";
534
535        fld = getStringNull("nm_field2","");
536        opr = getStringNull("nm_operator2","");
537        val = getStringNull("tx_value2","");
538        cod = getStringNull("vl_code2","");
539
540        if (val.length()>0 || opr.equals("N") || opr.equals("M")) {
541          qry += getClause(fld, opr, cod.length() > 0 ? cod : val);
542
543          if (!isNull("tx_condition2")) {
544            qry += " " + getString("tx_condition2") + " ";
545
546            fld = getStringNull("nm_field3", "");
547            opr = getStringNull("nm_operator3", "");
548            val = getStringNull("tx_value3", "");
549            cod = getStringNull("vl_code3", "");
550
551            qry += getClause(fld, opr, cod.length() > 0 ? cod : val);
552          } // fi (isNull("tx_condition2"))
553
} // fi (val!="" || opr=="N" || opr=="M")
554
} // fi (isNull("tx_condition1"))
555
} // // fi (val!="" || opr=="N" || opr=="M")
556

557    if (DebugFile.trace) {
558      DebugFile.decIdent();
559      DebugFile.writeln("End QueryByForm.composeSQL() : " + qry);
560    }
561
562    return qry;
563   } // composeQuery()
564

565   // ----------------------------------------------------------
566

567   /**
568    * <p>Execute query and print ResultSet to an OutputStream.</p>
569    * <p>Rows are directly fetched from database and printed to OutputStream one by one.</p>
570    * @param oConn Database Connection
571    * @param sColumnList Columns to SELECT
572    * @param sFilter Full SQL filter clause, including &lt;&gt;
573    * @param oOutStrm OutputStream for printing results.
574    * @param sShowAs Output Type<br>
575    * <table>
576    * <tr><td>TSV</td><td>Tab separated values</td><td>Columns are delimited by tabs and rows are delimited by line feeds</td></tr>
577    * <tr><td>XLS</td><td>Excel Default</td><td>Columns are delimited by ';' and rows are delimited by line feeds</td></tr>
578    * <tr><td>CSV</td><td>Comma separated values</td><td>Columns are delimited by ',' and rows are delimited by line feeds, text is qualified with double quoutes.</td></tr>
579    * </table>
580    * @throws SQLException
581    */

582   public void queryToStream(Connection JavaDoc oConn, String JavaDoc sColumnList, String JavaDoc sFilter, OutputStream JavaDoc oOutStrm, String JavaDoc sShowAs) throws SQLException JavaDoc {
583     if (DebugFile.trace) {
584       DebugFile.writeln("Begin QueryByForm.queryToStream([Connection]," + sColumnList + "," + sFilter + ", [OutputStream], " + sShowAs + ")");
585       DebugFile.incIdent();
586     }
587
588     DBSubset oDBSS = new DBSubset(getBaseObject(), sColumnList, sFilter, 100);
589
590     if (sShowAs.equalsIgnoreCase("TSV")) {
591       oDBSS.setColumnDelimiter("\t");
592       oDBSS.setRowDelimiter("\n");
593       oDBSS.setTextQualifier("");
594     }
595     else if (sShowAs.equalsIgnoreCase("XLS")) {
596       oDBSS.setColumnDelimiter(";");
597       oDBSS.setRowDelimiter("\n");
598       oDBSS.setTextQualifier("");
599     }
600     else {
601       oDBSS.setColumnDelimiter(",");
602       oDBSS.setRowDelimiter("\n");
603       oDBSS.setTextQualifier("\"");
604     }
605
606     oDBSS.print(oConn, oOutStrm);
607
608     if (DebugFile.trace) {
609       DebugFile.decIdent();
610       DebugFile.writeln("End QueryByForm.queryToStream()");
611     }
612   } // queryToStream()
613

614   // ----------------------------------------------------------
615

616   /**
617    * <p>Delete QBF instance from database</p>
618    * Dynamic Lists using this QBF will be deleted on cascade
619    * @param oConn Database Connection
620    * @param sQBFGUID GUID of QBF instance to be deleted.
621    * @throws SQLException
622    */

623   public static boolean delete(JDCConnection oConn, String JavaDoc sQBFGUID) throws SQLException JavaDoc {
624     if (DebugFile.trace) {
625       DebugFile.writeln("Begin QueryByForm.delete([Connection]," + sQBFGUID + ")");
626       DebugFile.incIdent();
627     }
628
629     DBSubset oLists = new DBSubset(DB.k_lists, DB.gu_list, DB.gu_query+"=?", 10);
630     int iLists = oLists.load(oConn, new Object JavaDoc[]{sQBFGUID});
631
632     for (int l=0; l<iLists; l++) {
633       DistributionList.delete(oConn, oLists.getString(0,l));
634     } // next
635

636     DBPersist oDBP = new DBPersist(DB.k_queries, "QueryByForm");
637
638     oDBP.put(DB.gu_query, sQBFGUID);
639
640     boolean bRetVal = oDBP.delete(oConn);
641
642     if (DebugFile.trace) {
643       DebugFile.decIdent();
644       DebugFile.writeln("End QueryByForm.delete() : " + String.valueOf(bRetVal));
645     }
646
647     return bRetVal;
648   }
649
650   // ----------------------------------------------------------
651

652 }
653
Popular Tags