- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java
r8742 r9874 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; -
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.