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

    r8742 r9874  
    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
    312325    try {
    313         ResultSet resultSet = connection.getResultSet();
    314         resultSet.first();
    315         do {
    316         METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet);
    317         if (filegroup != null) {
    318             set.addGroup(filegroup);
    319         }
    320         } while (resultSet.next());
     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();
    321336    }
    322337    catch (SQLException sqlEx) {
    323         System.out.println(sqlEx);
     338        System.out.println("METSFileSet.readSQL(): "+sqlEx);
    324339        System.exit(1);
    325340    }
    326    
    327341    return set;
    328342    }
Note: See TracChangeset for help on using the changeset viewer.