Project

General

Profile

« Previous | Next » 

Revision 3308

Added by Jing Tao almost 17 years ago

Merge the getting return fields for both elements and attributes.

View differences:

DBQuery.java
1143 1143
                   + (docListResultEnd - extendedQueryEnd));
1144 1144
           }
1145 1145

  
1146
           // get attribures return
1147
           double startGetAttribute = System.currentTimeMillis()/1000;
1148
           docListResult = getAttributeValueForReturn(qspec,
1149
                           docListResult, doclist.toString(), useXMLIndex);
1150
           double endGetAttribute = System.currentTimeMillis()/1000;
1151
           logMetacat.warn(
1152
                   "Time to get attribute return value after"
1153
                   + " execute extended query: "
1154
                   + (endGetAttribute - startGetAttribute));
1155
           MetaCatUtil.writeDebugToFile(
1156
                   "Get attribute return field "
1157
                   + (endGetAttribute - startGetAttribute));
1158
           MetaCatUtil.writeDebugToDelimiteredFile(" "+ (endGetAttribute - startGetAttribute), false);
1146
         
1159 1147
           
1160 1148
           
1161 1149
       }//if doclist lenght is great than zero
......
1334 1322
        return enumVector;
1335 1323
    }
1336 1324

  
1337
    /*
1338
     * A method to return search result after running a query which return
1339
     * field have attribue
1340
     */
1341
    private ResultDocumentSet getAttributeValueForReturn(QuerySpecification squery,
1342
            ResultDocumentSet docInformationList, String docList, boolean useXMLIndex)
1343
    {
1344
        StringBuffer XML = null;
1345
        String sql = null;
1346
        DBConnection dbconn = null;
1347
        PreparedStatement pstmt = null;
1348
        ResultSet rs = null;
1349
        int serialNumber = -1;
1350
        boolean tableHasRows = false;
1325
  
1351 1326

  
1352
        //check the parameter
1353
        if (squery == null || docList == null || docList.length() < 0) { return docInformationList; }
1354

  
1355
        // if has attribute as return field
1356
        if (squery.containsAttributeReturnField()) {
1357
            sql = squery.printAttributeQuery(docList, useXMLIndex);
1358
            try {
1359
                dbconn = DBConnectionPool
1360
                        .getDBConnection("DBQuery.getAttributeValue");
1361
                serialNumber = dbconn.getCheckOutSerialNumber();
1362
                pstmt = dbconn.prepareStatement(sql);
1363
                pstmt.execute();
1364
                rs = pstmt.getResultSet();
1365
                tableHasRows = rs.next();
1366
                while (tableHasRows) {
1367
                    String docid = rs.getString(1).trim();
1368
                    String fieldname = rs.getString(2);
1369
                    String fielddata = rs.getString(3);
1370
                    String attirbuteName = rs.getString(4);
1371
                    XML = new StringBuffer();
1372

  
1373
                    XML.append("<param name=\"");
1374
                    XML.append(fieldname);
1375
                    XML.append("/");
1376
                    XML.append(QuerySpecification.ATTRIBUTESYMBOL);
1377
                    XML.append(attirbuteName);
1378
                    XML.append("\">");
1379
                    XML.append(fielddata);
1380
                    XML.append("</param>");
1381
                    tableHasRows = rs.next();
1382

  
1383
                    if (docInformationList.containsDocid(docid)) {
1384
                        String removedelement = (String) docInformationList
1385
                                .remove(docid);
1386
                        docInformationList.put(docid, removedelement
1387
                                + XML.toString());
1388
                    } else {
1389
                        docInformationList.put(docid, XML.toString());
1390
                    }
1391
                }//while
1392
                rs.close();
1393
                pstmt.close();
1394
            } catch (Exception se) {
1395
                logMetacat.error(
1396
                        "Error in DBQuery.getAttributeValue1: "
1397
                                + se.getMessage());
1398
            } finally {
1399
                try {
1400
                    pstmt.close();
1401
                }//try
1402
                catch (SQLException sqlE) {
1403
                    logMetacat.error(
1404
                            "Error in DBQuery.getAttributeValue2: "
1405
                                    + sqlE.getMessage());
1406
                }//catch
1407
                finally {
1408
                    DBConnectionPool.returnDBConnection(dbconn, serialNumber);
1409
                }//finally
1410
            }//finally
1411
        }//if
1412
        return docInformationList;
1413

  
1414
    }
1415

  
1416 1327
    /*
1417 1328
     * A method to create a query to get owner's docid list
1418 1329
     */

Also available in: Unified diff