Project

General

Profile

Revision 2073

Added by Matt Jones over 16 years ago

Some refactoring of the printExtendedSQL()
methods to eliminate redundancy in the code and
to provide more readable documentation.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
813 813
     * xml_nodes to find the fields to be included by their path expression, and 
814 814
     * avoids the use of the xml_index table.
815 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
816
     * @param doclist the list of document ids to search
817
     * @param unaccessableNodePair the node pairs (start id and end id) which 
818
     *            this user should not access
819
     * @param useXMLIndex a boolean flag indicating whether to search using 
820
     *            xml_index
822 821
     */
823 822
    public String printExtendedSQL(String doclist,
824 823
            Hashtable unaccessableNodePair, boolean useXMLIndex)
......
840 839
                }
841 840
                String path  = (String) returnFieldList.elementAt(i);
842 841
                self.append("select xml_nodes.docid, ");
843
                self.append("'"+ path  + "' as path, ");
844
                self.append("xml_nodes.nodedata, ");
842
                self.append("'"+ path  + "' as path, xml_nodes.nodedata, ");
845 843
                self.append("xml_nodes.parentnodeid ");
846 844
                self.append("from xml_nodes, xml_documents ");
847 845
                self.append("where parentnodeid IN ");
......
849 847
                
850 848
                self.append(" AND xml_nodes.docid in (");
851 849
                self.append(doclist);
852
                self.append(")");
853
                self.append(" AND xml_nodes.nodetype = 'TEXT'");
850
                self.append(") AND xml_nodes.nodetype = 'TEXT'");
854 851
                self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid");
855 852
                
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
                }
853
                addAccessRestrictionSQL(unaccessableNodePair, self);
874 854
                self.append(")");
875 855
            }
876 856

  
......
884 864
     * It uses the xml_index table and so assumes that this table has been
885 865
     * built.
886 866
     * 
887
     * @param doclist
888
     *            the list of document ids to search by
889
     * @param unaccessableNodePair
890
     *            the node pair(start id and end id) which this user could not
891
     *            access it
867
     * @param doclist the list of document ids to search
868
     * @param unaccessableNodePair the node pairs (start id and end id) 
869
     *            which this user should not access
892 870
     */
893 871
    public String printExtendedSQL(String doclist, 
894 872
            Hashtable unaccessableNodePair)
......
913 891
            }
914 892
        }
915 893
        self.append(") AND xml_nodes.docid in (");
916
        //self.append(query.printSQL());
917 894
        self.append(doclist);
918
        self.append(")");
919
        self.append(" AND xml_nodes.nodetype = 'TEXT'");
895
        self.append(") AND xml_nodes.nodetype = 'TEXT'");
920 896

  
897
        addAccessRestrictionSQL(unaccessableNodePair, self);
898

  
899
        return self.toString();
900
    }
901

  
902
    /**
903
     * Create the SQl necessary to restrict access to allowed nodes.  This is
904
     * accomplished by restricting the nodes that are returned to include
905
     * only those whose IDs fall outside of a set of start/stop pairs of
906
     * nodeid values.  These pairs are passed in as a hash, with the key
907
     * containing the start nodeid and the value containing the end nodeid.
908
     * Any nodes between these start and end nodeid values will be excluded
909
     * from the results.
910
     * 
911
     * @param unaccessableNodePair hash of start/end nodeid pairs to restrict
912
     * @param self a stringbuffer to which the genrated SQL is appended 
913
     */
914
    private void addAccessRestrictionSQL(Hashtable unaccessableNodePair, 
915
            StringBuffer self)
916
    {
921 917
        // add control part for extended query
922 918
        Enumeration en = unaccessableNodePair.keys();
923 919

  
......
930 926
            long startNodeId = startNodeIdObject.longValue();
931 927
            long endNodeId = endNodeIdObject.longValue();
932 928
            // add into query
933
            self.append(" AND( xml_nodes.nodeid < ");
929
            self.append(" AND ( xml_nodes.nodeid < ");
934 930
            self.append(startNodeId);
935 931
            self.append(" OR xml_nodes.nodeid > ");
936 932
            self.append(endNodeId);
937 933
            self.append(")");
938 934
        }
939

  
940
        return self.toString();
941 935
    }
942

  
936
    
943 937
    /**
944 938
     * This method prints sql based upon the returnfield tag in the pathquery
945 939
     * document has an attribute. This allows for customization of the returned
946
     * fields
940
     * fields.
947 941
     * 
948 942
     * @param doclist
949 943
     *            the list of document ids to search by
......
1019 1013
        //"querytitle=" + querytitle + "\n" + query;
1020 1014
    }
1021 1015

  
1022
    /* A method to get rid of attribute part in path expression */
1016
    /** A method to get rid of attribute part in path expression */
1023 1017
    public static String newPathExpressionWithOutAttribute(String pathExpression)
1024 1018
    {
1025 1019
        if (pathExpression == null) { return null; }
......
1033 1027
        return newExpression;
1034 1028
    }
1035 1029

  
1036
    /* A method to get attribute name from path */
1030
    /** A method to get attribute name from path */
1037 1031
    public static String getAttributeName(String path)
1038 1032
    {
1039 1033
        if (path == null) { return null; }

Also available in: Unified diff