Project

General

Profile

« Previous | Next » 

Revision 2663

Added by sgarg over 18 years ago

Replacing MetaCatUtil.debugMessage or MetaCatUtil.logMetacat call with logMetacat (private Logger object) call

View differences:

DBQuery.java
54 54
import javax.servlet.ServletOutputStream;
55 55
import javax.servlet.http.HttpServletResponse;
56 56

  
57
import org.apache.log4j.Logger;
57 58

  
58 59
import edu.ucsb.nceas.morpho.datapackage.Triple;
59 60
import edu.ucsb.nceas.morpho.datapackage.TripleCollection;
......
78 79

  
79 80
    private MetaCatUtil util = new MetaCatUtil();
80 81

  
82
    private Logger logMetacat = Logger.getLogger(DBQuery.class);
83

  
81 84
    /**
82 85
     * the main routine used to test the DBQuery utility.
83 86
     * <p>
......
230 233
      // get query and qformat
231 234
      String xmlquery = ((String[])params.get("query"))[0];
232 235

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

  
......
288 291
        }
289 292
        catch(Exception e)
290 293
        {
291
         MetaCatUtil.debugMessage("Error in MetaCatServlet.transformResultset:"
292
                                +e.getMessage(), 30);
294
         logMetacat.error("Error in MetaCatServlet.transformResultset:"
295
                                +e.getMessage());
293 296
         }
294 297

  
295 298
      }//else
......
336 339
      } //try
337 340
      catch (IOException ioe)
338 341
      {
339
        MetaCatUtil.debugMessage("IO error in DBQuery.findDocuments:", 30);
340
        MetaCatUtil.debugMessage(ioe.getMessage(), 30);
342
        logMetacat.error("IO error in DBQuery.findDocuments:");
343
        logMetacat.error(ioe.getMessage());
341 344

  
342 345
      }
343 346
      catch (SQLException e)
344 347
      {
345
        MetaCatUtil.debugMessage("SQL Error in DBQuery.findDocuments: "
346
                                 + e.getMessage(), 30);
348
        logMetacat.error("SQL Error in DBQuery.findDocuments: "
349
                                 + e.getMessage());
347 350
      }
348 351
      catch (Exception ee)
349 352
      {
350
        MetaCatUtil.debugMessage("Exception in DBQuery.findDocuments: "
351
                                 + ee.getMessage(), 30);
353
        logMetacat.error("Exception in DBQuery.findDocuments: "
354
                                 + ee.getMessage());
352 355
      }
353 356
      finally
354 357
      {
......
404 407
      int rev = 0;
405 408
      String query = qspec.printSQL(useXMLIndex);
406 409
      String ownerQuery = getOwnerQuery(user);
407
      MetaCatUtil.debugMessage("query: " + query, 30);
408
      //MetaCatUtil.debugMessage("query: "+ownerQuery, 30);
410
      logMetacat.info("query: " + query);
411
      //logMetacat.info("query: "+ownerQuery);
409 412
      // if query is not the owner query, we need to check the permission
410 413
      // otherwise we don't need (owner has all permission by default)
411 414
      if (!query.equals(ownerQuery))
......
420 423
        } else {
421 424
            query = query + accessQuery.substring(4, accessQuery.length());
422 425
        }
423
        MetaCatUtil.debugMessage(" final query: " + query, 30);
426
        logMetacat.warn(" final query: " + query);
424 427
      }
425 428

  
426 429
      double startTime = System.currentTimeMillis() / 1000;
......
430 433
      pstmt.execute();
431 434
      ResultSet rs = pstmt.getResultSet();
432 435
      double queryExecuteTime = System.currentTimeMillis() / 1000;
433
      MetaCatUtil.debugMessage("Time for execute query: "
434
                    + (queryExecuteTime - startTime), 30);
436
      logMetacat.warn("Time for execute query: "
437
                    + (queryExecuteTime - startTime));
435 438
      boolean tableHasRows = rs.next();
436 439
      while (tableHasRows)
437 440
      {
......
448 451
         if (returndocVec.size() != 0 && !returndocVec.contains(doctype)
449 452
                        && !qspec.isPercentageSearch())
450 453
        {
451
           MetaCatUtil.debugMessage("Back tracing now...", 20);
454
           logMetacat.warn("Back tracing now...");
452 455
           String sep = MetaCatUtil.getOption("accNumSeparator");
453 456
           StringBuffer btBuf = new StringBuffer();
454 457
           btBuf.append("select docid from xml_relation where ");
......
480 483
               //there was a backtrackable document found
481 484
               DocumentImpl xmldoc = null;
482 485
               String packageDocid = btrs.getString(1);
483
               MetaCatUtil.debugMessage("Getting document for docid: "
484
                                         + packageDocid, 40);
486
               logMetacat.info("Getting document for docid: "
487
                                         + packageDocid);
485 488
                try
486 489
                {
487 490
                    //  THIS CONSTRUCTOR BUILDS THE WHOLE XML doc not
......
494 497
                    xmldoc = new DocumentImpl(accNumber, false);
495 498
                    if (xmldoc == null)
496 499
                    {
497
                       MetaCatUtil.debugMessage("Document was null for: "
498
                                                + packageDocid, 50);
500
                       logMetacat.info("Document was null for: "
501
                                                + packageDocid);
499 502
                    }
500 503
                }
501 504
                catch (Exception e)
......
508 511
                String docid_org = xmldoc.getDocID();
509 512
                if (docid_org == null)
510 513
                {
511
                   MetaCatUtil.debugMessage("Docid_org was null.", 40);
514
                   logMetacat.info("Docid_org was null.");
512 515
                   //continue;
513 516
                }
514 517
                docid = docid_org.trim();
......
606 609
                              user, groups,dbconn, useXMLIndex);
607 610
     }
608 611
     double docListTime = System.currentTimeMillis() / 1000;
609
     MetaCatUtil.debugMessage("prepare docid list time: "
610
                    + (docListTime - queryExecuteTime), 30);
612
     logMetacat.warn("prepare docid list time: "
613
                    + (docListTime - queryExecuteTime));
611 614

  
612 615
     return resultsetBuffer;
613 616
    }//findReturnDoclist
......
642 645
     }
643 646

  
644 647
     if(returnfield_id < 0){
645
         MetaCatUtil.debugMessage("Error in getting returnfield id from"
646
                                  + "xml_returnfield table", 20);
648
         logMetacat.warn("Error in getting returnfield id from"
649
                                  + "xml_returnfield table");
647 650
	enterRecords = false;
648 651
     }
649 652

  
650 653
     // get the hashtable containing the docids that already in the
651 654
     // xml_queryresult table
652
     MetaCatUtil.debugMessage("size of partOfDoclist before"
655
     logMetacat.info("size of partOfDoclist before"
653 656
                             + " docidsInQueryresultTable(): "
654
                             + partOfDoclist.size() , 50);
657
                             + partOfDoclist.size());
655 658
     Hashtable queryresultDocList = docidsInQueryresultTable(returnfield_id,
656 659
                                                        partOfDoclist, dbconn);
657 660

  
......
670 673
         partOfDoclistBackup.put(key, partOfDoclist.get(key));
671 674
     }
672 675

  
673
     MetaCatUtil.debugMessage("size of partOfDoclist after"
676
     logMetacat.info("size of partOfDoclist after"
674 677
                             + " docidsInQueryresultTable(): "
675
                             + partOfDoclist.size() , 50);
678
                             + partOfDoclist.size());
676 679

  
677 680
     //add return fields for the documents in partOfDoclist
678 681
     partOfDoclist = addReturnfield(partOfDoclist, qspec, user, groups,
......
774 777
             String query = "select docid, queryresult_string from "
775 778
                          + "xml_queryresult where returnfield_id = " +
776 779
                          returnfield_id +" and docid in ("+ doclist + ")";
777
             MetaCatUtil.debugMessage("Query to get docids from xml_queryresult:"
778
                                      + query, 50);
780
             logMetacat.info("Query to get docids from xml_queryresult:"
781
                                      + query);
779 782

  
780 783
             try {
781 784
                 // prepare and execute the query
......
792 795
                     if(element != null){
793 796
                         returnValue.put(key, element);
794 797
                     } else {
795
                         MetaCatUtil.debugMessage("Null elment found ("
796
                         + "DBQuery.docidsInQueryresultTable)", 50);
798
                         logMetacat.info("Null elment found ("
799
                         + "DBQuery.docidsInQueryresultTable)");
797 800
                     }
798 801
                     tableHasRows = rs.next();
799 802
                 }
800 803
                 rs.close();
801 804
                 pstmt.close();
802 805
             } catch (Exception e){
803
                 MetaCatUtil.debugMessage("Error getting docids from "
806
                 logMetacat.error("Error getting docids from "
804 807
                                          + "queryresult in "
805 808
                                          + "DBQuery.docidsInQueryresultTable: "
806
                                          + e.getMessage(), 20);
809
                                          + e.getMessage());
807 810
              }
808 811
         }
809 812
         return returnValue;
......
826 829
       // query for finding the id from xml_returnfield
827 830
       String query = "SELECT returnfield_id, usage_count FROM xml_returnfield "
828 831
            + "WHERE returnfield_string LIKE ?";
829
       MetaCatUtil.debugMessage("ReturnField Query:" + query, 50);
832
       logMetacat.info("ReturnField Query:" + query);
830 833

  
831 834
       try {
832 835
           // prepare and run the query
......
849 852
               // increase the usage count
850 853
               query = "UPDATE xml_returnfield SET usage_count ='" + count
851 854
                   + "' WHERE returnfield_id ='"+ id +"'";
852
               MetaCatUtil.debugMessage("ReturnField Table Update:"+ query, 50);
855
               logMetacat.info("ReturnField Table Update:"+ query);
853 856

  
854 857
               pstmt = dbconn.prepareStatement(query);
855 858
               dbconn.increaseUsageCount(1);
......
863 866
               // insert a new record
864 867
               query = "INSERT INTO xml_returnfield (returnfield_string, usage_count)"
865 868
                   + "VALUES (?, '1')";
866
               MetaCatUtil.debugMessage("ReturnField Table Insert:"+ query, 50);
869
               logMetacat.info("ReturnField Table Insert:"+ query);
867 870
               pstmt = dbconn.prepareStatement(query);
868 871
               pstmt.setString(1, returnfield);
869 872
               dbconn.increaseUsageCount(1);
......
873 876
               // get the id of the new record
874 877
               query = "SELECT returnfield_id FROM xml_returnfield "
875 878
                   + "WHERE returnfield_string LIKE ?";
876
               MetaCatUtil.debugMessage("ReturnField query after Insert:" + query, 50);
879
               logMetacat.info("ReturnField query after Insert:" + query);
877 880
               pstmt = dbconn.prepareStatement(query);
878 881
               pstmt.setString(1, returnfield);
879 882

  
......
890 893
           }
891 894

  
892 895
       } catch (Exception e){
893
           MetaCatUtil.debugMessage("Error getting id from xml_returnfield in "
896
           logMetacat.error("Error getting id from xml_returnfield in "
894 897
                                     + "DBQuery.getXmlReturnfieldsTableId: "
895
                                     + e.getMessage(), 20);
898
                                     + e.getMessage());
896 899
           id = -1;
897 900
       }
898 901

  
......
956 959
          }
957 960

  
958 961
           double extendedAccessQueryEnd = System.currentTimeMillis() / 1000;
959
           MetaCatUtil.debugMessage( "Time for execute access extended query: "
960
                          + (extendedAccessQueryEnd - extendedQueryStart),30);
962
           logMetacat.info( "Time for execute access extended query: "
963
                          + (extendedAccessQueryEnd - extendedQueryStart));
961 964

  
962 965
           String extendedQuery =
963 966
               qspec.printExtendedSQL(doclist.toString(), controlPairs, useXMLIndex);
964
           MetaCatUtil.debugMessage("Extended query: " + extendedQuery, 30);
967
           logMetacat.warn("Extended query: " + extendedQuery);
965 968

  
966 969
           if(extendedQuery != null){
967 970
               pstmt = dbconn.prepareStatement(extendedQuery);
......
970 973
               pstmt.execute();
971 974
               rs = pstmt.getResultSet();
972 975
               double extendedQueryEnd = System.currentTimeMillis() / 1000;
973
               MetaCatUtil.debugMessage(
976
               logMetacat.info(
974 977
                   "Time for execute extended query: "
975
                   + (extendedQueryEnd - extendedQueryStart), 30);
978
                   + (extendedQueryEnd - extendedQueryStart));
976 979
               tableHasRows = rs.next();
977 980
               while (tableHasRows) {
978 981
                   ReturnFieldValue returnValue = new ReturnFieldValue();
......
1043 1046
                   }
1044 1047
               } //while
1045 1048
               double docListResultEnd = System.currentTimeMillis() / 1000;
1046
               MetaCatUtil.debugMessage(
1049
               logMetacat.warn(
1047 1050
                   "Time for prepare doclistresult after"
1048 1051
                   + " execute extended query: "
1049
                   + (docListResultEnd - extendedQueryEnd),
1050
                   30);
1052
                   + (docListResultEnd - extendedQueryEnd));
1051 1053
           }
1052 1054

  
1053 1055
           // get attribures return
......
1120 1122
      pstmt.close();
1121 1123
    }//while
1122 1124
    double endRelation = System.currentTimeMillis() / 1000;
1123
    MetaCatUtil.debugMessage("Time for adding relation to docListResult: "
1124
                             + (endRelation - startRelation), 30);
1125
    logMetacat.info("Time for adding relation to docListResult: "
1126
                             + (endRelation - startRelation));
1125 1127

  
1126 1128
    return docListResult;
1127 1129
  }//addRelation
......
1279 1281
                rs.close();
1280 1282
                pstmt.close();
1281 1283
            } catch (Exception se) {
1282
                MetaCatUtil.debugMessage(
1284
                logMetacat.error(
1283 1285
                        "Error in DBQuery.getAttributeValue1: "
1284
                                + se.getMessage(), 30);
1286
                                + se.getMessage());
1285 1287
            } finally {
1286 1288
                try {
1287 1289
                    pstmt.close();
1288 1290
                }//try
1289 1291
                catch (SQLException sqlE) {
1290
                    MetaCatUtil.debugMessage(
1292
                    logMetacat.error(
1291 1293
                            "Error in DBQuery.getAttributeValue2: "
1292
                                    + sqlE.getMessage(), 30);
1294
                                    + sqlE.getMessage());
1293 1295
                }//catch
1294 1296
                finally {
1295 1297
                    DBConnectionPool.returnDBConnection(dbconn, serialNumber);
......
1607 1609
            pStmt.close();
1608 1610
        }//try
1609 1611
        catch (SQLException e) {
1610
            MetaCatUtil.debugMessage("Error in getDocidListForDataPackage: "
1611
                    + e.getMessage(), 30);
1612
            logMetacat.error("Error in getDocidListForDataPackage: "
1613
                    + e.getMessage());
1612 1614
        }//catch
1613 1615
        finally {
1614 1616
            try {
1615 1617
                pStmt.close();
1616 1618
            }//try
1617 1619
            catch (SQLException ee) {
1618
                MetaCatUtil.debugMessage(
1620
                logMetacat.error(
1619 1621
                        "Error in getDocidListForDataPackage: "
1620
                                + ee.getMessage(), 30);
1622
                                + ee.getMessage());
1621 1623
            }//catch
1622 1624
            finally {
1623 1625
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
1668 1670
            }//for
1669 1671
        }//try
1670 1672
        catch (Exception e) {
1671
            MetaCatUtil.debugMessage("Error in getOldVersionAllDocumentImpl: "
1672
                    + e.getMessage(), 30);
1673
            logMetacat.error("Error in getOldVersionAllDocumentImpl: "
1674
                    + e.getMessage());
1673 1675
        }//catch
1674 1676

  
1675 1677
        // return result
......
1711 1713
            pStmt.close();
1712 1714
        }//try
1713 1715
        catch (SQLException e) {
1714
            MetaCatUtil.debugMessage("Error in isDataPackageId: "
1715
                    + e.getMessage(), 30);
1716
            logMetacat.error("Error in isDataPackageId: "
1717
                    + e.getMessage());
1716 1718
        } finally {
1717 1719
            try {
1718 1720
                pStmt.close();
1719 1721
            }//try
1720 1722
            catch (SQLException ee) {
1721
                MetaCatUtil.debugMessage("Error in isDataPackageId: "
1722
                        + ee.getMessage(), 30);
1723
                logMetacat.error("Error in isDataPackageId: "
1724
                        + ee.getMessage());
1723 1725
            }//catch
1724 1726
            finally {
1725 1727
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
1779 1781

  
1780 1782
        }//try
1781 1783
        catch (SQLException e) {
1782
            MetaCatUtil.debugMessage(
1784
            logMetacat.error(
1783 1785
                    "Error in getCurrentRevFromXMLDoumentsTable: "
1784
                            + e.getMessage(), 30);
1786
                            + e.getMessage());
1785 1787
            throw e;
1786 1788
        }//catch
1787 1789
        finally {
......
1789 1791
                pStmt.close();
1790 1792
            }//try
1791 1793
            catch (SQLException ee) {
1792
                MetaCatUtil.debugMessage(
1794
                logMetacat.error(
1793 1795
                        "Error in getCurrentRevFromXMLDoumentsTable: "
1794
                                + ee.getMessage(), 30);
1796
                                + ee.getMessage());
1795 1797
            }//catch
1796 1798
            finally {
1797 1799
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
1874 1876
                documentImplList.add(documentImplObject);
1875 1877
            }//try
1876 1878
            catch (Exception e) {
1877
                MetaCatUtil.debugMessage("Error in getCurrentAllDocumentImpl: "
1878
                        + e.getMessage(), 30);
1879
                logMetacat.error("Error in getCurrentAllDocumentImpl: "
1880
                        + e.getMessage());
1879 1881
                // continue the for loop
1880 1882
                continue;
1881 1883
            }
......
1915 1917
                documentImplList.add(documentImplObject);
1916 1918
            }//try
1917 1919
            catch (McdbDocNotFoundException notFoundE) {
1918
                MetaCatUtil.debugMessage(
1920
                logMetacat.error(
1919 1921
                        "Error in DBQuery.getOldVersionAllDocument" + "Imple"
1920
                                + notFoundE.getMessage(), 30);
1922
                                + notFoundE.getMessage());
1921 1923
                // Rather than add a DocumentImple object into vetor, a String
1922 1924
                // object
1923 1925
                // - the doicd was added to the vector
......
1926 1928
                continue;
1927 1929
            }//catch
1928 1930
            catch (Exception e) {
1929
                MetaCatUtil.debugMessage(
1931
                logMetacat.error(
1930 1932
                        "Error in DBQuery.getOldVersionAllDocument" + "Imple"
1931
                                + e.getMessage(), 30);
1933
                                + e.getMessage());
1932 1934
                // Continue the for loop
1933 1935
                continue;
1934 1936
            }//catch
......
1972 1974
            zipOut.closeEntry();
1973 1975
        }//try
1974 1976
        catch (IOException ioe) {
1975
            MetaCatUtil.debugMessage("There is an exception: "
1976
                    + ioe.getMessage(), 30);
1977
            logMetacat.error("There is an exception: "
1978
                    + ioe.getMessage());
1977 1979
        }//catch
1978 1980
    }//addDataFileToZipOutputStream()
1979 1981

  
......
2181 2183
                        .equals("class java.lang.String")) {
2182 2184
                    // Get String object from vetor
2183 2185
                    String documentId = (String) documentImplList.elementAt(i);
2184
                    MetaCatUtil.debugMessage("docid: " + documentId, 30);
2186
                    logMetacat.info("docid: " + documentId);
2185 2187
                    // Get doicd without revision
2186 2188
                    String docidWithoutRevision = MetaCatUtil
2187 2189
                            .getDocIdFromString(documentId);
2188
                    MetaCatUtil.debugMessage("docidWithoutRevsion: "
2189
                            + docidWithoutRevision, 30);
2190
                    logMetacat.info("docidWithoutRevsion: "
2191
                            + docidWithoutRevision);
2190 2192
                    // Get revision
2191 2193
                    String revision = MetaCatUtil
2192 2194
                            .getRevisionStringFromString(documentId);
2193
                    MetaCatUtil.debugMessage("revsion from docIdentifier: "
2194
                            + revision, 30);
2195
                    logMetacat.info("revsion from docIdentifier: "
2196
                            + revision);
2195 2197
                    // Zip entry string
2196 2198
                    String zipEntryPath = rootName + "/data/";
2197 2199
                    // Create a RemoteDocument object

Also available in: Unified diff