Project

General

Profile

« Previous | Next » 

Revision 2472

Added by Chris Jones over 19 years ago

I've added in a test in QuerySpecification.printExtendedSQL that checks
to see if attributes, and sometimes only attributes, are in the original
returnfield request. If so, the printAttributeQuery is called.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
374 374
    /**
375 375
     * A method to get if the query has an attribute return field
376 376
     */
377
    public boolean containAttributeReturnField()
377
    public boolean containsAttributeReturnField()
378 378
    {
379 379
        return hasAttributeReturnField;
380 380
    }
......
667 667
            // case where the return field is solely an attribute
668 668
            MetaCatUtil.debugMessage("QuerySpecification.handleReturnField(): " , 35);
669 669
            MetaCatUtil.debugMessage("  there are *only* attributes in the XPATH statement" , 35);
670
            returnFieldList.add(inputString);
670
            String returnPath = newPathExpressionWithOutAttribute(inputString);
671
            String attributeName = getAttributeName(inputString);
672
            Vector pathInfo = new Vector();
673
            // the vector has the information about return path and
674
            // attributename
675
            pathInfo.addElement(returnPath);
676
            pathInfo.addElement(attributeName);
677
            // put the vector into a hash table. The reseaon why don't put
678
            // return path or attributename as a key is because they are not
679
            // unique
680
            attributeReturnList.put(new Integer(countAttributeReturnField),
681
                    pathInfo);
682
            countAttributeReturnField++;
683
            hasAttributeReturnField = true;
671 684
            containsExtendedSQL = true;
672 685
          } else {
673 686
            // has a attribute return field
......
923 936
    public String printExtendedSQL(String doclist,
924 937
            Hashtable unaccessableNodePair)
925 938
    {
939
        MetaCatUtil.debugMessage("querySpecification.printExtendedSQL called\n", 35);
926 940
        StringBuffer self = new StringBuffer();
941

  
942
      // test if the are elements in the return fields
943
      if ( returnFieldList.size() != 0 ) {  
927 944
        self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
928 945
        self.append("xml_nodes.parentnodeid ");
929 946
        self.append("from xml_index, xml_nodes where xml_index.nodeid=");
......
933 950
        //put the returnfields into the query
934 951
        //the for loop allows for multiple fields
935 952
        for (int i = 0; i < returnFieldList.size(); i++) {
936
            if (firstfield) {
937
                firstfield = false;
938
                self.append((String) returnFieldList.elementAt(i));
939
                self.append("' ");
940
            } else {
941
                self.append("or xml_index.path like '");
942
                self.append((String) returnFieldList.elementAt(i));
943
                self.append("' ");
944
            }
953
          if (firstfield) {
954
            firstfield = false;
955
            self.append((String) returnFieldList.elementAt(i));
956
            self.append("' ");
957
          } else {
958
            self.append("or xml_index.path like '");
959
            self.append((String) returnFieldList.elementAt(i));
960
            self.append("' ");
961
          }
945 962
        }
946 963
        self.append(") AND xml_nodes.docid in (");
947 964
        self.append(doclist);
......
949 966

  
950 967
        addAccessRestrictionSQL(unaccessableNodePair, self);
951 968

  
952
        return self.toString();
969
      }
970
    
971
      // test if there are attributes in the return fields
972
      if ( containsAttributeReturnField() ) {
973
        MetaCatUtil.debugMessage("QuerySpecification.printExtendedSQL: " + 
974
                                 "Attributes *are* in the returnfields\n", 35);
975
        // append the attribute query 
976
        self.append(printAttributeQuery(doclist));
977
      }
978

  
979
      return self.toString();
953 980
    }
954 981

  
955 982

  
......
1113 1140
                    self.append("xml_index.path like '");
1114 1141
                    self.append(returnPath);
1115 1142
                    self.append("' AND ");
1143
                }else {
1144
                  MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: " 
1145
                   + "returnPath is: " + returnPath, 30);
1116 1146
                }
1117 1147
                self.append("xml_nodes.nodename like '");
1118 1148
                self.append(attributeName);
......
1123 1153
                    self.append("xml_index.path like '");
1124 1154
                    self.append(returnPath);
1125 1155
                    self.append("' AND ");
1156
                }else {
1157
                  MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: " 
1158
                   + "returnPath is null: " + returnPath, 30);
1126 1159
                }
1127 1160
                self.append("xml_nodes.nodename like '");
1128 1161
                self.append(attributeName);

Also available in: Unified diff