Project

General

Profile

« Previous | Next » 

Revision 2168

Added by Jing Tao about 20 years ago

Revised the api and ecogrid can use it easily.

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
230 230
    {
231 231
      // get query and qformat
232 232
      String xmlquery = ((String[])params.get("query"))[0];
233
      xmlquery = transformQuery(xmlquery);
233

  
234 234
      MetaCatUtil.debugMessage("xmlquery: " + xmlquery, 30);
235 235
      String qformat = ((String[])params.get("qformat"))[0];
236 236
      MetaCatUtil.debugMessage("qformat: " + qformat, 30);
237
      // Get the XML query and covert it into a SQL statment
238
      QuerySpecification qspec = null;
239
      if ( xmlquery != null)
240
      {
241
         xmlquery = transformQuery(xmlquery);
242
         try
243
         {
244
           qspec = new QuerySpecification(xmlquery,
245
                                          parserName,
246
                                          MetaCatUtil.getOption("accNumSeparator"));
247
         }
248
         catch (Exception ee)
249
         {
250
           MetaCatUtil.debugMessage("erro to generate QuerySpecification object"
251
                                    +" in DBQuery.findDocuments"
252
                                    + ee.getMessage(), 30);
253
         }
254
      }
237 255

  
256

  
257

  
238 258
      if (qformat != null && qformat.equals(MetaCatServlet.XMLFORMAT))
239 259
      {
240 260
        //xml format
241 261
        response.setContentType("text/xml");
242
        createResultDocument(xmlquery, out, user, groups, useXMLIndex);
262
        createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex);
243 263
      }//if
244 264
      else
245 265
      {
246 266
        //knb format, in this case we will get whole result and sent it out
247 267
        response.setContentType("text/html");
248 268
        PrintWriter nonout = null;
249
        StringBuffer xml =
250
              createResultDocument(xmlquery, nonout, user, groups, useXMLIndex);
269
        StringBuffer xml = createResultDocument(xmlquery, qspec, nonout, user,
270
                                                groups, useXMLIndex);
251 271
        //transfer the xml to html
252 272
        try
253 273
        {
......
271 291

  
272 292
  /*
273 293
   * Transforms a hashtable of documents to an xml or html result and sent
274
   * the content to outputstream. Keep going untill hastable is empty. stop it.   *
294
   * the content to outputstream. Keep going untill hastable is empty. stop it.
295
   * add the QuerySpecification as parameter is for ecogrid. But it is duplicate
296
   * to xmlquery String
275 297
   */
276
  private StringBuffer createResultDocument(String xmlquery, PrintWriter out,
298
  public StringBuffer createResultDocument(String xmlquery,
299
                                            QuerySpecification qspec,
300
                                            PrintWriter out,
277 301
                                            String user, String[] groups,
278 302
                                            boolean useXMLIndex)
279 303
  {
......
288 312
    {
289 313
      out.println(resultset.toString());
290 314
    }
291
    try
315
    if (qspec != null)
292 316
    {
293
      // Get the XML query and covert it into a SQL statment
294
      QuerySpecification qspec = new QuerySpecification(xmlquery,
295
                   parserName, MetaCatUtil.getOption("accNumSeparator"));
296
      //checkout the dbconnection
297
      dbconn = DBConnectionPool.getDBConnection("DBQuery.findDocuments");
298
      serialNumber = dbconn.getCheckOutSerialNumber();
317
      try
318
      {
299 319

  
300
      //print out the search result
301
      // search the doc list
302
      resultset = findResultDoclist(qspec, resultset, out, user, groups,
303
                                    dbconn, useXMLIndex);
320
        //checkout the dbconnection
321
        dbconn = DBConnectionPool.getDBConnection("DBQuery.findDocuments");
322
        serialNumber = dbconn.getCheckOutSerialNumber();
304 323

  
324
        //print out the search result
325
        // search the doc list
326
        resultset = findResultDoclist(qspec, resultset, out, user, groups,
327
                                      dbconn, useXMLIndex);
305 328

  
306
    }//try
307
    catch (IOException ioe)
308
    {
309
       MetaCatUtil.debugMessage("IO error in DBQuery.findDocuments:", 30);
310
       MetaCatUtil.debugMessage(ioe.getMessage(), 30);
329
      } //try
330
      catch (IOException ioe)
331
      {
332
        MetaCatUtil.debugMessage("IO error in DBQuery.findDocuments:", 30);
333
        MetaCatUtil.debugMessage(ioe.getMessage(), 30);
311 334

  
312
    }
313
    catch (SQLException e)
314
    {
315
      MetaCatUtil.debugMessage("SQL Error in DBQuery.findDocuments: "
316
                   + e.getMessage(), 30);
317
    }
318
    catch (Exception ee)
319
    {
320
      MetaCatUtil.debugMessage("Exception in DBQuery.findDocuments: "
321
                   + ee.getMessage(), 30);
322
    }
323
    finally
324
    {
325
       DBConnectionPool.returnDBConnection(dbconn, serialNumber);
326
    }//finally
335
      }
336
      catch (SQLException e)
337
      {
338
        MetaCatUtil.debugMessage("SQL Error in DBQuery.findDocuments: "
339
                                 + e.getMessage(), 30);
340
      }
341
      catch (Exception ee)
342
      {
343
        MetaCatUtil.debugMessage("Exception in DBQuery.findDocuments: "
344
                                 + ee.getMessage(), 30);
345
      }
346
      finally
347
      {
348
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
349
      } //finally
350
    }//if
327 351
    String closeRestultset = "</resultset>";
328 352
    resultset.append(closeRestultset);
329 353
    if (out != null)
330 354
    {
331 355
      out.println(closeRestultset);
332 356
    }
357

  
333 358
    return resultset;
334 359
  }//createResultDocuments
335 360

  

Also available in: Unified diff