Changeset 9858 for branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata
- Timestamp:
- 2005-05-12T14:52:45+12:00 (19 years ago)
- Location:
- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java
r9851 r9858 8 8 9 9 import java.sql.SQLException; 10 import java.sql.Statement; 10 11 import java.sql.ResultSet; 11 12 … … 275 276 } else { 276 277 // TODO: raise an error! 277 System.out.println("Error: METSDescri iptive: unrecognised tag "+childName);278 System.out.println("Error: METSDescriptive: unrecognised tag "+childName); 278 279 } 279 280 } … … 375 376 select.setWhere(where); 376 377 377 connection.execute(select.toString());378 379 378 try { 379 Statement statement = connection.createStatement(); 380 ResultSet resultSet = statement.executeQuery(select.toString()); 380 381 GS3SQLAction action; 381 382 382 ResultSet resultSet = connection.getResultSet(); 383 384 if (resultSet != null && 385 resultSet.first()) { 383 if (resultSet.first()) { 386 384 // the node already exists - no need to do anything as such 387 385 GS3SQLUpdate update = new GS3SQLUpdate("metadata"); … … 390 388 } 391 389 else { // Set result set to null, just in case first() didn't work above... 392 resultSet = null;393 394 390 // It is a new node and needs writing 395 391 action = new GS3SQLInsert("metadata"); … … 403 399 404 400 // execute the action as required 405 connection.execute(action.toString());401 statement.execute(action.toString()); 406 402 407 403 // get the resultSet again … … 409 405 // 'MetadataRef' 410 406 // System.out.println(select.toString()); 411 connection.execute(select.toString()); 412 413 resultSet = connection.getResultSet(); 414 resultSet.first(); 415 416 417 // get the reference for this item... 418 sqlId = resultSet.getInt("MetadataRef"); 419 connection.closeStatement(); 407 resultSet = statement.executeQuery(select.toString()); 408 409 if (resultSet.first()) { 410 // get the reference for this item... 411 sqlId = resultSet.getInt("MetadataRef"); 412 } 413 statement.close(); 420 414 } 421 415 catch (SQLException sql){ 422 System.out.println(sql); 416 System.err.println("METSDescriptive.writeSQL(): "+sql); 417 } 418 if (sqlId == -1) { 419 return false; 423 420 } 424 421 … … 470 467 select.setWhere(where); 471 468 472 connection.execute(select.toString()); 473 474 // parse through the namespaces, calling the namespace class to create instances 475 // as it will 476 ResultSet namespaceSet = connection.getResultSet(); 477 478 // clone the connection cos we are still usign the old result set 479 GS3SQLConnection cloned_connection = connection.cloneConnection(); 480 481 if (namespaceSet != null && namespaceSet.first()) { 469 Statement statement = connection.createStatement(); 470 ResultSet namespaceSet = statement.executeQuery(select.toString()); 471 472 // parse through the namespaces, calling the namespace class to create instances as it will 473 if (namespaceSet.first()) { 482 474 do { 483 METSNamespace namespace = METSNamespace.readSQL(c loned_connection, namespaceSet);475 METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet); 484 476 if (namespace != null) { 485 477 descriptive.addNamespace(namespace); 486 478 } 487 479 else { 488 System. out.println("Null namespace output");480 System.err.println("Null namespace output"); 489 481 } 490 482 } 491 483 while (namespaceSet.next()); 492 484 } 493 cloned_connection.close(); 494 cloned_connection = null; 485 statement.close(); 495 486 return descriptive; 496 487 } 497 488 catch (SQLException sqlEx){ 498 System.out.println(sqlEx); 499 sqlEx.printStackTrace(); 489 System.err.println("METSDescriptive.readSQL(): "+sqlEx); 500 490 System.exit(1); 501 491 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java
r9851 r9858 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 … … 236 237 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 237 238 select.setWhere(new GS3SQLWhere(whereItem)); 238 connection.execute(select.toString());239 240 // clone the connection cos we are still using the old result set241 GS3SQLConnection cloned_connection = connection.cloneConnection();242 239 243 240 // start going through the matching metadata blocks 244 241 try { 245 ResultSet resultSet = connection.getResultSet(); 246 resultSet.first(); 247 do { 248 METSDescriptive descriptive = METSDescriptive.readSQL(document, cloned_connection, resultSet); 249 if (descriptive != null) { 250 set.addDescriptive(descriptive); 251 } 252 else { 253 System.out.println("Null descriptive"); 254 } 255 } while (resultSet.next()); 256 257 connection.closeStatement(); 242 Statement statement = connection.createStatement(); 243 ResultSet resultSet = statement.executeQuery(select.toString()); 244 if (resultSet.first()) { 245 do { 246 METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet); 247 if (descriptive != null) { 248 set.addDescriptive(descriptive); 249 } 250 else { 251 System.out.println("Null descriptive"); 252 } 253 } while (resultSet.next()); 254 } 255 statement.close(); 258 256 } 259 257 catch (SQLException sqlEx) { 260 System.out.println(sqlEx); 261 sqlEx.printStackTrace(); 258 System.err.println("METSDescriptiveSet.readSQL(): "+sqlEx); 262 259 System.exit(1); 263 260 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java
r9851 r9858 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 475 476 select.setWhere(where); 476 477 477 connection.execute(select.toString()); 478 Statement statement = null; 479 ResultSet resultSet = null; 478 480 479 481 // Do the actual writing 480 482 GS3SQLAction action; 481 483 482 ResultSet resultSet = connection.getResultSet();483 484 try { 484 if (resultSet == null || 485 !resultSet.first()) { 486 if (resultSet != null) { 487 resultSet.close(); 488 resultSet = null; 489 } 485 statement = connection.createStatement(); 486 resultSet = statement.executeQuery(select.toString()); 487 if (!resultSet.first()) { 490 488 491 489 GS3SQLInsert insert = new GS3SQLInsert("divisions"); … … 517 515 action.addValue("UserLabel", this.userLabel); 518 516 519 if (!connection.execute(action.toString())){ 517 try { 518 statement.execute(action.toString()); 519 } catch (SQLException e) { 520 System.err.println("METSDivision.writeSQL(): "+e); 520 521 return false; 521 522 } 522 523 523 524 // if doing a fresh item, get the new structure reference... 524 if ( resultSet == null){525 if (sqlRef == -1){ 525 526 // get the new structure reference 526 connection.execute(select.toString());527 528 // get the sql reference for the division529 527 try { 530 528 // read in the structure reference 531 resultSet = connection.getResultSet();532 if (resultSet == null) {533 return false;529 resultSet = statement.executeQuery(select.toString()); 530 if (resultSet.first()) { 531 sqlRef = resultSet.getInt("DivisionRef"); 534 532 } 535 resultSet.first();536 sqlRef = resultSet.getInt("DivisionRef");537 resultSet.close();538 resultSet = null;539 533 } 540 534 catch (SQLException sqlex) { 541 System.err.println(" Unable to retrieve reference for Division " + sqlex);535 System.err.println("METSDIVISION.writeSQL(): Unable to retrieve reference for Division " + sqlex); 542 536 return false; 543 537 } 544 538 } 545 // close the open resultSet, as we don't need it any longer...546 else {547 try {548 resultSet.close();549 }550 catch (SQLException sql) {551 System.err.println(sql + " " + select.toString());552 }553 }554 539 555 540 // delete the old file/metadata references 556 GS3SQLWhere referenceWhere = 557 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), 558 GS3SQLField.INTEGER_TYPE)); 559 560 GS3SQLDelete delete = new GS3SQLDelete("divisionfilerefs"); 561 delete.setWhere(referenceWhere); 562 connection.execute(delete.toString()); 563 564 delete = new GS3SQLDelete("divisionmetarefs"); 565 delete.setWhere(referenceWhere); 566 connection.execute(delete.toString()); 567 568 // write the new file references 569 if (this.fileRefs.size() > 0){ 570 Iterator iterator = this.fileRefs.iterator(); 571 572 while (iterator.hasNext()) { 573 GS3SQLInsert fileinsert = new GS3SQLInsert("divisionfilerefs"); 574 fileinsert.addValue("DocID", docId.toString()); 575 fileinsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 576 fileinsert.addValue("DivisionType", "Group"); 577 fileinsert.addValue("FileID", iterator.next().toString()); 578 connection.execute(fileinsert.toString()); 579 } 580 } 581 582 // write the metadata references 583 if (this.metadataRefs.size() > 0){ 584 Iterator iterator = this.metadataRefs.iterator(); 585 586 while (iterator.hasNext()) { 587 GS3SQLInsert metainsert = new GS3SQLInsert("divisionmetarefs"); 588 metainsert.addValue("DocID", docId.toString()); 589 metainsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 590 metainsert.addValue("DivisionType", "Group"); 591 metainsert.addValue("MetaID", iterator.next().toString()); 592 connection.execute(metainsert.toString()); 593 } 594 } 595 541 try { 542 GS3SQLWhere referenceWhere = 543 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), 544 GS3SQLField.INTEGER_TYPE)); 545 546 GS3SQLDelete delete = new GS3SQLDelete("divisionfilerefs"); 547 delete.setWhere(referenceWhere); 548 549 statement.execute(delete.toString()); 550 551 delete = new GS3SQLDelete("divisionmetarefs"); 552 delete.setWhere(referenceWhere); 553 statement.execute(delete.toString()); 554 555 // write the new file references 556 if (this.fileRefs.size() > 0){ 557 Iterator iterator = this.fileRefs.iterator(); 558 559 while (iterator.hasNext()) { 560 GS3SQLInsert fileinsert = new GS3SQLInsert("divisionfilerefs"); 561 fileinsert.addValue("DocID", docId.toString()); 562 fileinsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 563 fileinsert.addValue("DivisionType", "Group"); 564 fileinsert.addValue("FileID", iterator.next().toString()); 565 statement.execute(fileinsert.toString()); 566 } 567 } 568 569 // write the metadata references 570 if (this.metadataRefs.size() > 0){ 571 Iterator iterator = this.metadataRefs.iterator(); 572 573 while (iterator.hasNext()) { 574 GS3SQLInsert metainsert = new GS3SQLInsert("divisionmetarefs"); 575 metainsert.addValue("DocID", docId.toString()); 576 metainsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 577 metainsert.addValue("DivisionType", "Group"); 578 metainsert.addValue("MetaID", iterator.next().toString()); 579 statement.execute(metainsert.toString()); 580 } 581 } 582 statement.close(); 583 } catch (SQLException e) { 584 System.err.println("METSDIVISION.writeSQL(): "+e); 585 return false; 586 } 596 587 // write out any children in turn 597 588 Iterator groups = this.children.values().iterator(); … … 635 626 select.setWhere(where); 636 627 637 connection.execute(select.toString()); 628 Statement statement = connection.createStatement(); 629 ResultSet childSet = statement.executeQuery(select.toString()); 638 630 639 631 // circulate through to obtain further children 640 ResultSet childSet = connection.getResultSet();641 // clone the connection cos we are still usign the old result set642 GS3SQLConnection cloned_connection = connection.cloneConnection();643 644 632 if (childSet.first()) 645 633 { 646 634 do { 647 METSDivision childDivision = METSDivision.readSQL(c loned_connection, childSet);635 METSDivision childDivision = METSDivision.readSQL(connection, childSet); 648 636 division.addDivision(childDivision); 649 637 } 650 638 while (childSet.next()); 651 639 } 652 653 cloned_connection.close();654 cloned_connection = null;655 640 select = new GS3SQLSelect("divisionfilerefs"); 656 641 select.addField("*"); … … 659 644 select.setWhere(where); 660 645 661 connection.execute(select.toString()); 662 663 ResultSet fileSet = connection.getResultSet(); 664 if (fileSet != null && fileSet.first()){ 646 ResultSet fileSet = statement.executeQuery(select.toString()); 647 648 if (fileSet.first()){ 665 649 do { 666 650 String reference = fileSet.getString("FileID"); … … 669 653 while (fileSet.next()); 670 654 } 671 655 672 656 select = new GS3SQLSelect("divisionmetarefs"); 673 657 select.addField("*"); … … 676 660 select.setWhere(where); 677 661 678 connection.execute(select.toString()); 679 680 ResultSet metaSet = connection.getResultSet(); 681 if (metaSet != null && metaSet.first()){ 662 ResultSet metaSet = statement.executeQuery(select.toString()); 663 664 if (metaSet.first()){ 682 665 do { 683 666 String reference = metaSet.getString("MetaID"); … … 687 670 } 688 671 689 connection.closeStatement();672 statement.close(); 690 673 return division; 691 674 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java
r9851 r9858 11 11 import java.sql.ResultSet; 12 12 import java.sql.SQLException; 13 import java.sql.Statement; 13 14 14 15 import org.w3c.dom.Document; … … 201 202 where.add(whereItem); 202 203 select.setWhere(where); 203 connection.execute(select.toString()); 204 205 Statement statement = null; 204 206 205 207 // if not, then make an insert action 206 208 try { 207 ResultSet results = connection.getResultSet();208 if (results == null ||209 209 statement = connection.createStatement(); 210 ResultSet results = statement.executeQuery(select.toString()); 211 if (!results.first()){ 210 212 GS3SQLInsert insert = new GS3SQLInsert("files"); 211 213 … … 223 225 } 224 226 catch (SQLException ex){ 225 System.err.println( ex);227 System.err.println("METSFile.writeSQL(): "+ex); 226 228 return false; 227 229 } … … 230 232 action.addValue("MIMEType", this.MIMEType); 231 233 232 boolean return_val = connection.execute(action.toString()); 233 connection.closeStatement(); 234 return return_val; 234 try { 235 statement.execute(action.toString()); 236 statement.close(); 237 238 } catch (SQLException e) { 239 System.err.println("METSFile.writeSQL():"+e); 240 return false; 241 } 242 return true; 235 243 } 236 244 … … 250 258 } 251 259 catch (SQLException ex){ 252 System.out.println( ex);260 System.out.println("METSFile.readSQL(): "+ex); 253 261 } 254 262 catch (java.net.MalformedURLException urlEx){ 255 System.out.println( urlEx);263 System.out.println("METSFile.readSQL(): "+urlEx); 256 264 } 257 265 return null; … … 311 319 } catch (java.net.MalformedURLException ex) { 312 320 // TODO: raise error 313 System.err.println( ex);321 System.err.println("METSFile.parse_flocateXML(): "+ex); 314 322 } 315 323 return thisFilePos; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java
r9851 r9858 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(); 377 // clone the connection cos we are still usign the old result set 378 GS3SQLConnection cloned_connection = connection.cloneConnection(); 373 ResultSet childSet = statement.executeQuery(select.toString()); 379 374 if (childSet.first()) { 380 375 do { 381 METSFileGroup fileGroup = METSFileGroup.readSQL(document, c loned_connection, childSet);376 METSFileGroup fileGroup = METSFileGroup.readSQL(document, connection, childSet); 382 377 if (fileGroup != null) { 383 378 group.addGroup(fileGroup); … … 386 381 while (childSet.next()); 387 382 } 388 389 383 // now scan for file members 390 384 select = new GS3SQLSelect("files"); 391 385 select.addField("*"); 392 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), 393 GS3SQLField.INTEGER_TYPE); 386 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), GS3SQLField.INTEGER_TYPE); 394 387 where = new GS3SQLWhere(whereItem); 395 388 select.setWhere(where); 396 connection.execute(select.toString()); 397 398 ResultSet childFileSet = connection.getResultSet(); 399 if (childFileSet != null && childFileSet.first()) { 389 ResultSet childFileSet = statement.executeQuery(select.toString()); 390 if (childFileSet.first()) { 400 391 do { 401 METSFile file = METSFile.readSQL(c loned_connection, childFileSet);392 METSFile file = METSFile.readSQL(connection, childFileSet); 402 393 if (file != null) { 403 394 group.addFile(file); … … 406 397 while (childFileSet.next()); 407 398 } 408 cloned_connection.close(); 409 cloned_connection = null; 399 statement.close(); 410 400 return group; 411 401 } 412 402 catch (SQLException sqlEx){ 413 System. out.println(sqlEx);403 System.err.println("METSFileGroup.readSQL(): "+sqlEx); 414 404 System.exit(1); 415 405 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java
r9851 r9858 16 16 17 17 import java.sql.SQLException; 18 import java.sql.Statement; 18 19 import java.sql.ResultSet; 19 20 … … 232 233 insert.addValue("FileSecID", "test"); // TODO: remove magic string 233 234 234 if (!connection.execute(insert.toString())){ 235 Statement statement = null; 236 try { 237 statement = connection.createStatement(); 238 statement.execute(insert.toString()); 239 } catch (SQLException e) { 240 System.err.println("METSFileSet.writeSQL(): "+e); 235 241 return false; 236 242 } … … 246 252 247 253 try { 248 connection.execute(select.toString());249 250 ResultSet set = connection.getResultSet();251 set.first();252 int sectionRef = set.getInt("FileSectionRef");253 254 this.reference = Integer.toString(sectionRef);254 ResultSet set = statement.executeQuery(select.toString()); 255 if (set.first()) { 256 int sectionRef = set.getInt("FileSectionRef"); 257 258 this.reference = Integer.toString(sectionRef); 259 } 260 statement.close(); 255 261 } 256 262 catch (SQLException ex){ 257 System.out.println( ex);263 System.out.println("METSFileSet.writeSQL(): "+ex); 258 264 return false; 259 265 } 260 266 } 261 267 268 if (this.reference == null) { 269 return false; 270 } 262 271 // write out the children 263 272 while (groups.hasNext()){ … … 281 290 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 282 291 select.setWhere(new GS3SQLWhere(whereItem)); 283 connection.execute(select.toString()); 292 293 Statement statement = null; 284 294 285 295 // Get the identifier for this file set, etc. 286 ResultSet sections = connection.getResultSet(); 287 int fileSetRef; 296 int fileSetRef = -1; 288 297 try { 289 sections.first(); 290 fileSetRef = sections.getInt("FileSectionRef"); 291 set.reference = Integer.toString(fileSetRef); 298 statement = connection.createStatement(); 299 ResultSet sections = statement.executeQuery(select.toString()); 300 if (sections.first()) { 301 fileSetRef = sections.getInt("FileSectionRef"); 302 set.reference = Integer.toString(fileSetRef); 303 } else { 304 statement.close(); 305 return null; 306 } 307 292 308 } 293 309 catch (SQLException ex){ 294 System. out.println(ex);310 System.err.println("METSFileSet.readSQL() "+ex); 295 311 return null; 296 312 } 297 298 313 // Get child file groups 299 314 select = new GS3SQLSelect("filegroups"); … … 307 322 where.add(whereItem); 308 323 select.setWhere(where); 309 connection.execute(select.toString());310 311 324 // start going through the matching file groups 312 // clone the connection cos we are still usign the old result set313 GS3SQLConnection cloned_connection = connection.cloneConnection();314 325 try { 315 ResultSet resultSet = connection.getResultSet(); 316 resultSet.first(); 317 do { 318 METSFileGroup filegroup = METSFileGroup.readSQL(document, cloned_connection, resultSet); 319 if (filegroup != null) { 320 set.addGroup(filegroup); 321 } 322 } while (resultSet.next()); 323 324 cloned_connection.close(); 325 cloned_connection = null; 326 ResultSet resultSet = statement.executeQuery(select.toString()); 327 if (resultSet.first()) { 328 do { 329 METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet); 330 if (filegroup != null) { 331 set.addGroup(filegroup); 332 } 333 } while (resultSet.next()); 334 } 335 statement.close(); 326 336 } 327 337 catch (SQLException sqlEx) { 328 System.out.println(sqlEx); 329 sqlEx.printStackTrace(); 338 System.out.println("METSFileSet.readSQL(): "+sqlEx); 330 339 System.exit(1); 331 340 } 332 333 341 return set; 334 342 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java
r8742 r9858 6 6 import java.util.Iterator; 7 7 import java.sql.SQLException; 8 import java.sql.Statement; 8 9 import java.sql.ResultSet; 9 10 … … 150 151 151 152 // Execute the action 152 connection.execute(action.toString()); 153 153 Statement statement = null; 154 try { 155 statement = connection.createStatement(); 156 statement.execute(action.toString()); 157 } catch (SQLException e) { 158 System.err.println("METSNamespace.writeSQL(): "+e); 159 return false; 160 } 154 161 // then get the namespace reference number if needsbe... 155 162 if (this.id == null) { … … 161 168 where.add(where); 162 169 try { 163 connection.execute(select.toString());164 165 ResultSet result = connection.getResultSet();166 result.last();167 this.id = Integer.toString(result.getInt("NamespaceRef"));170 ResultSet result = statement.executeQuery(select.toString()); 171 if (result.last()) { 172 this.id = Integer.toString(result.getInt("NamespaceRef")); 173 } 174 statement.close(); 168 175 } 169 176 catch (SQLException sqlex){ 170 177 this.id = null; 171 System.err.println( sqlex);178 System.err.println("METSNamespace.writeSQL(): "+sqlex); 172 179 return false; 173 180 } … … 201 208 select.setWhere(where); 202 209 203 connection.execute(select.toString()); 204 205 ResultSet valuesSet = connection.getResultSet(); 206 if (valuesSet != null && valuesSet.first()) { 210 Statement statement = connection.createStatement(); 211 ResultSet valuesSet = statement.executeQuery(select.toString()); 212 if (valuesSet.first()) { 207 213 do { 208 214 String label = valuesSet.getString("Label"); … … 213 219 while (valuesSet.next()); 214 220 } 215 221 statement.close(); 216 222 return namespace; 217 223 } 218 224 catch (java.net.MalformedURLException urlEx){ 219 System. out.println(urlEx);225 System.err.println("METSNamespace.readSQL(): "+urlEx); 220 226 } 221 227 catch (SQLException sqlEx){ 222 System. out.println(sqlEx);228 System.err.println("METSNamespace.readSQL(): "+sqlEx); 223 229 } 224 230 return null; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java
r9851 r9858 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 180 181 { 181 182 int sqlRef = -1; 182 ResultSet results; 183 183 ResultSet results = null; 184 Statement statement = null; 185 184 186 // Prepare query to see if this structure has already been written 185 187 GS3SQLSelect select = new GS3SQLSelect("structure"); … … 190 192 where.add(item); 191 193 select.setWhere(where); 192 194 193 195 // attempt to execute the query & get the current structure's reference 194 196 try { 195 connection.execute(select.toString()); 196 results = connection.getResultSet(); 197 if (results != null && 198 results.first()){ 197 statement = connection.createStatement(); 198 results = statement.executeQuery(select.toString()); 199 if (results.first()){ 199 200 sqlRef = results.getInt("structureRef"); 200 201 } 201 else {202 results = null;203 }204 205 if (results != null) {206 results.close();207 }208 202 } 209 203 catch (SQLException sqlEx) { 210 System.err.print( sqlEx);204 System.err.print("METSStructure.writeSQL(): "+sqlEx); 211 205 return false; 212 206 } 213 207 214 208 // insert a new structure if it wasn't there previously 215 if ( results == null) {209 if (sqlRef == -1) { 216 210 GS3SQLInsert insert = new GS3SQLInsert("structure"); 217 211 insert.addValue("DocID", document.getID().toString()); … … 220 214 insert.addValue("Label", this.label); 221 215 222 if (!connection.execute(insert.toString())) { 216 try { 217 statement.execute(insert.toString()); 218 219 // get the new structure reference by re-running the original select object 220 results = statement.executeQuery(select.toString()); 221 if (results.first()) { 222 sqlRef = results.getInt("StructureRef"); 223 } 224 } catch (SQLException sqlEx) { 225 System.err.print("METSStructure.writeSQL(): "+sqlEx); 223 226 return false; 224 227 } 225 228 226 // get the new structure reference by re-running the original select object227 connection.execute(select.toString());228 229 try {230 results = connection.getResultSet();231 results.first();232 sqlRef = results.getInt("StructureRef");233 }234 catch (SQLException sql) {235 System.err.println(sql);236 return false;237 }238 229 } 239 230 else { … … 244 235 update.addValue("Label", this.label); 245 236 246 connection.execute(update.toString()); 247 } 248 237 try { 238 statement.execute(update.toString()); 239 } catch (SQLException sqlEx) { 240 System.err.print("METSStructure.writeSQL(): "+sqlEx); 241 return false; 242 } 243 } 244 245 // close the statement 246 try { 247 statement.close(); 248 } catch (SQLException e) { 249 System.err.println("METSStructure.writeSQL(): "+e); 250 } 249 251 // write out the child groups (Divisions) now... 250 252 Iterator groups = this.children.values().iterator(); … … 296 298 select.setWhere(where); 297 299 298 connection.execute(select.toString()); 300 Statement statement = connection.createStatement(); 301 ResultSet divisionSet = statement.executeQuery(select.toString()); 299 302 300 303 // parse through the divisions 301 ResultSet divisionSet = connection.getResultSet(); 302 // use a new connection for the following bit, cos we still want to use results from the last execute 303 GS3SQLConnection cloned_connection = connection.cloneConnection(); 304 if (divisionSet != null && divisionSet.first()) { 304 if (divisionSet.first()) { 305 305 do { 306 METSDivision division = METSDivision.readSQL(c loned_connection, divisionSet);306 METSDivision division = METSDivision.readSQL(connection, divisionSet); 307 307 if (division != null) { 308 308 structure.addDivision(division); … … 311 311 while (divisionSet.next()); 312 312 } 313 cloned_connection.close(); 314 cloned_connection = null; 313 statement.close(); 315 314 return structure; 316 315 } 317 catch (SQLException sqlEx) 318 { System.out.println(sqlEx + " " + select.toString()); 319 sqlEx.printStackTrace(); 316 catch (SQLException sqlEx) { 317 System.err.println("METSStructure.readSQL(): "+ sqlEx + " " + select.toString()); 320 318 System.exit(1); 321 319 } 322 320 return null; 323 321 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java
r9851 r9858 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 157 158 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 158 159 select.setWhere(new GS3SQLWhere(whereItem)); 159 connection.execute(select.toString()); 160 // clone the connection cos we are still usign the old result set 161 GS3SQLConnection cloned_connection = connection.cloneConnection(); 162 160 163 161 // start going through the matching metadata blocks 164 162 try { 165 ResultSet resultSet = connection.getResultSet(); 166 resultSet.first(); 167 do { 168 METSStructure structure = METSStructure.readSQL(document, cloned_connection, resultSet); 169 if (structure != null) { 170 set.addStructure(structure); 171 } 172 } while (resultSet.next()); 173 cloned_connection.close(); 174 cloned_connection = null; 163 Statement statement = connection.createStatement(); 164 ResultSet resultSet = statement.executeQuery(select.toString()); 165 if (resultSet.first()) { 166 do { 167 METSStructure structure = METSStructure.readSQL(document, connection, resultSet); 168 if (structure != null) { 169 set.addStructure(structure); 170 } 171 } while (resultSet.next()); 172 } 173 statement.close(); 175 174 } 176 175 catch (SQLException sqlEx) { 177 System.out.println(sqlEx); 178 sqlEx.printStackTrace(); 176 System.err.println("METSStructureSet.readSQL(): "+sqlEx); 179 177 System.exit(1); 180 178 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/SimpleNamespace.java
r8742 r9858 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 … … 281 282 } 282 283 284 Statement statement = null; 285 ResultSet results = null; 283 286 try { 287 statement = connection.createStatement(); 284 288 if (this.id == null) { 285 289 GS3SQLSelect select = new GS3SQLSelect("namespaces"); 286 290 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("MetadataRef", "=", Integer.toString(parentId), GS3SQLField.INTEGER_TYPE))); 287 291 select.addField("NamespaceRef"); 288 connection.execute(select.toString()); 289 290 ResultSet results = connection.getResultSet(); 291 results.first(); 292 sqlId = Integer.toString(results.getInt("NamespaceRef")); 292 results = statement.executeQuery(select.toString()); 293 if (results.first()) { 294 sqlId = Integer.toString(results.getInt("NamespaceRef")); 295 } else { 296 statement.close(); 297 return false; 298 } 293 299 } 294 300 else { … … 300 306 GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("NamespaceRef", "=", sqlId, GS3SQLField.INTEGER_TYPE)); 301 307 delete.setWhere(where); 302 connection.execute(delete.toString());308 statement.execute(delete.toString()); 303 309 304 310 // write out the metadata for this namespace … … 316 322 insert.addValue("Label", thisKey); 317 323 insert.addValue("Value", value); 318 connection.execute(insert.toString()); 319 } 320 } 324 statement.execute(insert.toString()); 325 } 326 } 327 statement.close(); 321 328 } 322 329 catch (SQLException sql) { 323 System.out.println( sql);330 System.out.println("SimpleNamespace.writeSQL(): "+sql); 324 331 } 325 332 return true;
Note:
See TracChangeset
for help on using the changeset viewer.