Project

General

Profile

« Previous | Next » 

Revision 2069

Added by Matt Jones over 20 years ago

Created new printExtendedSQL function that can get the extended
return fields using only xml_nodes and not xml_index. One
step closer to eliminating the dependence ofn xml_index.

View differences:

test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java
96 96
    public void testPrintSQL()
97 97
    {
98 98
        try {
99
            System.out.println("----------------------");
99 100
            QuerySpecification qspec = new QuerySpecification(xml, 
100 101
                    MetaCatUtil.getOption("saxparser"), 
101 102
                    MetaCatUtil.getOption("accNumberSeparator"));
102
            System.out.println(qspec.printSQL(true));
103
            System.out.println(qspec.printSQL(false));
103 104
        } catch (IOException e) {
104 105
            fail(e.getMessage());
105 106
        }
......
111 112
    public void testPrintExtendedSQL()
112 113
    {
113 114
        try {
115
            System.out.println("----------------------");
114 116
            Hashtable controlPairs = new Hashtable();
115 117
            QuerySpecification qspec = new QuerySpecification(xml, 
116 118
                    MetaCatUtil.getOption("saxparser"), 
117 119
                    MetaCatUtil.getOption("accNumberSeparator"));
118
            System.out.println(qspec.printExtendedSQL("n.1.1, n.2.2", controlPairs));
120
            System.out.println(
121
                    qspec.printExtendedSQL("'obfs.45337', 'obfs.45338', 'obfs.45346'", 
122
                            controlPairs, false));
119 123
        } catch (IOException e) {
120 124
            fail(e.getMessage());
121 125
        }
src/edu/ucsb/nceas/metacat/QuerySpecification.java
808 808

  
809 809
    /**
810 810
     * This method prints sql based upon the <returnfield> tag in the
811
     * pathquery document. This allows for customization of the returned fields
811
     * pathquery document. This allows for customization of the returned fields.
812
     * If the boolean useXMLIndex paramter is false, it uses a recursive query on 
813
     * xml_nodes to find the fields to be included by their path expression, and 
814
     * avoids the use of the xml_index table.
812 815
     * 
816
     * @param doclist 
817
     *            the list of document ids to search by
818
     * @param unaccessableNodePair
819
     *            the node pair(start id and end id) which this user could not
820
     *            access it
821
     * @param useXMLIndex a boolean flag indicating whether to search using xml_index
822
     */
823
    public String printExtendedSQL(String doclist,
824
            Hashtable unaccessableNodePair, boolean useXMLIndex)
825
    {
826
        if (useXMLIndex) {
827
            return printExtendedSQL(doclist, unaccessableNodePair);
828
        } else {
829
            StringBuffer self = new StringBuffer();
830

  
831
            boolean firstfield = true;
832
            //put the returnfields into the query
833
            //the for loop allows for multiple fields
834
            for (int i = 0; i < returnFieldList.size(); i++) {
835
                if (firstfield) {
836
                    firstfield = false;
837
                    self.append("(");
838
                } else {
839
                    self.append(" UNION (");   
840
                }
841
                String path  = (String) returnFieldList.elementAt(i);
842
                self.append("select xml_nodes.docid, ");
843
                self.append("'"+ path  + "' as path, ");
844
                self.append("xml_nodes.nodedata, ");
845
                self.append("xml_nodes.parentnodeid ");
846
                self.append("from xml_nodes, xml_documents ");
847
                self.append("where parentnodeid IN ");
848
                self.append(QueryTerm.useNestedStatements(path));
849
                
850
                self.append(" AND xml_nodes.docid in (");
851
                self.append(doclist);
852
                self.append(")");
853
                self.append(" AND xml_nodes.nodetype = 'TEXT'");
854
                self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid");
855
                
856
                // add control part for extended query
857
                Enumeration en = unaccessableNodePair.keys();
858

  
859
                while (en.hasMoreElements()) {
860
                    // Get control pairs in object
861
                    Long startNodeIdObject = (Long) en.nextElement();
862
                    Long endNodeIdObject = (Long) unaccessableNodePair
863
                            .get(startNodeIdObject);
864
                    // change it to long
865
                    long startNodeId = startNodeIdObject.longValue();
866
                    long endNodeId = endNodeIdObject.longValue();
867
                    // add into query
868
                    self.append(" AND( xml_nodes.nodeid < ");
869
                    self.append(startNodeId);
870
                    self.append(" OR xml_nodes.nodeid > ");
871
                    self.append(endNodeId);
872
                    self.append(")");
873
                }
874
                self.append(")");
875
            }
876

  
877
            return self.toString();
878
        }
879
    }
880
    
881
    /**
882
     * This method prints sql based upon the &lt;returnfield&gt; tag in the
883
     * pathquery document. This allows for customization of the returned fields.
884
     * It uses the xml_index table and so assumes that this table has been
885
     * built.
886
     * 
813 887
     * @param doclist
814 888
     *            the list of document ids to search by
815 889
     * @param unaccessableNodePair
816 890
     *            the node pair(start id and end id) which this user could not
817 891
     *            access it
818 892
     */
819
    public String printExtendedSQL(String doclist,
893
    public String printExtendedSQL(String doclist, 
820 894
            Hashtable unaccessableNodePair)
821 895
    {
822 896
        StringBuffer self = new StringBuffer();
src/edu/ucsb/nceas/metacat/DBQuery.java
833 833
    self.append(") ");
834 834
    return self.toString();
835 835
  }
836
  
836 837
  /**
837 838
   * returns a string array of the contents of a particular node.
838 839
   * If the node appears more than once, the contents are returned
......
854 855
    try
855 856
    {
856 857
      dbconn=DBConnectionPool.getDBConnection("DBQuery.getNodeContent");
857
        serialNumber=dbconn.getCheckOutSerialNumber();
858
      serialNumber=dbconn.getCheckOutSerialNumber();
858 859
      pstmt = dbconn.prepareStatement(query.toString());
859 860

  
860 861
      // Execute the SQL query using the JDBC connection
src/edu/ucsb/nceas/metacat/QueryTerm.java
244 244
     * Constraint the query with @pathexp without using the XML Index, but
245 245
     * nested SQL statements instead. The query migth be slower.
246 246
     */
247
    private String useNestedStatements(String pathexpr)
247
    public static String useNestedStatements(String pathexpr)
248 248
    {
249 249
        StringBuffer nestedStmts = new StringBuffer();
250 250
        Vector nodes = new Vector();

Also available in: Unified diff