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/METSStructure.java

    r8742 r9874  
    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         if (divisionSet != null && divisionSet.first()) {
     304        if (divisionSet.first()) {
    303305        do {
    304306            METSDivision division = METSDivision.readSQL(connection, divisionSet);
     
    309311        while (divisionSet.next());
    310312        }
    311 
     313        statement.close();
    312314        return structure;
    313315    }
    314     catch (SQLException sqlEx)
    315         { System.out.println(sqlEx + " " + select.toString());
     316    catch (SQLException sqlEx) {
     317        System.err.println("METSStructure.readSQL(): "+ sqlEx + " " + select.toString());
    316318        System.exit(1);
    317         }
     319    }
    318320    return null;
    319321    }
Note: See TracChangeset for help on using the changeset viewer.