Project

General

Profile

« Previous | Next » 

Revision 2072

Added by Matt Jones over 20 years ago

Moved decision about whether to use xml_index for
query to the metacat.properties as "usexmlindex". Default
is now false. Still have some refactoring to do to remove a
few more uses of the xml_index table.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
979 979
            }
980 980
        }
981 981
        self.append(") AND xml_nodes.docid in (");
982
        //self.append(query.printSQL());
983 982
        self.append(doclist);
984 983
        self.append(")");
985 984
        self.append(" AND xml_nodes.nodetype = 'ATTRIBUTE'");
src/edu/ucsb/nceas/metacat/DBQuery.java
63 63
  //private Connection  conn = null;
64 64
  private String  parserName = null;
65 65
  private MetaCatUtil util = new MetaCatUtil();
66
  
66 67
  /**
67 68
   * the main routine used to test the DBQuery utility.
68 69
   * <p>
......
188 189
   */
189 190
  public Hashtable findDocuments(Reader xmlquery, String user, String[] groups)
190 191
  {
191
    return findDocuments(xmlquery, user, groups, true);
192
    boolean useXMLIndex = (new Boolean(
193
            MetaCatUtil.getOption("usexmlindex"))).booleanValue();
194
    return findDocuments(xmlquery, user, groups, useXMLIndex);
192 195
  }
193 196

  
194 197
  /**
......
833 836
    self.append(") ");
834 837
    return self.toString();
835 838
  }
836
  
837
  /**
838
   * returns a string array of the contents of a particular node.
839
   * If the node appears more than once, the contents are returned
840
   * in the order in which they appearred in the document.
841
   * @param nodename the name or path of the particular node.
842
   * @param docid the docid of the document you want the node from.
843
   */
844
  public static Object[] getNodeContent(String nodename, String docid)
845
  {
846
    DBConnection dbconn = null;
847
    int serialNumber = -1;
848
    StringBuffer query = new StringBuffer();
849
    Vector result = new Vector();
850
    PreparedStatement pstmt = null;
851
    query.append("select nodedata from xml_nodes where parentnodeid in ");
852
    query.append("(select nodeid from xml_index where path like '");
853
    query.append(nodename);
854
    query.append("' and docid like '").append(docid).append("')");
855
    try
856
    {
857
      dbconn=DBConnectionPool.getDBConnection("DBQuery.getNodeContent");
858
      serialNumber=dbconn.getCheckOutSerialNumber();
859
      pstmt = dbconn.prepareStatement(query.toString());
860 839

  
861
      // Execute the SQL query using the JDBC connection
862
      pstmt.execute();
863
      ResultSet rs = pstmt.getResultSet();
864
      boolean tableHasRows = rs.next();
865
      while (tableHasRows)
866
      {
867
        result.add(rs.getString(1));
868
        //System.out.println(rs.getString(1));
869
        tableHasRows = rs.next();
870
      }
871
    }
872
    catch (SQLException e)
873
    {
874
      System.err.println("Error in DBQuery.getNodeContent: " + e.getMessage());
875
    } finally {
876
      try
877
      {
878
        pstmt.close();
879
      }
880
      catch(SQLException sqle)
881
      {}
882
      finally
883
      {
884
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
885
      }
886

  
887
    }
888
    return result.toArray();
889
  }
890

  
891 840
  /**
892 841
   * format a structured query as an XML document that conforms
893 842
   * to the pathquery.dtd and is appropriate for submission to the DBQuery
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
93 93
 * dtdtext -- XML DTD text for a new DTD to load into Metacat XML Catalog<br>
94 94
 * query -- actual query text (to go with 'action=query' or 'action=squery')<br>
95 95
 * valtext -- XML text to be validated<br>
96
 * abstractpath -- XPath in metadata document to read from<br>
97 96
 * action=getaccesscontrol -- retrieve acl info for Metacat document<br>
98 97
 * action=getdoctypes -- retrieve all doctypes (publicID)<br>
99 98
 * action=getdtdschema -- retrieve a DTD or Schema file<br>
......
1134 1133
          withInlineData = false;
1135 1134
        }
1136 1135
      }
1137
      if (params.containsKey("abstractpath")) {
1138
        abstrpath = ((String[])params.get("abstractpath"))[0];
1139
        if ( !abstrpath.equals("") && (abstrpath != null) ) {
1140
          viewAbstract(response, abstrpath, docs[0]);
1141
          return;
1142
        }
1143
      }
1144 1136
      if ( (docs.length > 1) || qformat.equals("zip") ) {
1145 1137
        zip = true;
1146 1138
        out = response.getOutputStream();
......
1540 1532
    }
1541 1533

  
1542 1534
  }
1543

  
1544
  // view abstract within document
1545
  private void viewAbstract(HttpServletResponse response,
1546
                            String abstractpath, String docid)
1547
               throws ClassNotFoundException, IOException, SQLException,
1548
                      McdbException, Exception
1549
  {
1550

  
1551
    PrintWriter out =null;
1552
    try {
1553

  
1554
      response.setContentType("text/html");  //MIME type
1555
      out = response.getWriter();
1556
      Object[] abstracts = DBQuery.getNodeContent(abstractpath, docid);
1557
      out.println("<html><head><title>Abstract</title></head>");
1558
      out.println("<body bgcolor=\"white\"><h1>Abstract</h1>");
1559
      for (int i=0; i<abstracts.length; i++) {
1560
        out.println("<p>" + (String)abstracts[i] + "</p>");
1561
      }
1562
      out.println("</body></html>");
1563

  
1564
    } catch (Exception e) {
1565
       out.println("<?xml version=\"1.0\"?>");
1566
       out.println("<error>");
1567
       out.println(e.getMessage());
1568
       out.println("</error>");
1569

  
1570

  
1571
    }
1572
  }
1535
  
1573 1536
  /**
1574 1537
   * If metacat couldn't find a data file or document locally, it will read this
1575 1538
   * docid from its home server. This is for the replication feature

Also available in: Unified diff