Changeset 9858


Ignore:
Timestamp:
2005-05-12T14:52:45+12:00 (19 years ago)
Author:
kjdon
Message:

OK, changed my mind about making SQLConnection kill off the previous statement.
To make it more transparent what is happening, you now have to create a Statement (connection.createStatement()), then use the Statement to execute the query. This means that the thing doing the query owns the Statement, and can kill it off when finished with it, and nothing else can kill it off unexpectedly. The previous way this was all implemented meant that there was a large memory leak, and some functionality actually relied on this. A newer version of the mysql connector/J has fixed the bug where the statement wasn't closed on garbage collection, but it still seems better to close it explicitly.
Hopefully I have got it all back to working as well as it was bfore, and haven't introduced any bugs :-)

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  
    216216      GS3SQLSelect select = new GS3SQLSelect("build");
    217217      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()) {
    222221    System.out.println("Reading all keys");
    223222    do {
     
    238237    } while (results.next());
    239238      }
     239      statement.close();
    240240    }
    241241    catch (SQLException ex)
     
    479479   
    480480    // 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   
    496502    // Do tail of build output
    497503    Date startDate = this.lastBuildDate.getTime();
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java

    r8742 r9858  
    99import java.sql.ResultSet;
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112
    1213import org.xml.sax.XMLReader;
     
    189190    select.setWhere(where);
    190191
    191     connection.execute(select.toString());
    192192
    193193    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()) {
    196197    GS3SQLUpdate update = new GS3SQLUpdate("classifiers");
    197198    update.setWhere(where);
     
    206207
    207208    action = insert;
     209    classifyRef = -1;
    208210      }
    209211      action.addValue("ClassifyID", label);
     
    213215      action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE);
    214216
    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()) {
    231226      return -1;
    232227    }
     
    234229    classifyRef = results.getInt("ClassifyRef");
    235230      }
    236       catch (SQLException sqlEx) {
    237     System.err.println(sqlEx);
     231     
     232      statement.close();
     233    }  catch (SQLException sqlEx) {
     234    System.err.println("AZListClassifier.writeSQLClassifyNode(): "+sqlEx);
    238235    return -1;
    239       }
    240     }
     236    }
     237 
    241238
    242239    return classifyRef;
     
    274271    }
    275272
     273    try {
     274    Statement statement = connection.createStatement();
     275   
    276276    List children;
    277277   
     
    292292        Iterator iterator = childDocs.iterator();
    293293    int childOrder = 1;
     294    //St
    294295    while (iterator.hasNext()) {
    295296      AZDocumentItem documentItem = (AZDocumentItem) iterator.next();
     
    301302      insert.addValue("DocOrder", Integer.toString(childOrder), GS3SQLField.INTEGER_TYPE);   
    302303
    303       connection.execute(insert.toString());
     304      statement.execute(insert.toString());
    304305
    305306      childOrder ++;
     
    310311    }
    311312
     313   
    312314    /*
    313315    else {
     
    318320      delete.setWhere(where);
    319321
    320       connection.execute(delete.toString());
     322      statement.execute(delete.toString());
    321323    }
    322324
     
    331333    }
    332334    */
     335    statement.close();
     336    } catch (SQLException e) {
     337    System.err.println("AZListClassifier.writeSQL(): "+e);
     338    return false;
     339    }
    333340
    334341    return true;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java

    r8742 r9858  
    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  }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java

    r9847 r9858  
    6565     
    6666    try {
    67       statement = this.connection.createStatement();
     67      Statement statement = this.connection.createStatement();
    6868
    6969      // create build history table
     
    236236    {
    237237      System.out.println(ex.toString());
    238       if (statement != null) {
    239       try {
    240           statement.close();
    241       } catch (Exception e){}
    242       statement = null;
    243       }
    244238      return false;
    245239    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java

    r9847 r9858  
    1010{
    1111    protected Connection connection;
    12     protected Statement  statement;
    1312    protected String database;
    1413   
     
    2423        this.connection.close();       
    2524        } catch (Exception e) {}
    26     }
    27     if (this.statement!=null) {
    28         try {
    29         this.statement.close();     
    30         } catch (Exception e) {}
    31     }
    32    
     25    }   
    3326    this.connection = null;   
    34     this.statement = null;
    35 
    3627    }
    3728   
     
    3930    finalize();
    4031    }
    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     }
    5732   
    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
    6734    {
    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();
    8936    }
    9037   
     
    10552    public boolean dropDatabase(String database) {
    10653    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();
    11057    }
    11158    catch (SQLException ex){
     
    12067    try {
    12168        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();
    12572    } catch (Exception e) {
    12673        System.err.println(e);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java

    r9849 r9858  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213import java.sql.Timestamp;
     
    190191    // Query for documents using the same file...
    191192    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 
    197193    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        }
    216216        }
    217       }
    218217    }
    219       }
     218    statement.close();
    220219    }
    221220    catch (java.sql.SQLException sqlEx) {
    222       System.err.println(sqlEx);
     221      System.err.println("AbstractDocument.getDuplicateID(): "+sqlEx);
    223222    }
    224223
     
    454453      // Use a factory method to create the correct subtype...
    455454      AbstractDocument document = DocumentFactory.createDocument(type, id);
    456 
    457455      // Append the document date information
    458456      document.indexDate    = sqlResult.getTimestamp("IndexedDate");
     
    460458      document.modifiedDate = sqlResult.getTimestamp("ModifiedDate");
    461459
    462       // Note that once we have used the connection for something else, our results are closed.
    463460      // Get the individual components of the document
    464461      METSFileSet fileSet = METSFileSet.readSQL(document, connection);
     
    474471    }
    475472    catch (SQLException sqlEx) {
    476       System.out.println("Failure to load document: " + sqlEx);
     473      System.err.println("AbstractDocument.readSQL(): Failure to load document: " + sqlEx);
    477474    }
    478475    return null;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java

    r8742 r9858  
    22
    33import java.sql.SQLException;
     4import java.sql.Statement;
    45import java.sql.ResultSet;
    56import java.net.URL;
     
    6162  {
    6263    String query = "SELECT * FROM document WHERE DocID=\""+id.toString()+"\";";
    63     connection.execute(query);
    64 
    6564    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;
    7074    }
    7175    catch (SQLException sqlEx) {
    72       System.err.println(sqlEx);
     76      System.err.println("AbstractDocument.readSQLDocument():"+sqlEx);
    7377    }
    7478    return null;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java

    r9850 r9858  
    1313
    1414import java.sql.SQLException;
     15import java.sql.Statement;
    1516import java.sql.ResultSet;
    1617
     
    6869    select.setWhere(where);
    6970
    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();
    8585    do {
    8686      int fileGroupRef = results.getInt("FileGroupRef");
     
    9090    while (results.next());
    9191    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   
    9795    results.first();
    9896    do {
     
    10098      reply.add(docId);
    10199    } 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   
    107106    return reply;
    108107  }
     
    173172  }
    174173
    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    }
    185185     
    186186      // get a list of group ids first and turn it into a query on filegroups
     
    207207      // structures...recreating new filegroup queries as necessary
    208208      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;
    214214    }
    215215   
     
    256256     
    257257      // 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;
    264263      }
    265264
     
    268267    reply.add(results.getString("DocID"));
    269268      } while (results.next());
    270 
     269     
     270      statement.close();
    271271      return reply;
    272272    }
    273273    catch (SQLException ex) {
    274       System.err.println(ex);
     274      System.err.println("DocumentList.findDocumentIdsUsingFileQuery()"+ ex);
    275275    }
    276276    return null;
     
    454454    select.addField("*");
    455455   
    456     ResultSet documents;
    457456    try {
    458     connection.execute(select.toString());
    459     documents = connection.getResultSet();
    460 
    461      
     457    Statement statement = connection.createStatement();
     458    ResultSet documents = statement.executeQuery(select.toString());
    462459    if (documents.first()) {
    463         // clone the connection cos we are still usign the old result set
    464         GS3SQLConnection cloned_connection = connection.cloneConnection();
    465        
    466460        do {
    467         DocumentInterface document = AbstractDocument.readSQL(cloned_connection, documents);
     461        DocumentInterface document = AbstractDocument.readSQL(connection, documents);
    468462        list.addDocument(document);
    469463        }
    470464        while (documents.next());
    471         cloned_connection.close();
    472         cloned_connection = null;
    473     }
     465    }
     466    statement.close();
    474467    }
    475468    catch (java.sql.SQLException ex) {
    476     System.out.println(ex);
    477     ex.printStackTrace();
     469    System.out.println("DocumentList.writeSQLDocuments(): "+ex);
    478470    return null;
    479471    }
     
    494486{
    495487  private boolean hasNext;
     488  private Statement statement;
    496489  private ResultSet resultSet;
    497490  private GS3SQLConnection connection;
     
    505498
    506499    try {
    507       connection.execute(select.toString());
    508       this.resultSet = connection.getResultSet();
     500    this.statement = connection.createStatement();
     501      this.resultSet = statement.executeQuery(select.toString());
    509502      this.hasNext = this.resultSet.first();
    510503    } catch (SQLException ex) {
     504      System.err.println("DocumentListIterator(): "+ex);
    511505      this.hasNext = false;
    512506    }
     
    527521
    528522      if (!this.hasNext) {
    529     this.resultSet.close(); // be a good citizen & close used result sets
     523      this.statement.close(); // be a good citizen & close used statement
    530524      }
    531525    } catch (SQLException ex) {
     526    System.err.println("DocumentList.iterator.next(): "+ex);
    532527      this.hasNext = false;
    533528    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java

    r8742 r9858  
    1919    update.addDate("IndexedDate", new java.sql.Timestamp(touchTime));
    2020    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    }
    2229    System.out.println(update.toString());
    2330    return true;
     
    3946    select.addField("*");
    4047    select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString())));
    41     connection.execute(select.toString());
    4248   
    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");
    4853      insert.addValue("DocID", document.getID().toString());
    4954      insert.addValue("DocType", document.getDocumentType());
     
    5358      insert.addDate("ModifiedDate", new java.sql.Timestamp(document.getModifiedDatestamp()));
    5459
    55       connection.execute(insert.toString());
     60      statement.execute(insert.toString());
    5661    }
    5762    else {
     
    6166      //      connection.execute(update.toString());
    6267    }
     68    statement.close();
    6369      }
    64     } catch (Exception ex) {
    65     System.out.println(ex);
     70    } catch (SQLException ex) {
     71    System.out.println("DocumentSQLWriter.writeDocument() Error:"+ex);
    6672    }
    6773    //    output.println(tag);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/HTMLDocument.java

    r8929 r9858  
    279279    public Document getDOMDocument()
    280280    {   
    281     if (this.domDocument == null) {
     281      if (this.domDocument == null) {
    282282      URL     url =(URL) this.fileSet.getFile(0).getLocation();
    283283      this.loadDocument(url);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java

    r9851 r9858  
    88
    99import java.sql.SQLException;
     10import java.sql.Statement;
    1011import java.sql.ResultSet;
    1112
     
    275276        } else {
    276277        // TODO: raise an error!
    277         System.out.println("Error: METSDescriiptive: unrecognised tag "+childName);
     278        System.out.println("Error: METSDescriptive: unrecognised tag "+childName);
    278279        }
    279280    }
     
    375376    select.setWhere(where);
    376377   
    377     connection.execute(select.toString());
    378    
    379378    try {
     379        Statement statement = connection.createStatement();
     380        ResultSet resultSet = statement.executeQuery(select.toString());
    380381        GS3SQLAction action;
    381382       
    382         ResultSet resultSet = connection.getResultSet();
    383        
    384         if (resultSet != null &&
    385         resultSet.first()) {
     383        if (resultSet.first()) {
    386384        // the node already exists - no need to do anything as such
    387385        GS3SQLUpdate update = new GS3SQLUpdate("metadata");
     
    390388        }
    391389        else { // Set result set to null, just in case first() didn't work above...
    392         resultSet = null;
    393        
    394390        // It is a new node and needs writing
    395391        action = new GS3SQLInsert("metadata");
     
    403399       
    404400        // execute the action as required
    405         connection.execute(action.toString());
     401        statement.execute(action.toString());
    406402       
    407403        // get the resultSet again
     
    409405        // 'MetadataRef'
    410406        // 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();
    420414    }
    421415    catch (SQLException sql){
    422         System.out.println(sql);
     416        System.err.println("METSDescriptive.writeSQL(): "+sql);
     417    }
     418    if (sqlId == -1) {
     419        return false;
    423420    }
    424421   
     
    470467        select.setWhere(where);
    471468       
    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()) {
    482474        do {
    483             METSNamespace namespace = METSNamespace.readSQL(cloned_connection, namespaceSet);
     475            METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet);
    484476            if (namespace != null) {
    485477            descriptive.addNamespace(namespace);
    486478            }
    487479            else {
    488             System.out.println("Null namespace output");
     480            System.err.println("Null namespace output");
    489481            }
    490482        }
    491483        while (namespaceSet.next());
    492484        }
    493         cloned_connection.close();
    494         cloned_connection = null;
     485        statement.close();
    495486        return descriptive;
    496487    }
    497488    catch (SQLException sqlEx){
    498         System.out.println(sqlEx);
    499         sqlEx.printStackTrace();
     489        System.err.println("METSDescriptive.readSQL(): "+sqlEx);
    500490        System.exit(1);
    501491    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java

    r9851 r9858  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213
     
    236237    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    237238    select.setWhere(new GS3SQLWhere(whereItem));
    238     connection.execute(select.toString());
    239    
    240     // clone the connection cos we are still using the old result set
    241     GS3SQLConnection cloned_connection = connection.cloneConnection();
    242239
    243240    // start going through the matching metadata blocks
    244241    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();
    258256    }
    259257    catch (SQLException sqlEx) {
    260         System.out.println(sqlEx);
    261         sqlEx.printStackTrace();
     258        System.err.println("METSDescriptiveSet.readSQL(): "+sqlEx);
    262259        System.exit(1);
    263260    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java

    r9851 r9858  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    475476    select.setWhere(where);
    476477   
    477     connection.execute(select.toString());
     478    Statement statement = null;
     479    ResultSet resultSet = null;
    478480   
    479481    // Do the actual writing
    480482    GS3SQLAction action;
    481483   
    482     ResultSet resultSet = connection.getResultSet();
    483484    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()) {
    490488       
    491489        GS3SQLInsert insert = new GS3SQLInsert("divisions");
     
    517515    action.addValue("UserLabel", this.userLabel);
    518516   
    519     if (!connection.execute(action.toString())){
     517    try {
     518        statement.execute(action.toString());
     519    } catch (SQLException e) {
     520        System.err.println("METSDivision.writeSQL(): "+e);
    520521        return false;
    521522    }
    522523   
    523524    // if doing a fresh item, get the new structure reference...
    524     if (resultSet == null){
     525    if (sqlRef == -1){
    525526        // get the new structure reference
    526         connection.execute(select.toString());
    527        
    528         // get the sql reference for the division
    529527        try {
    530528        // 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");
    534532        }
    535         resultSet.first();
    536         sqlRef = resultSet.getInt("DivisionRef");
    537         resultSet.close();
    538         resultSet = null;
    539533        }
    540534        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);
    542536        return false;
    543537        }
    544538    }
    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     }
    554539   
    555540    // 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    }
    596587    // write out any children in turn
    597588    Iterator groups = this.children.values().iterator();
     
    635626        select.setWhere(where);
    636627
    637         connection.execute(select.toString());
     628        Statement statement = connection.createStatement();
     629        ResultSet childSet = statement.executeQuery(select.toString());
    638630     
    639631        // circulate through to obtain further children
    640         ResultSet childSet = connection.getResultSet();
    641         // clone the connection cos we are still usign the old result set
    642         GS3SQLConnection cloned_connection = connection.cloneConnection();
    643 
    644632        if (childSet.first())
    645633        {
    646634            do {
    647             METSDivision childDivision = METSDivision.readSQL(cloned_connection, childSet);
     635            METSDivision childDivision = METSDivision.readSQL(connection, childSet);
    648636            division.addDivision(childDivision);
    649637            }
    650638            while (childSet.next());
    651639        }
    652 
    653         cloned_connection.close();
    654         cloned_connection = null;
    655640        select = new GS3SQLSelect("divisionfilerefs");
    656641        select.addField("*");
     
    659644        select.setWhere(where);
    660645
    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()){
    665649        do {
    666650            String reference = fileSet.getString("FileID");
     
    669653        while (fileSet.next()); 
    670654        }
    671 
     655       
    672656        select = new GS3SQLSelect("divisionmetarefs");
    673657        select.addField("*");
     
    676660        select.setWhere(where);
    677661
    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()){
    682665        do {
    683666            String reference = metaSet.getString("MetaID");
     
    687670        }
    688671       
    689         connection.closeStatement();
     672        statement.close();
    690673        return division;
    691674    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java

    r9851 r9858  
    1111import java.sql.ResultSet;
    1212import java.sql.SQLException;
     13import java.sql.Statement;
    1314
    1415import org.w3c.dom.Document;
     
    201202    where.add(whereItem);
    202203    select.setWhere(where);
    203     connection.execute(select.toString());
     204
     205    Statement statement = null;
    204206   
    205207    // if not, then make an insert action
    206208    try {
    207         ResultSet results = connection.getResultSet();
    208         if (results == null ||
    209         !results.first()){
     209        statement = connection.createStatement();
     210        ResultSet results = statement.executeQuery(select.toString());
     211        if (!results.first()){
    210212        GS3SQLInsert insert = new GS3SQLInsert("files");
    211213       
     
    223225    }
    224226    catch (SQLException ex){
    225         System.err.println(ex);
     227        System.err.println("METSFile.writeSQL(): "+ex);
    226228        return false;
    227229    }
     
    230232    action.addValue("MIMEType", this.MIMEType);
    231233   
    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;
    235243    }
    236244   
     
    250258    }
    251259    catch (SQLException ex){
    252         System.out.println(ex);
     260        System.out.println("METSFile.readSQL(): "+ex);
    253261    }
    254262    catch (java.net.MalformedURLException urlEx){
    255         System.out.println(urlEx);
     263        System.out.println("METSFile.readSQL(): "+urlEx);
    256264    }
    257265    return null;
     
    311319    } catch (java.net.MalformedURLException ex) {
    312320        // TODO: raise error
    313         System.err.println(ex);
     321        System.err.println("METSFile.parse_flocateXML(): "+ex);
    314322    }
    315323    return thisFilePos;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java

    r9851 r9858  
    88
    99import java.sql.SQLException;
     10import java.sql.Statement;
    1011import java.sql.ResultSet;
    1112
     
    271272    {
    272273    int sqlId = -1;
    273    
    274274    // check if this node is in the database already
    275275    GS3SQLSelect select = new GS3SQLSelect("filegroups");
     
    281281    select.setWhere(where);
    282282   
    283     connection.execute(select.toString());
    284    
    285     ResultSet selectResult = connection.getResultSet();
     283    ResultSet results = null;
     284    Statement statement = null;
    286285   
    287286    try {
    288         if (selectResult == null ||
    289         !selectResult.first()) {
     287        statement = connection.createStatement();
     288        results = statement.executeQuery(select.toString());
     289        if (!results.first()) {
    290290        GS3SQLInsert insert = new GS3SQLInsert("filegroups");
    291291       
     
    295295        insert.addValue("ParentType", parentIsSection ? SECTION_PARENT : GROUP_PARENT);
    296296       
    297         if (!connection.execute(insert.toString())) {
    298             return false;
    299         }
     297        statement.execute(insert.toString());
    300298        }
    301299        else {
     
    304302    }
    305303    catch (SQLException ex){
    306         System.err.println(ex);
     304        System.err.println("METSFileGroup.writeSQL(): "+ex);
    307305        return false;
    308306    }
    309307   
    310308    // get the filegroup reference now
    311     connection.execute(select.toString());
    312    
    313309    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();
    316315        return false;
    317316        }
    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);
    323320        return false;
    324321    }
    325    
    326322    // iterate over the child groups
    327323    Iterator childIter = childGroups.iterator();
     
    330326       
    331327        if (!fileGroup.writeSQL(document, Integer.toString(sqlId), false, connection)){
     328        System.err.println("METSFileGroup.writeSQL(): Couldn't write FileGroup");
    332329        return false;
    333330        }
     
    337334    childIter = children.iterator();
    338335    while (childIter.hasNext()){
    339         METSFile file = (METSFile) childIter.next();
    340        
     336        METSFile file = (METSFile) childIter.next();       
    341337        if (!file.writeSQL(sqlId, connection)){
     338        System.err.println("METSFileGroup.writeSQL(): Couldn't write File");
    342339        return false;
    343340        }
     
    371368        select.setWhere(where);
    372369       
    373         connection.execute(select.toString());
     370        Statement statement = connection.createStatement();
    374371       
    375372        // 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());
    379374        if (childSet.first()) {
    380375        do {
    381             METSFileGroup fileGroup = METSFileGroup.readSQL(document, cloned_connection, childSet);
     376            METSFileGroup fileGroup = METSFileGroup.readSQL(document, connection, childSet);
    382377            if (fileGroup != null) {
    383378            group.addGroup(fileGroup);
     
    386381        while (childSet.next());
    387382        }
    388        
    389383        // now scan for file members
    390384        select = new GS3SQLSelect("files");
    391385        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);
    394387        where = new GS3SQLWhere(whereItem);
    395388        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()) {
    400391        do {
    401             METSFile file = METSFile.readSQL(cloned_connection, childFileSet);
     392            METSFile file = METSFile.readSQL(connection, childFileSet);
    402393            if (file != null) {
    403394            group.addFile(file);
     
    406397        while (childFileSet.next());
    407398        }
    408         cloned_connection.close();
    409         cloned_connection = null;
     399        statement.close();
    410400        return group;
    411401    }
    412402    catch (SQLException sqlEx){
    413         System.out.println(sqlEx);
     403        System.err.println("METSFileGroup.readSQL(): "+sqlEx);
    414404        System.exit(1);
    415405    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java

    r9851 r9858  
    1616
    1717import java.sql.SQLException;
     18import java.sql.Statement;
    1819import java.sql.ResultSet;
    1920
     
    232233        insert.addValue("FileSecID", "test"); // TODO: remove magic string
    233234       
    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);
    235241        return false;
    236242        }
     
    246252       
    247253        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();
    255261        }
    256262        catch (SQLException ex){
    257         System.out.println(ex);
     263        System.out.println("METSFileSet.writeSQL(): "+ex);
    258264        return false;
    259265        }
    260266    }
    261267   
     268    if (this.reference == null) {
     269        return false;
     270    }
    262271    // write out the children
    263272    while (groups.hasNext()){
     
    281290    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    282291    select.setWhere(new GS3SQLWhere(whereItem));
    283     connection.execute(select.toString());
     292
     293    Statement statement = null;
    284294   
    285295    // Get the identifier for this file set, etc.
    286     ResultSet sections = connection.getResultSet();
    287     int fileSetRef;
     296    int fileSetRef = -1;
    288297    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       
    292308    }
    293309    catch (SQLException ex){
    294         System.out.println(ex);
     310        System.err.println("METSFileSet.readSQL() "+ex);
    295311        return null;
    296312    }
    297    
    298313    // Get child file groups
    299314    select = new GS3SQLSelect("filegroups");
     
    307322    where.add(whereItem);
    308323    select.setWhere(where);
    309     connection.execute(select.toString());
    310    
    311324    // start going through the matching file groups
    312     // clone the connection cos we are still usign the old result set
    313     GS3SQLConnection cloned_connection = connection.cloneConnection();
    314325    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();
    326336    }
    327337    catch (SQLException sqlEx) {
    328         System.out.println(sqlEx);
    329         sqlEx.printStackTrace();
     338        System.out.println("METSFileSet.readSQL(): "+sqlEx);
    330339        System.exit(1);
    331340    }
    332    
    333341    return set;
    334342    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java

    r8742 r9858  
    66import java.util.Iterator;
    77import java.sql.SQLException;
     8import java.sql.Statement;
    89import java.sql.ResultSet;
    910
     
    150151
    151152    // 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    }
    154161    // then get the namespace reference number if needsbe...
    155162    if (this.id == null) {
     
    161168        where.add(where);
    162169        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();
    168175        }
    169176        catch (SQLException sqlex){
    170177        this.id = null;
    171         System.err.println(sqlex);
     178        System.err.println("METSNamespace.writeSQL(): "+sqlex);
    172179        return false;
    173180        }
     
    201208        select.setWhere(where);
    202209
    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()) {
    207213        do {
    208214            String label = valuesSet.getString("Label");
     
    213219        while (valuesSet.next());
    214220        }
    215 
     221        statement.close();
    216222        return namespace;
    217223    }
    218224    catch (java.net.MalformedURLException urlEx){
    219         System.out.println(urlEx);
     225        System.err.println("METSNamespace.readSQL(): "+urlEx);
    220226    }
    221227    catch (SQLException sqlEx){
    222         System.out.println(sqlEx);
     228        System.err.println("METSNamespace.readSQL(): "+sqlEx);
    223229    }   
    224230    return null;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java

    r9851 r9858  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    180181    {
    181182    int sqlRef = -1;
    182     ResultSet results;
    183 
     183    ResultSet results = null;
     184    Statement statement = null;
     185   
    184186    // Prepare query to see if this structure has already been written
    185187    GS3SQLSelect select = new GS3SQLSelect("structure");
     
    190192    where.add(item);
    191193    select.setWhere(where);
    192 
     194   
    193195    // attempt to execute the query & get the current structure's reference
    194196    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()){
    199200        sqlRef = results.getInt("structureRef");
    200201        }
    201         else {
    202         results = null;
    203         }
    204        
    205         if (results != null) {
    206         results.close();
    207         }
    208202    }
    209203    catch (SQLException sqlEx) {
    210         System.err.print(sqlEx);
     204        System.err.print("METSStructure.writeSQL(): "+sqlEx);
    211205        return false;
    212206    }
    213207   
    214208    // insert a new structure if it wasn't there previously
    215     if (results == null) {
     209    if (sqlRef == -1) {
    216210        GS3SQLInsert insert = new GS3SQLInsert("structure");
    217211        insert.addValue("DocID", document.getID().toString());
     
    220214        insert.addValue("Label", this.label);
    221215       
    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);
    223226        return false;
    224227        }
    225228       
    226         // get the new structure reference by re-running the original select object
    227         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         }
    238229    }
    239230    else {
     
    244235        update.addValue("Label", this.label);
    245236       
    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    }
    249251    // write out the child groups (Divisions) now...   
    250252    Iterator groups = this.children.values().iterator();
     
    296298        select.setWhere(where);
    297299
    298         connection.execute(select.toString());
     300        Statement statement = connection.createStatement();
     301        ResultSet divisionSet = statement.executeQuery(select.toString());
    299302
    300303        // 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()) {
    305305        do {
    306             METSDivision division = METSDivision.readSQL(cloned_connection, divisionSet);
     306            METSDivision division = METSDivision.readSQL(connection, divisionSet);
    307307            if (division != null) {
    308308            structure.addDivision(division);
     
    311311        while (divisionSet.next());
    312312        }
    313         cloned_connection.close();
    314         cloned_connection = null;
     313        statement.close();
    315314        return structure;
    316315    }
    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());
    320318        System.exit(1);
    321         }
     319    }
    322320    return null;
    323321    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java

    r9851 r9858  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    157158    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    158159    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   
    163161    // start going through the matching metadata blocks
    164162    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();
    175174    }
    176175    catch (SQLException sqlEx) {
    177         System.out.println(sqlEx);
    178         sqlEx.printStackTrace();
     176        System.err.println("METSStructureSet.readSQL(): "+sqlEx);
    179177        System.exit(1);
    180178    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/SimpleNamespace.java

    r8742 r9858  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213
     
    281282    }
    282283   
     284    Statement statement = null;
     285    ResultSet results = null;
    283286    try {
     287        statement = connection.createStatement();
    284288        if (this.id == null) {
    285289        GS3SQLSelect select = new GS3SQLSelect("namespaces");
    286290        select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("MetadataRef", "=", Integer.toString(parentId), GS3SQLField.INTEGER_TYPE)));
    287291        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        }
    293299        }
    294300        else {
     
    300306        GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("NamespaceRef", "=", sqlId, GS3SQLField.INTEGER_TYPE));
    301307        delete.setWhere(where);
    302         connection.execute(delete.toString());
     308        statement.execute(delete.toString());
    303309       
    304310        // write out the metadata for this namespace
     
    316322            insert.addValue("Label", thisKey);
    317323            insert.addValue("Value", value);
    318             connection.execute(insert.toString());
    319         }
    320         }
     324            statement.execute(insert.toString());
     325        }
     326        }
     327        statement.close();
    321328    }
    322329    catch (SQLException sql) {
    323         System.out.println(sql);
     330        System.out.println("SimpleNamespace.writeSQL(): "+sql);
    324331    }
    325332    return true;
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java

    r9848 r9858  
    2727    String lastBuild = dateToSqlString(collManager.getBuildDate());
    2828    System.out.println("last build was " + lastBuild);
    29     Statement statement = collManager.getDatabase().createStatement();
    3029        try {
     30        Statement statement = collManager.getDatabase().createStatement();
    3131            // detect all new documents. A document is new if and only if
    3232            // AccessionDate >= CollectionLastRebuiltDate
     
    130130    private String getDocumentTitle(String documentID, GS3SQLConnection database) {
    131131        System.out.println("getting title for document " + documentID + " from database");
    132         Statement statement = database.createStatement();
    133132
    134         ResultSet results;
    135133        try {
     134        Statement statement = database.createStatement();
    136135            String sqlString = "SELECT mdvalues.value " +
    137136        "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " +
     
    144143        "                                 AND d.parenttype = 'Structure' " +
    145144        "                                 AND m.docID = s.docid;";
    146             results = statement.executeQuery(sqlString);
    147             if (results.next()) {
     145            ResultSet results = statement.executeQuery(sqlString);
     146            if (results.first()) {
    148147                String title = results.getString("value");
    149148                System.out.println("title is " + title);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/util/SQLQuery.java

    r9822 r9858  
    66import java.sql.ResultSet;
    77import java.sql.SQLException;
     8import java.sql.Statement;
    89
    910import java.util.ArrayList;
     
    1718
    1819    public boolean setDatabase(String db_name) {
    19     try {
    20         connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);
    21        
     20    connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);
     21    try {
     22
    2223        // test the connection
    2324        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();
    2928        return true;
    3029    } 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;
    3434    }
    3535
    3636    public void closeConnection() {
    37     connection=null;
     37    if (connection != null) {
     38        connection.close();
     39        connection=null;
     40    }
    3841    }
    3942
     
    5255        GSSQL.END;
    5356   
    54     connection.execute(query);
     57    Statement statement = null;
    5558    ResultSet results = null;
    5659    String doc_id = null;
    5760    String meta_id = null;
    5861    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    }
    6975
    7076    // now get division label
     
    7783        GSSQL.END;
    7884
    79     connection.execute(query);
     85   
    8086    String short_label = null;
    8187    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) {
    8797
    8898        System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage());
    8999        return null;
    90100    }
    91 
    92     ///ystem.out.println("short label = "+short_label);
    93 
    94     System.out.println("final doc_id = "+GS3OID.createOID(doc_id, short_label));
     101   
    95102    return GS3OID.createOID(doc_id, short_label);
    96103    }
    97104
    98105    public String OID2MGNum(String oid) {
    99     System.out.println("converting oid "+oid+" to mg num");
    100106    String id = getDocumentMetadata(oid, "gsdl3.mgseqno");
    101     System.out.println("mg id = "+id);
    102107    return id;
    103108
     
    117122        " and "+ GSSQL.STRUCTURE_ID +GSSQL.EQUALS_QUOTE + "Section" + GSSQL.QUOTE +
    118123        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();
    127130    } catch (java.sql.SQLException e) {
    128131        return false;
    129132    }
    130 
    131     return false;
     133   
     134    return is_hierarchical;
    132135    }
    133136   
     
    135138    public String getClassifierMetadata(String oid, String full_meta_name) {
    136139
    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) {
    150165       
    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   
    167171    }
    168172   
     
    176180        section_id = GS3OID.getSectionLabel(oid);
    177181    }
    178     System.out.println("getDocChildren: oid = "+oid+", doc id = "+doc_id+", sec id ="+section_id);
    179182//      int sep_index = oid.indexOf(".");
    180183//      if (sep_index != -1) {
     
    190193        GSSQL.END;
    191194
    192     connection.execute(query);
    193195    ResultSet results = null;
     196    Statement statement = null;
    194197    String div_ref = null;
    195198    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        }
    199207    } catch (java.sql.SQLException e) {
    200208       
     
    210218        " and "+GSSQL.PARENT_REF+GSSQL.EQUALS_QUOTE+div_ref+GSSQL.QUOTE+
    211219        GSSQL.END;
    212     connection.execute(query);
    213     results = null;
    214     try {
    215         results = connection.getResultSet();
     220    try {
     221        results = statement.executeQuery(query);
    216222        while (results.next()) {
    217223        String id = results.getString(GSSQL.SHORT_LABEL);
    218224        children.add(GS3OID.createOID(doc_id, id));
    219225        }
     226        statement.close();
    220227    } catch (java.sql.SQLException e) {
    221228       
     
    247254        GSSQL.END;
    248255   
    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);
    253259        while (results.next()) {
    254260        String id = results.getString(GSSQL.CLASSIFIER_ID);
    255261        children.add(id);
    256262        }
    257     } catch (java.sql.SQLException e) {
    258        
     263        statement.close();
     264    } catch (java.sql.SQLException e) {
     265       
    259266        System.err.println("SQLQuery.getClassifierChildren Error: "+e.getMessage());
    260267        return null;
     
    264271
    265272    public ArrayList getClassifierDocChildren(String oid) {
    266     System.out.println("in getclassifierdocchildren");
    267273    ArrayList children = new ArrayList();
    268274
     
    273279        " order by "+GSSQL.CLASS_DOCUMENT_TABLE+GSSQL.DOT+GSSQL.DOCUMENT_ORDER+
    274280        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);
    280284        while (results.next()) {
    281285        String id = results.getString(GSSQL.DOCUMENT_ID);
     
    287291        return null;
    288292    }
    289     // now check for documents
    290293   
    291294    return children;
     
    306309//      }
    307310
    308     System.out.println("get meta for "+oid+", doc id = "+doc_id+"sec id = "+section_id);
    309311
    310312    // get the metadata block id
     
    318320        GSSQL.END;
    319321   
    320     connection.execute(query);
     322    Statement statement = null;
    321323    ResultSet results = null;
    322324    String meta_id = null;
    323325    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        }
    327334    } catch (java.sql.SQLException e) {
    328335
     
    330337        return null;
    331338    }
    332     System.err.println("metadata block id = "+meta_id);
    333 
     339   
    334340    // now get the list of namespace refs for the right namespace
    335341    int sep_index = full_meta_name.indexOf('.');
     
    341347        meta_name = full_meta_name.substring(sep_index+1);
    342348    }
    343     System.out.println("orig meta = "+full_meta_name+", ns = "+meta_ns+", name="+meta_name);
    344349
    345350    query = "select * "+
     
    351356        " and "+GSSQL.NAMESPACE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+GSSQL.EQUALS+GSSQL.METADATA_VALUE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+
    352357        GSSQL.END;
    353     System.out.println("query="+query);
    354     connection.execute(query);
     358   
    355359    String meta_value = null;
    356360    try {
    357         results = connection.getResultSet();
     361        statement = connection.createStatement();
     362        results = statement.executeQuery(query);
    358363        while (results.next()) {
    359364        String m_name = results.getString(GSSQL.LABEL);
     
    363368        }
    364369        }
     370        statement.close();
    365371    } catch (java.sql.SQLException e) {
    366372
Note: See TracChangeset for help on using the changeset viewer.