Changeset 9858
- Timestamp:
- 2005-05-12T14:52:45+12:00 (19 years ago)
- Location:
- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java
r8969 r9858 216 216 GS3SQLSelect select = new GS3SQLSelect("build"); 217 217 select.addField("*"); 218 this.database.execute(select.toString()); 219 ResultSet results = this.database.getResultSet(); 220 if (results != null && 221 results.first()) { 218 Statement statement = this.database.createStatement(); 219 ResultSet results = statement.executeQuery(select.toString()); 220 if (results.first()) { 222 221 System.out.println("Reading all keys"); 223 222 do { … … 238 237 } while (results.next()); 239 238 } 239 statement.close(); 240 240 } 241 241 catch (SQLException ex) … … 479 479 480 480 // Update build date information 481 GS3SQLDelete remove = new GS3SQLDelete("build"); 482 // GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("buildKey", "=", "NextSeqNo")); 483 // rem 484 this.database.execute(remove.toString()); 485 486 GS3SQLInsert insert = new GS3SQLInsert("build"); 487 insert.addValue("buildKey", "NextSeqNo"); 488 insert.addValue("buildValue", Integer.toString(this.buildDocNo)); 489 this.database.execute(insert.toString()); 490 491 insert = new GS3SQLInsert("build"); 492 insert.addValue("buildKey", "lastBuildDate"); 493 insert.addValue("buildValue", getDateString(this.lastBuildDate)); 494 this.database.execute(insert.toString()); 495 481 try { 482 GS3SQLDelete remove = new GS3SQLDelete("build"); 483 // GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("buildKey", "=", "NextSeqNo")); 484 // rem 485 Statement statement = this.database.createStatement(); 486 statement.execute(remove.toString()); 487 488 GS3SQLInsert insert = new GS3SQLInsert("build"); 489 insert.addValue("buildKey", "NextSeqNo"); 490 insert.addValue("buildValue", Integer.toString(this.buildDocNo)); 491 statement.execute(insert.toString()); 492 493 insert = new GS3SQLInsert("build"); 494 insert.addValue("buildKey", "lastBuildDate"); 495 insert.addValue("buildValue", getDateString(this.lastBuildDate)); 496 statement.execute(insert.toString()); 497 statement.close(); 498 } catch (SQLException e) { 499 System.err.println("CollectionManager.endBuild(): Can't update build information: "+e); 500 } 501 496 502 // Do tail of build output 497 503 Date startDate = this.lastBuildDate.getTime(); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java
r8742 r9858 9 9 import java.sql.ResultSet; 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 12 13 import org.xml.sax.XMLReader; … … 189 190 select.setWhere(where); 190 191 191 connection.execute(select.toString());192 192 193 193 try { 194 ResultSet results = connection.getResultSet(); 195 if (results != null && results.first()) { 194 Statement statement = connection.createStatement(); 195 ResultSet results = statement.executeQuery(select.toString()); 196 if (results.first()) { 196 197 GS3SQLUpdate update = new GS3SQLUpdate("classifiers"); 197 198 update.setWhere(where); … … 206 207 207 208 action = insert; 209 classifyRef = -1; 208 210 } 209 211 action.addValue("ClassifyID", label); … … 213 215 action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE); 214 216 215 connection.execute(action.toString()); 216 classifyRef = -1; 217 } 218 catch (SQLException sqlEx) { 219 System.err.println(sqlEx); 220 return -1; 221 } 222 223 // get the ClassifyRef if we don't already have it (have done a 224 // insert action above)... 225 if (classifyRef == -1) { 226 connection.execute(select.toString()); 227 228 try { 229 ResultSet results = connection.getResultSet(); 230 if (results == null || !results.first()) { 217 // do the update/insert 218 statement.execute(action.toString()); 219 220 221 // get the ClassifyRef if we don't already have it (have done a 222 // insert action above)... 223 if (classifyRef == -1) { 224 results = statement.executeQuery(select.toString()); 225 if (!results.first()) { 231 226 return -1; 232 227 } … … 234 229 classifyRef = results.getInt("ClassifyRef"); 235 230 } 236 catch (SQLException sqlEx) { 237 System.err.println(sqlEx); 231 232 statement.close(); 233 } catch (SQLException sqlEx) { 234 System.err.println("AZListClassifier.writeSQLClassifyNode(): "+sqlEx); 238 235 return -1; 239 240 }236 } 237 241 238 242 239 return classifyRef; … … 274 271 } 275 272 273 try { 274 Statement statement = connection.createStatement(); 275 276 276 List children; 277 277 … … 292 292 Iterator iterator = childDocs.iterator(); 293 293 int childOrder = 1; 294 //St 294 295 while (iterator.hasNext()) { 295 296 AZDocumentItem documentItem = (AZDocumentItem) iterator.next(); … … 301 302 insert.addValue("DocOrder", Integer.toString(childOrder), GS3SQLField.INTEGER_TYPE); 302 303 303 connection.execute(insert.toString());304 statement.execute(insert.toString()); 304 305 305 306 childOrder ++; … … 310 311 } 311 312 313 312 314 /* 313 315 else { … … 318 320 delete.setWhere(where); 319 321 320 connection.execute(delete.toString());322 statement.execute(delete.toString()); 321 323 } 322 324 … … 331 333 } 332 334 */ 335 statement.close(); 336 } catch (SQLException e) { 337 System.err.println("AZListClassifier.writeSQL(): "+e); 338 return false; 339 } 333 340 334 341 return true; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
r8742 r9858 7 7 import java.sql.ResultSet; 8 8 import java.sql.SQLException; 9 import java.sql.Statement; 9 10 10 11 import org.greenstone.gsdl3.gs3build.doctypes.DocumentID; … … 273 274 GS3SQLInsert insert; 274 275 276 Statement statement; 277 // can we connect to the database? 278 try { 279 statement = connection.createStatement(); 280 } catch (SQLException e) { 281 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 282 return false; 283 } 284 275 285 // Get own full id 276 286 String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix; … … 283 293 select.setWhere(where); 284 294 285 connection.execute(select.toString());286 295 287 296 // update or insert the classifier as required 288 297 try { 289 ResultSet results = connection.getResultSet();290 if (results != null && results.first()) {298 ResultSet results = statement.executeQuery(select.toString()); 299 if (results.first()) { 291 300 GS3SQLUpdate update = new GS3SQLUpdate("classifiers"); 292 301 update.setWhere(where); … … 313 322 314 323 action = insert; 324 classifyRef = -1; 315 325 } 316 326 action.addValue("ClassifyID", fullId); … … 331 341 action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE); 332 342 333 connection.execute(action.toString()); 334 classifyRef = -1; 343 statement.execute(action.toString()); 335 344 } 336 345 catch (SQLException sqlEx) { 337 346 if (action == null) { 338 System.err.println( sqlEx);347 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx); 339 348 } 340 349 else { 341 System.err.println( sqlEx + " " + action.toString());350 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx + " " + action.toString()); 342 351 } 343 352 return false; … … 347 356 // insert action above)... 348 357 if (classifyRef == -1) { 349 connection.execute(select.toString());350 351 358 try { 352 ResultSet results = connection.getResultSet(); 353 if (results == null || !results.first()) { 354 return false; 359 ResultSet results = statement.executeQuery(select.toString()); 360 if (!results.first()) { 361 statement.close(); 362 return false; 355 363 } 356 364 357 365 classifyRef = results.getInt("ClassifyRef"); 366 358 367 } 359 368 catch (SQLException sqlEx) { 360 System.err.println( sqlEx);369 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx); 361 370 return false; 362 371 } … … 368 377 GS3SQLDelete delete = new GS3SQLDelete("classdocuments"); 369 378 delete.setWhere(where); 370 371 connection.execute(delete.toString()); 372 } 373 379 try { 380 statement.execute(delete.toString()); 381 } catch (SQLException e) { 382 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 383 return false; 384 } 385 } 386 374 387 // post the child nodes... 375 388 Iterator iterator = this.childNodes.iterator(); … … 379 392 if (!childNode.writeSQL(connection)) { 380 393 System.out.println("Failed to write " ); 381 return false;394 return false; 382 395 } 383 396 } … … 394 407 insert.addValue("DocID", docId.toString()); 395 408 insert.addValue("DocOrder", Integer.toString(order), GS3SQLField.INTEGER_TYPE); 396 397 connection.execute(insert.toString()); 398 409 try { 410 statement.execute(insert.toString()); 411 } catch (SQLException e) { 412 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 413 return false; 414 } 399 415 order ++; 400 416 } 417 // close the statment 418 try { 419 statement.close(); 420 } catch (SQLException e) { 421 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 422 } 423 401 424 return true; 402 425 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java
r9847 r9858 65 65 66 66 try { 67 statement = this.connection.createStatement();67 Statement statement = this.connection.createStatement(); 68 68 69 69 // create build history table … … 236 236 { 237 237 System.out.println(ex.toString()); 238 if (statement != null) {239 try {240 statement.close();241 } catch (Exception e){}242 statement = null;243 }244 238 return false; 245 239 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java
r9847 r9858 10 10 { 11 11 protected Connection connection; 12 protected Statement statement;13 12 protected String database; 14 13 … … 24 23 this.connection.close(); 25 24 } catch (Exception e) {} 26 } 27 if (this.statement!=null) { 28 try { 29 this.statement.close(); 30 } catch (Exception e) {} 31 } 32 25 } 33 26 this.connection = null; 34 this.statement = null;35 36 27 } 37 28 … … 39 30 finalize(); 40 31 } 41 42 public boolean execute(String sql)43 {44 try {45 if (this.statement != null) {46 this.statement.close();47 }48 this.statement = this.connection.createStatement();49 this.statement.execute(sql);50 }51 catch (SQLException ex) {52 System.out.println(ex);53 return false;54 }55 return true;56 }57 32 58 public void closeStatement() { 59 try { 60 if (this.statement != null) { 61 this.statement.close(); 62 } 63 } catch (Exception e) {} 64 65 } 66 public Statement createStatement() 33 public Statement createStatement() throws SQLException 67 34 { 68 try { 69 return this.connection.createStatement(); 70 } 71 catch (SQLException ex) { 72 return null; 73 } 74 } 75 76 public Statement getStatement() 77 { 78 return this.statement; 79 } 80 81 public ResultSet getResultSet() 82 { 83 try { 84 return this.statement.getResultSet(); 85 } 86 catch (SQLException ex) { 87 return null; 88 } 35 return this.connection.createStatement(); 89 36 } 90 37 … … 105 52 public boolean dropDatabase(String database) { 106 53 try { 107 this.statement = this.connection.createStatement();108 this.statement.execute("DROP DATABASE "+database+";");109 this.statement.close();54 Statement statement = this.connection.createStatement(); 55 statement.execute("DROP DATABASE "+database+";"); 56 statement.close(); 110 57 } 111 58 catch (SQLException ex){ … … 120 67 try { 121 68 String command = "CREATE DATABASE " + database; 122 this.statement = this.connection.createStatement();123 this.statement.execute(command);124 this.statement.close();69 Statement statement = this.connection.createStatement(); 70 statement.execute(command); 71 statement.close(); 125 72 } catch (Exception e) { 126 73 System.err.println(e); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java
r9849 r9858 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 import java.sql.Timestamp; … … 190 191 // Query for documents using the same file... 191 192 String query = "SELECT DocID FROM files INNER JOIN filegroups ON files.FileGroupRef=filegroups.FileGroupRef WHERE (filegroups.FileGroupId=\"default\" AND files.FileLocation=\"" + this.fileSet.getFile(0).getLocation().toString() + "\")"; 192 connection.execute(query);193 194 List docs = new ArrayList();195 ResultSet results = connection.getResultSet();196 197 193 try { 198 if (results != null && 199 results.first()) 200 { do { 201 String value = results.getString("DocID"); 202 203 docs.add(value); 204 } while (results.next()); 205 206 Iterator docIterator = docs.iterator(); 207 while (docIterator.hasNext()) { 208 String docId = docIterator.next().toString(); 209 String innerQuery = "SELECT * FROM document WHERE DocID=\"" + docId + "\""; 210 connection.execute(innerQuery); 211 ResultSet innerSet = connection.getResultSet(); 212 if (innerSet != null && innerSet.first()) { 213 String docType = innerSet.getString("DocType"); 214 if (docType.equals(this.getDocumentType())) { 215 return docId; 194 Statement statement = connection.createStatement(); 195 ResultSet results = statement.executeQuery(query); 196 197 List docs = new ArrayList(); 198 199 if (results.first()) { 200 do { 201 String value = results.getString("DocID"); 202 docs.add(value); 203 } while (results.next()); 204 205 Iterator docIterator = docs.iterator(); 206 while (docIterator.hasNext()) { 207 String docId = docIterator.next().toString(); 208 String innerQuery = "SELECT * FROM document WHERE DocID=\"" + docId + "\""; 209 results = statement.executeQuery(innerQuery); 210 if (results.first()) { 211 String docType = results.getString("DocType"); 212 if (docType.equals(this.getDocumentType())) { 213 return docId; 214 } 215 } 216 216 } 217 }218 217 } 219 } 218 statement.close(); 220 219 } 221 220 catch (java.sql.SQLException sqlEx) { 222 System.err.println( sqlEx);221 System.err.println("AbstractDocument.getDuplicateID(): "+sqlEx); 223 222 } 224 223 … … 454 453 // Use a factory method to create the correct subtype... 455 454 AbstractDocument document = DocumentFactory.createDocument(type, id); 456 457 455 // Append the document date information 458 456 document.indexDate = sqlResult.getTimestamp("IndexedDate"); … … 460 458 document.modifiedDate = sqlResult.getTimestamp("ModifiedDate"); 461 459 462 // Note that once we have used the connection for something else, our results are closed.463 460 // Get the individual components of the document 464 461 METSFileSet fileSet = METSFileSet.readSQL(document, connection); … … 474 471 } 475 472 catch (SQLException sqlEx) { 476 System. out.println("Failure to load document: " + sqlEx);473 System.err.println("AbstractDocument.readSQL(): Failure to load document: " + sqlEx); 477 474 } 478 475 return null; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java
r8742 r9858 2 2 3 3 import java.sql.SQLException; 4 import java.sql.Statement; 4 5 import java.sql.ResultSet; 5 6 import java.net.URL; … … 61 62 { 62 63 String query = "SELECT * FROM document WHERE DocID=\""+id.toString()+"\";"; 63 connection.execute(query);64 65 64 try { 66 ResultSet results = connection.getResultSet(); 67 if (results != null && results.first()) { 68 return AbstractDocument.readSQL(connection, results); 69 } 65 Statement statement = connection.createStatement(); 66 ResultSet results = statement.executeQuery(query); 67 68 DocumentInterface di = null; 69 if (results.first()) { 70 di = AbstractDocument.readSQL(connection, results); 71 } 72 statement.close(); 73 return di; 70 74 } 71 75 catch (SQLException sqlEx) { 72 System.err.println( sqlEx);76 System.err.println("AbstractDocument.readSQLDocument():"+sqlEx); 73 77 } 74 78 return null; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java
r9850 r9858 13 13 14 14 import java.sql.SQLException; 15 import java.sql.Statement; 15 16 import java.sql.ResultSet; 16 17 … … 68 69 select.setWhere(where); 69 70 70 this.connection.execute(select.toString()); 71 72 ResultSet results = this.connection.getResultSet(); 73 if (results != null) { 74 select = new GS3SQLSelect("filegroups"); 75 select.addField("DocID"); 76 select.setDistinct(true); 77 78 where = new GS3SQLWhere(); 79 where.setCondition(GS3SQLWhere.OR_CONDITION); 80 81 GS3SQLWhereItem whereItem = null; 82 83 try { 84 results.first(); 71 try { 72 Statement statement = connection.createStatement(); 73 ResultSet results = statement.executeQuery(select.toString()); 74 75 select = new GS3SQLSelect("filegroups"); 76 select.addField("DocID"); 77 select.setDistinct(true); 78 79 where = new GS3SQLWhere(); 80 where.setCondition(GS3SQLWhere.OR_CONDITION); 81 82 GS3SQLWhereItem whereItem = null; 83 84 results.first(); 85 85 do { 86 86 int fileGroupRef = results.getInt("FileGroupRef"); … … 90 90 while (results.next()); 91 91 select.setWhere(where); 92 results.close(); 93 94 this.connection.execute(select.toString()); 95 96 results = this.connection.getResultSet(); 92 93 results = statement.executeQuery(select.toString()); 94 97 95 results.first(); 98 96 do { … … 100 98 reply.add(docId); 101 99 } while (results.next()); 102 } 103 catch (SQLException sqlEx) 104 { System.err.println(sqlEx); 105 } 106 } 100 statement.close(); 101 } 102 catch (SQLException sqlEx) { 103 System.err.println("DocumentList.getDocumentIdsWithFile(): "+sqlEx); 104 } 105 107 106 return reply; 108 107 } … … 173 172 } 174 173 175 private List findDocumentIdsUsingFileQuery(String query) 176 { this.connection.execute(query); 177 178 try { 179 180 ResultSet results = this.connection.getResultSet(); 181 if (results == null || 182 !results.first()) { 183 return null; 184 } 174 private List findDocumentIdsUsingFileQuery(String query) { 175 176 try { 177 178 Statement statement = connection.createStatement(); 179 ResultSet results = statement.executeQuery(query); 180 181 if (!results.first()) { 182 statement.close(); 183 return null; 184 } 185 185 186 186 // get a list of group ids first and turn it into a query on filegroups … … 207 207 // structures...recreating new filegroup queries as necessary 208 208 while (queryBuffer.length() > 0) { 209 connection.execute(queryBuffer.toString());210 211 results = this.connection.getResultSet();212 if (results == null || !results.first()) {213 return null;209 results = statement.executeQuery(queryBuffer.toString()); 210 211 if (!results.first()) { 212 statement.close(); 213 return null; 214 214 } 215 215 … … 256 256 257 257 // execute the division query 258 this.connection.execute(queryBuffer.toString()); 259 260 results = this.connection.getResultSet(); 261 if (results == null || 262 !results.first()) { 263 return null; 258 results = statement.executeQuery(queryBuffer.toString()); 259 260 if (!results.first()) { 261 statement.close(); 262 return null; 264 263 } 265 264 … … 268 267 reply.add(results.getString("DocID")); 269 268 } while (results.next()); 270 269 270 statement.close(); 271 271 return reply; 272 272 } 273 273 catch (SQLException ex) { 274 System.err.println( ex);274 System.err.println("DocumentList.findDocumentIdsUsingFileQuery()"+ ex); 275 275 } 276 276 return null; … … 454 454 select.addField("*"); 455 455 456 ResultSet documents;457 456 try { 458 connection.execute(select.toString()); 459 documents = connection.getResultSet(); 460 461 457 Statement statement = connection.createStatement(); 458 ResultSet documents = statement.executeQuery(select.toString()); 462 459 if (documents.first()) { 463 // clone the connection cos we are still usign the old result set464 GS3SQLConnection cloned_connection = connection.cloneConnection();465 466 460 do { 467 DocumentInterface document = AbstractDocument.readSQL(c loned_connection, documents);461 DocumentInterface document = AbstractDocument.readSQL(connection, documents); 468 462 list.addDocument(document); 469 463 } 470 464 while (documents.next()); 471 cloned_connection.close(); 472 cloned_connection = null; 473 } 465 } 466 statement.close(); 474 467 } 475 468 catch (java.sql.SQLException ex) { 476 System.out.println(ex); 477 ex.printStackTrace(); 469 System.out.println("DocumentList.writeSQLDocuments(): "+ex); 478 470 return null; 479 471 } … … 494 486 { 495 487 private boolean hasNext; 488 private Statement statement; 496 489 private ResultSet resultSet; 497 490 private GS3SQLConnection connection; … … 505 498 506 499 try { 507 connection.execute(select.toString());508 this.resultSet = connection.getResultSet();500 this.statement = connection.createStatement(); 501 this.resultSet = statement.executeQuery(select.toString()); 509 502 this.hasNext = this.resultSet.first(); 510 503 } catch (SQLException ex) { 504 System.err.println("DocumentListIterator(): "+ex); 511 505 this.hasNext = false; 512 506 } … … 527 521 528 522 if (!this.hasNext) { 529 this.resultSet.close(); // be a good citizen & close used result sets523 this.statement.close(); // be a good citizen & close used statement 530 524 } 531 525 } catch (SQLException ex) { 526 System.err.println("DocumentList.iterator.next(): "+ex); 532 527 this.hasNext = false; 533 528 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java
r8742 r9858 19 19 update.addDate("IndexedDate", new java.sql.Timestamp(touchTime)); 20 20 update.addDate("ModifiedDate", new java.sql.Timestamp(modTime)); 21 connection.execute(update.toString()); 21 try { 22 Statement statement = connection.createStatement(); 23 statement.execute(update.toString()); 24 statement.close(); 25 } catch (SQLException e) { 26 System.err.println("DocumentSQLWriter.touchDocument() Error: "+ e); 27 return false; 28 } 22 29 System.out.println(update.toString()); 23 30 return true; … … 39 46 select.addField("*"); 40 47 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString()))); 41 connection.execute(select.toString());42 48 43 ResultSet results = connection.getResultSet(); 44 45 if (results == null || 46 !results.first()) 47 { GS3SQLInsert insert = new GS3SQLInsert("document"); 49 Statement statement = connection.createStatement(); 50 ResultSet results = statement.executeQuery(select.toString()); 51 if (!results.first()) { // empty result 52 GS3SQLInsert insert = new GS3SQLInsert("document"); 48 53 insert.addValue("DocID", document.getID().toString()); 49 54 insert.addValue("DocType", document.getDocumentType()); … … 53 58 insert.addDate("ModifiedDate", new java.sql.Timestamp(document.getModifiedDatestamp())); 54 59 55 connection.execute(insert.toString());60 statement.execute(insert.toString()); 56 61 } 57 62 else { … … 61 66 // connection.execute(update.toString()); 62 67 } 68 statement.close(); 63 69 } 64 } catch ( Exception ex) {65 System.out.println( ex);70 } catch (SQLException ex) { 71 System.out.println("DocumentSQLWriter.writeDocument() Error:"+ex); 66 72 } 67 73 // output.println(tag); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/HTMLDocument.java
r8929 r9858 279 279 public Document getDOMDocument() 280 280 { 281 if (this.domDocument == null) {281 if (this.domDocument == null) { 282 282 URL url =(URL) this.fileSet.getFile(0).getLocation(); 283 283 this.loadDocument(url); -
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; -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r9848 r9858 27 27 String lastBuild = dateToSqlString(collManager.getBuildDate()); 28 28 System.out.println("last build was " + lastBuild); 29 Statement statement = collManager.getDatabase().createStatement();30 29 try { 30 Statement statement = collManager.getDatabase().createStatement(); 31 31 // detect all new documents. A document is new if and only if 32 32 // AccessionDate >= CollectionLastRebuiltDate … … 130 130 private String getDocumentTitle(String documentID, GS3SQLConnection database) { 131 131 System.out.println("getting title for document " + documentID + " from database"); 132 Statement statement = database.createStatement();133 132 134 ResultSet results;135 133 try { 134 Statement statement = database.createStatement(); 136 135 String sqlString = "SELECT mdvalues.value " + 137 136 "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " + … … 144 143 " AND d.parenttype = 'Structure' " + 145 144 " AND m.docID = s.docid;"; 146 results = statement.executeQuery(sqlString);147 if (results. next()) {145 ResultSet results = statement.executeQuery(sqlString); 146 if (results.first()) { 148 147 String title = results.getString("value"); 149 148 System.out.println("title is " + title); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/util/SQLQuery.java
r9822 r9858 6 6 import java.sql.ResultSet; 7 7 import java.sql.SQLException; 8 import java.sql.Statement; 8 9 9 10 import java.util.ArrayList; … … 17 18 18 19 public boolean setDatabase(String db_name) { 19 try {20 connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);21 20 connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name); 21 try { 22 22 23 // test the connection 23 24 String query = "select * from "+GSSQL.DOCUMENT_TABLE+GSSQL.END; 24 if (!connection.execute(query)) { 25 //connection.close(); 26 connection = null; 27 return false; 28 } 25 Statement s = connection.createStatement(); 26 s.execute(query); 27 s.close(); 29 28 return true; 30 29 } catch (Exception e) { 31 System.err.println("SQLQuery.setDatabase Exception"); 32 return false; 33 } 30 System.err.println("SQLQuery.setDatabase():"+e); 31 } 32 closeConnection(); 33 return false; 34 34 } 35 35 36 36 public void closeConnection() { 37 connection=null; 37 if (connection != null) { 38 connection.close(); 39 connection=null; 40 } 38 41 } 39 42 … … 52 55 GSSQL.END; 53 56 54 connection.execute(query);57 Statement statement = null; 55 58 ResultSet results = null; 56 59 String doc_id = null; 57 60 String meta_id = null; 58 61 try { 59 results = connection.getResultSet(); 60 results.first(); 61 doc_id = results.getString(GSSQL.DOCUMENT_ID); 62 meta_id = results.getString(GSSQL.METADATA_ID); 63 } catch (java.sql.SQLException e) { 64 65 System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage()); 66 return null; 67 } 68 System.out.println("doc id ="+doc_id+", meta id = "+meta_id); 62 statement = connection.createStatement(); 63 results = statement.executeQuery(query); 64 if (results.first()) { 65 doc_id = results.getString(GSSQL.DOCUMENT_ID); 66 meta_id = results.getString(GSSQL.METADATA_ID); 67 } else { 68 statement.close(); 69 return null; 70 } 71 } catch (java.sql.SQLException e) { 72 System.err.println("SQLQuery.MGNum2OID(): "+e); 73 return null; 74 } 69 75 70 76 // now get division label … … 77 83 GSSQL.END; 78 84 79 connection.execute(query);85 80 86 String short_label = null; 81 87 try { 82 results = connection.getResultSet(); 83 results.first(); 84 short_label = results.getString(GSSQL.SHORT_LABEL); 85 86 } catch (java.sql.SQLException e) { 88 results = statement.executeQuery(query); 89 if (results.first()) { 90 short_label = results.getString(GSSQL.SHORT_LABEL); 91 } else { 92 statement.close(); 93 return null; 94 } 95 statement.close(); 96 } catch (SQLException e) { 87 97 88 98 System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage()); 89 99 return null; 90 100 } 91 92 ///ystem.out.println("short label = "+short_label); 93 94 System.out.println("final doc_id = "+GS3OID.createOID(doc_id, short_label)); 101 95 102 return GS3OID.createOID(doc_id, short_label); 96 103 } 97 104 98 105 public String OID2MGNum(String oid) { 99 System.out.println("converting oid "+oid+" to mg num");100 106 String id = getDocumentMetadata(oid, "gsdl3.mgseqno"); 101 System.out.println("mg id = "+id);102 107 return id; 103 108 … … 117 122 " and "+ GSSQL.STRUCTURE_ID +GSSQL.EQUALS_QUOTE + "Section" + GSSQL.QUOTE + 118 123 GSSQL.END; 119 120 connection.execute(query); 121 ResultSet results = null; 122 try { 123 results = connection.getResultSet(); 124 if (results.next()) { 125 return true; 126 } 124 boolean is_hierarchical = false; 125 try { 126 Statement statement = connection.createStatement(); 127 ResultSet results = statement.executeQuery(query); 128 is_hierarchical = results.first(); 129 statement.close(); 127 130 } catch (java.sql.SQLException e) { 128 131 return false; 129 132 } 130 131 return false;133 134 return is_hierarchical; 132 135 } 133 136 … … 135 138 public String getClassifierMetadata(String oid, String full_meta_name) { 136 139 137 if (full_meta_name.equals("Title") || full_meta_name.equals("numleafdocs")) { 138 // get the description 139 String field_name=""; 140 if (full_meta_name.equals("Title")) { 141 field_name = GSSQL.DESCRIPTION; 142 } else { 143 field_name = GSSQL.NUM_LEAF_DOCUMENTS; 144 } 145 146 String query = "select "+ field_name+ 147 " from " + GSSQL.CLASSIFIER_TABLE + 148 " where " + GSSQL.CLASSIFIER_ID + GSSQL.EQUALS_QUOTE + oid + GSSQL.QUOTE + 149 GSSQL.END; 140 if (!full_meta_name.equals("Title") && !full_meta_name.equals("numleafdocs")) { 141 return null; 142 } 143 // get the description 144 String field_name=""; 145 if (full_meta_name.equals("Title")) { 146 field_name = GSSQL.DESCRIPTION; 147 } else { 148 field_name = GSSQL.NUM_LEAF_DOCUMENTS; 149 } 150 151 String query = "select "+ field_name+ 152 " from " + GSSQL.CLASSIFIER_TABLE + 153 " where " + GSSQL.CLASSIFIER_ID + GSSQL.EQUALS_QUOTE + oid + GSSQL.QUOTE + 154 GSSQL.END; 155 156 String value = null; 157 try { 158 Statement statement = connection.createStatement(); 159 ResultSet results = statement.executeQuery(query); 160 if (results.first()) { 161 value = results.getString(field_name); 162 } 163 statement.close(); 164 } catch (java.sql.SQLException e) { 150 165 151 connection.execute(query); 152 ResultSet results = null; 153 String value = null; 154 try { 155 results = connection.getResultSet(); 156 results.first(); 157 value = results.getString(field_name); 158 } catch (java.sql.SQLException e) { 159 160 System.err.println("SQLQuery.getClassifierMetadata() Error: "+e.getMessage()); 161 return null; 162 } 163 return value; 164 165 } else return null; 166 166 System.err.println("SQLQuery.getClassifierMetadata() Error: "+e.getMessage()); 167 return null; 168 } 169 return value; 170 167 171 } 168 172 … … 176 180 section_id = GS3OID.getSectionLabel(oid); 177 181 } 178 System.out.println("getDocChildren: oid = "+oid+", doc id = "+doc_id+", sec id ="+section_id);179 182 // int sep_index = oid.indexOf("."); 180 183 // if (sep_index != -1) { … … 190 193 GSSQL.END; 191 194 192 connection.execute(query);193 195 ResultSet results = null; 196 Statement statement = null; 194 197 String div_ref = null; 195 198 try { 196 results = connection.getResultSet(); 197 results.first(); 198 div_ref = results.getString(GSSQL.DIVISION_REF); 199 statement = connection.createStatement(); 200 results = statement.executeQuery(query); 201 if (results.first()) { 202 div_ref = results.getString(GSSQL.DIVISION_REF); 203 } else { 204 statement.close(); 205 return null; 206 } 199 207 } catch (java.sql.SQLException e) { 200 208 … … 210 218 " and "+GSSQL.PARENT_REF+GSSQL.EQUALS_QUOTE+div_ref+GSSQL.QUOTE+ 211 219 GSSQL.END; 212 connection.execute(query); 213 results = null; 214 try { 215 results = connection.getResultSet(); 220 try { 221 results = statement.executeQuery(query); 216 222 while (results.next()) { 217 223 String id = results.getString(GSSQL.SHORT_LABEL); 218 224 children.add(GS3OID.createOID(doc_id, id)); 219 225 } 226 statement.close(); 220 227 } catch (java.sql.SQLException e) { 221 228 … … 247 254 GSSQL.END; 248 255 249 connection.execute(query); 250 ResultSet results = null; 251 try { 252 results = connection.getResultSet(); 256 try { 257 Statement statement = connection.createStatement(); 258 ResultSet results = statement.executeQuery(query); 253 259 while (results.next()) { 254 260 String id = results.getString(GSSQL.CLASSIFIER_ID); 255 261 children.add(id); 256 262 } 257 } catch (java.sql.SQLException e) { 258 263 statement.close(); 264 } catch (java.sql.SQLException e) { 265 259 266 System.err.println("SQLQuery.getClassifierChildren Error: "+e.getMessage()); 260 267 return null; … … 264 271 265 272 public ArrayList getClassifierDocChildren(String oid) { 266 System.out.println("in getclassifierdocchildren");267 273 ArrayList children = new ArrayList(); 268 274 … … 273 279 " order by "+GSSQL.CLASS_DOCUMENT_TABLE+GSSQL.DOT+GSSQL.DOCUMENT_ORDER+ 274 280 GSSQL.END; 275 System.out.println("query="+query); 276 connection.execute(query); 277 ResultSet results = null; 278 try { 279 results = connection.getResultSet(); 281 try { 282 Statement statement = connection.createStatement(); 283 ResultSet results = statement.executeQuery(query); 280 284 while (results.next()) { 281 285 String id = results.getString(GSSQL.DOCUMENT_ID); … … 287 291 return null; 288 292 } 289 // now check for documents290 293 291 294 return children; … … 306 309 // } 307 310 308 System.out.println("get meta for "+oid+", doc id = "+doc_id+"sec id = "+section_id);309 311 310 312 // get the metadata block id … … 318 320 GSSQL.END; 319 321 320 connection.execute(query);322 Statement statement = null; 321 323 ResultSet results = null; 322 324 String meta_id = null; 323 325 try { 324 results = connection.getResultSet(); 325 results.first(); 326 meta_id = results.getString(GSSQL.METADATA_ID); 326 statement = connection.createStatement(); 327 results = statement.executeQuery(query); 328 if (results.first()) { 329 meta_id = results.getString(GSSQL.METADATA_ID); 330 } else { 331 statement.close(); 332 return null; 333 } 327 334 } catch (java.sql.SQLException e) { 328 335 … … 330 337 return null; 331 338 } 332 System.err.println("metadata block id = "+meta_id); 333 339 334 340 // now get the list of namespace refs for the right namespace 335 341 int sep_index = full_meta_name.indexOf('.'); … … 341 347 meta_name = full_meta_name.substring(sep_index+1); 342 348 } 343 System.out.println("orig meta = "+full_meta_name+", ns = "+meta_ns+", name="+meta_name);344 349 345 350 query = "select * "+ … … 351 356 " and "+GSSQL.NAMESPACE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+GSSQL.EQUALS+GSSQL.METADATA_VALUE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+ 352 357 GSSQL.END; 353 System.out.println("query="+query); 354 connection.execute(query); 358 355 359 String meta_value = null; 356 360 try { 357 results = connection.getResultSet(); 361 statement = connection.createStatement(); 362 results = statement.executeQuery(query); 358 363 while (results.next()) { 359 364 String m_name = results.getString(GSSQL.LABEL); … … 363 368 } 364 369 } 370 statement.close(); 365 371 } catch (java.sql.SQLException e) { 366 372
Note:
See TracChangeset
for help on using the changeset viewer.