Revision 2067
Added by Matt Jones about 20 years ago
DBUtil.java | ||
---|---|---|
67 | 67 |
{ |
68 | 68 |
System.err.println("Wrong number of arguments!!!"); |
69 | 69 |
System.err.println( |
70 |
"USAGE: java DBUtil <-dt | -ds [doctype] | -dg [doctype] | -dl user>");
|
|
70 |
"USAGE: java DBUtil <-dt | -ds [doctype] | -dl user>"); |
|
71 | 71 |
return; |
72 | 72 |
} else { |
73 | 73 |
try { |
... | ... | |
81 | 81 |
if ( args[0].equals("-dt") ) { |
82 | 82 |
String doctypes = dbutil.readDoctypes(); |
83 | 83 |
System.out.println(doctypes); |
84 |
} else if ( args[0].equals("-dg") ) { |
|
85 |
String doctype = null; |
|
86 |
if ( args.length == 2 ) { doctype = args[1]; } |
|
87 |
String dataguide = dbutil.readDataGuide(doctype); |
|
88 |
System.out.println(dataguide); |
|
89 | 84 |
} else if ( args[0].equals("-ds") ) { |
90 | 85 |
String doctype = null; |
91 | 86 |
if ( args.length == 2 ) { doctype = args[1]; } |
... | ... | |
245 | 240 |
} |
246 | 241 |
|
247 | 242 |
/** |
248 |
* read Data Guide for a given doctype from db connection in XML format |
|
249 |
* select all distinct absolute paths from xml_index table |
|
250 |
*/ |
|
251 |
public String readDataGuide( String doctype ) |
|
252 |
throws SQLException { |
|
253 |
|
|
254 |
Vector dataguide = new Vector(); |
|
255 |
String path; |
|
256 |
PreparedStatement pstmt = null; |
|
257 |
DBConnection dbConn = null; |
|
258 |
int serialNumber = -1; |
|
259 |
|
|
260 |
try { |
|
261 |
dbConn=DBConnectionPool. |
|
262 |
getDBConnection("DBUtil.readDataGuide"); |
|
263 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
264 |
|
|
265 |
if ( doctype != null ) { |
|
266 |
pstmt = dbConn.prepareStatement("SELECT distinct path, nodeid " + |
|
267 |
"FROM xml_index " + |
|
268 |
"WHERE path LIKE '/%' " + |
|
269 |
"AND doctype LIKE ? " + |
|
270 |
"ORDER BY nodeid"); |
|
271 |
pstmt.setString(1, doctype); |
|
272 |
} else { |
|
273 |
pstmt = |
|
274 |
dbConn.prepareStatement("SELECT distinct path, doctype, nodeid " + |
|
275 |
"FROM xml_index " + |
|
276 |
"WHERE path LIKE '/%' " + |
|
277 |
"ORDER BY doctype, nodeid"); |
|
278 |
} |
|
279 |
|
|
280 |
pstmt.execute(); |
|
281 |
ResultSet rs = pstmt.getResultSet(); |
|
282 |
boolean tableHasRows = rs.next(); |
|
283 |
while (tableHasRows) { |
|
284 |
path = rs.getString(1); |
|
285 |
if ( dataguide.indexOf(path) == -1 ) { |
|
286 |
dataguide.addElement(path); |
|
287 |
} |
|
288 |
tableHasRows = rs.next(); |
|
289 |
} |
|
290 |
|
|
291 |
pstmt.close(); |
|
292 |
|
|
293 |
} catch (SQLException e) { |
|
294 |
throw new SQLException("DBUtil.readDataGuide(). " + e.getMessage()); |
|
295 |
} |
|
296 |
finally |
|
297 |
{ |
|
298 |
try |
|
299 |
{ |
|
300 |
pstmt.close(); |
|
301 |
}//try |
|
302 |
finally |
|
303 |
{ |
|
304 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
305 |
}//finally |
|
306 |
}//finally |
|
307 |
|
|
308 |
return formatToXML(dataguide); |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 | 243 |
* format the DataGuide ResultSet to XML |
313 | 244 |
*/ |
314 | 245 |
private String formatToXML(Vector resultset) { |
Also available in: Unified diff
Removed the "getdataguide" action as it was always experimental and is no longer used in metacat or morpho.