Project

General

Profile

« Previous | Next » 

Revision 315

Added by bojilova over 23 years ago

doctype attr in xml_index table has been added
so changed the getDataGuide routine to select for paths by given doctype

View differences:

src/edu/ucsb/nceas/metacat/DBUtil.java
5 5
 *             2/ Reading Lore type Data Guide from db connection
6 6
 *  Copyright: 2000 Regents of the University of California and the
7 7
 *             National Center for Ecological Analysis and Synthesis
8
 *    Authors: Matt Jones
8
 *    Authors: Jivka Bojilova
9 9
 * 
10 10
 *   '$Author$'
11 11
 *     '$Date$'
......
42 42
     if (args.length < 1)
43 43
     {
44 44
        System.err.println("Wrong number of arguments!!!");
45
        System.err.println("USAGE: java DBUtil <-dt|-dg>");
45
        System.err.println("USAGE: java DBUtil <-dt | -dg doctype>");
46 46
        return;
47 47
     } else {
48 48
        try {
......
57 57
            String doctypes = dbutil.readDoctypes();
58 58
            System.out.println(doctypes);
59 59
          } else if ( args[0].equals("-dg") ) {
60
            String dataguide = dbutil.readDataGuide("");
60
            String doctype = null;
61
            if ( args.length == 2 ) { doctype = args[1]; }
62
            String dataguide = dbutil.readDataGuide(doctype);
61 63
            System.out.println(dataguide);
62 64
          } else {
63
            System.err.println("USAGE: java DBUtil <-dt|-dg>");
65
            System.err.println("USAGE: java DBUtil <-dt | -dg doctype>");
64 66
          }  
65 67

  
66 68
        } catch (Exception e) {
......
119 121

  
120 122
    Vector dataguide = new Vector();
121 123
    String path;
122

  
124
    PreparedStatement pstmt;
125
    
123 126
    try {
124 127

  
125
      PreparedStatement pstmt =
126
        conn.prepareStatement("SELECT distinct path, nodeid FROM xml_index" +
127
                              " WHERE path LIKE '/' || ? || '%'" + 
128
                              " ORDER BY nodeid");
129
      pstmt.setString(1, doctype);
130
      pstmt.execute();
131
      ResultSet rs = pstmt.getResultSet();
132
      boolean tableHasRows = rs.next();
133
      while (tableHasRows) {
134
        path = rs.getString(1);
135
        if ( dataguide.indexOf(path) == -1 ) {
136
            dataguide.addElement(path);
137
        }    
138
        tableHasRows = rs.next();
139
      }
128
        if ( doctype != null ) {
129
            pstmt = conn.prepareStatement("SELECT distinct path, nodeid " + 
130
                                          "FROM xml_index " +
131
                                          "WHERE path LIKE '/%' " + 
132
                                          "AND doctype LIKE ? " +
133
                                          "ORDER BY nodeid");
134
            pstmt.setString(1, doctype);
135
        } else {
136
            pstmt = conn.prepareStatement("SELECT distinct path, nodeid " + 
137
                                          "FROM xml_index " +
138
                                          "WHERE path LIKE '/%' " + 
139
                                          "ORDER BY nodeid");
140
        }
141

  
142
        pstmt.execute();
143
        ResultSet rs = pstmt.getResultSet();
144
        boolean tableHasRows = rs.next();
145
        while (tableHasRows) {
146
            path = rs.getString(1);
147
            if ( dataguide.indexOf(path) == -1 ) {
148
                dataguide.addElement(path);
149
            }    
150
            tableHasRows = rs.next();
151
        }
140 152
      
141
      pstmt.close();
153
        pstmt.close();
142 154

  
143 155
    } catch (SQLException e) {
144 156
      System.out.println("DBUtil.readDoctypes(): " + e.getMessage());

Also available in: Unified diff