- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java
r8742 r9874 8 8 9 9 import java.sql.SQLException; 10 import java.sql.Statement; 10 11 import java.sql.ResultSet; 11 12 … … 271 272 { 272 273 int sqlId = -1; 273 274 274 // check if this node is in the database already 275 275 GS3SQLSelect select = new GS3SQLSelect("filegroups"); … … 281 281 select.setWhere(where); 282 282 283 connection.execute(select.toString()); 284 285 ResultSet selectResult = connection.getResultSet(); 283 ResultSet results = null; 284 Statement statement = null; 286 285 287 286 try { 288 if (selectResult == null || 289 !selectResult.first()) { 287 statement = connection.createStatement(); 288 results = statement.executeQuery(select.toString()); 289 if (!results.first()) { 290 290 GS3SQLInsert insert = new GS3SQLInsert("filegroups"); 291 291 … … 295 295 insert.addValue("ParentType", parentIsSection ? SECTION_PARENT : GROUP_PARENT); 296 296 297 if (!connection.execute(insert.toString())) { 298 return false; 299 } 297 statement.execute(insert.toString()); 300 298 } 301 299 else { … … 304 302 } 305 303 catch (SQLException ex){ 306 System.err.println( ex);304 System.err.println("METSFileGroup.writeSQL(): "+ex); 307 305 return false; 308 306 } 309 307 310 308 // get the filegroup reference now 311 connection.execute(select.toString());312 313 309 try { 314 ResultSet results = connection.getResultSet(); 315 if (results == null) { 310 results = statement.executeQuery(select.toString()); 311 if (results.first()) { 312 sqlId = results.getInt("FileGroupRef"); 313 } else { 314 statement.close(); 316 315 return false; 317 316 } 318 results.first(); 319 sqlId = results.getInt("FileGroupRef"); 320 } 321 catch (SQLException sqlex) { 322 System.out.println(sqlex); 317 statement.close(); 318 } catch (SQLException sqlex) { 319 System.err.println("METSFileGroup.writeSQL(): "+sqlex); 323 320 return false; 324 321 } 325 326 322 // iterate over the child groups 327 323 Iterator childIter = childGroups.iterator(); … … 330 326 331 327 if (!fileGroup.writeSQL(document, Integer.toString(sqlId), false, connection)){ 328 System.err.println("METSFileGroup.writeSQL(): Couldn't write FileGroup"); 332 329 return false; 333 330 } … … 337 334 childIter = children.iterator(); 338 335 while (childIter.hasNext()){ 339 METSFile file = (METSFile) childIter.next(); 340 336 METSFile file = (METSFile) childIter.next(); 341 337 if (!file.writeSQL(sqlId, connection)){ 338 System.err.println("METSFileGroup.writeSQL(): Couldn't write File"); 342 339 return false; 343 340 } … … 371 368 select.setWhere(where); 372 369 373 connection.execute(select.toString());370 Statement statement = connection.createStatement(); 374 371 375 372 // parse through the child groups 376 ResultSet childSet = connection.getResultSet();373 ResultSet childSet = statement.executeQuery(select.toString()); 377 374 if (childSet.first()) { 378 375 do { … … 384 381 while (childSet.next()); 385 382 } 386 387 383 // now scan for file members 388 384 select = new GS3SQLSelect("files"); 389 385 select.addField("*"); 390 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), 391 GS3SQLField.INTEGER_TYPE); 386 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), GS3SQLField.INTEGER_TYPE); 392 387 where = new GS3SQLWhere(whereItem); 393 388 select.setWhere(where); 394 connection.execute(select.toString()); 395 396 ResultSet childFileSet = connection.getResultSet(); 397 if (childFileSet != null && childFileSet.first()) { 389 ResultSet childFileSet = statement.executeQuery(select.toString()); 390 if (childFileSet.first()) { 398 391 do { 399 392 METSFile file = METSFile.readSQL(connection, childFileSet); … … 404 397 while (childFileSet.next()); 405 398 } 406 399 statement.close(); 407 400 return group; 408 401 } 409 402 catch (SQLException sqlEx){ 410 System. out.println(sqlEx);403 System.err.println("METSFileGroup.readSQL(): "+sqlEx); 411 404 System.exit(1); 412 405 }
Note:
See TracChangeset
for help on using the changeset viewer.