Changeset 9874 for trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
r8742 r9874 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 }
Note:
See TracChangeset
for help on using the changeset viewer.