Ignore:
Timestamp:
2005-05-16T11:02:50+12:00 (19 years ago)
Author:
kjdon
Message:

merged from branch ant-install-branch: merge 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java

    r8742 r9874  
    77import java.sql.ResultSet;
    88import java.sql.SQLException;
     9import java.sql.Statement;
    910
    1011import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
     
    273274    GS3SQLInsert insert;
    274275
     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   
    275285    // Get own full id
    276286    String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix;
     
    283293    select.setWhere(where);
    284294
    285     connection.execute(select.toString());
    286295
    287296    // update or insert the classifier as required
    288297    try {
    289       ResultSet results = connection.getResultSet();
    290       if (results != null && results.first()) {
     298      ResultSet results = statement.executeQuery(select.toString());
     299      if (results.first()) {
    291300    GS3SQLUpdate update = new GS3SQLUpdate("classifiers");
    292301    update.setWhere(where);
     
    313322
    314323    action = insert;
     324    classifyRef = -1;
    315325      }
    316326      action.addValue("ClassifyID", fullId);
     
    331341      action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE);
    332342
    333       connection.execute(action.toString());
    334       classifyRef = -1;
     343      statement.execute(action.toString());
    335344    }
    336345    catch (SQLException sqlEx) {
    337346      if (action == null) {
    338     System.err.println(sqlEx);
     347    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx);
    339348      }
    340349      else {
    341     System.err.println(sqlEx + " " + action.toString());
     350    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx + " " + action.toString());
    342351      }
    343352      return false;
     
    347356    // insert action above)...
    348357    if (classifyRef == -1) {
    349       connection.execute(select.toString());
    350      
    351358      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;
    355363    }
    356364   
    357365    classifyRef = results.getInt("ClassifyRef");
     366   
    358367      }
    359368      catch (SQLException sqlEx) {
    360     System.err.println(sqlEx);
     369    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx);
    361370    return false;
    362371      }
     
    368377      GS3SQLDelete delete = new GS3SQLDelete("classdocuments");
    369378      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   
    374387    // post the child nodes...
    375388    Iterator iterator = this.childNodes.iterator();
     
    379392      if (!childNode.writeSQL(connection)) {
    380393      System.out.println("Failed to write " );
    381     return false;
     394      return false;
    382395      }
    383396    }
     
    394407      insert.addValue("DocID", docId.toString());
    395408      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      }
    399415      order ++;
    400416    }
     417    // close the statment
     418    try {
     419    statement.close();
     420    } catch (SQLException e) {
     421    System.err.println("AbstractHierarchyNode.writeSQL(): "+e);
     422    }
     423
    401424    return true;
    402425  }
Note: See TracChangeset for help on using the changeset viewer.