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/metadata/METSFileGroup.java

    r8742 r9874  
    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();
     373        ResultSet childSet = statement.executeQuery(select.toString());
    377374        if (childSet.first()) {
    378375        do {
     
    384381        while (childSet.next());
    385382        }
    386        
    387383        // now scan for file members
    388384        select = new GS3SQLSelect("files");
    389385        select.addField("*");
    390         whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef),
    391                         GS3SQLField.INTEGER_TYPE);
     386        whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), GS3SQLField.INTEGER_TYPE);
    392387        where = new GS3SQLWhere(whereItem);
    393388        select.setWhere(where);
    394         connection.execute(select.toString());
    395        
    396         ResultSet childFileSet = connection.getResultSet();
    397         if (childFileSet != null && childFileSet.first()) {
     389        ResultSet childFileSet = statement.executeQuery(select.toString());
     390        if (childFileSet.first()) {
    398391        do {
    399392            METSFile file = METSFile.readSQL(connection, childFileSet);
     
    404397        while (childFileSet.next());
    405398        }
    406        
     399        statement.close();
    407400        return group;
    408401    }
    409402    catch (SQLException sqlEx){
    410         System.out.println(sqlEx);
     403        System.err.println("METSFileGroup.readSQL(): "+sqlEx);
    411404        System.exit(1);
    412405    }
Note: See TracChangeset for help on using the changeset viewer.