Changeset 9851


Ignore:
Timestamp:
2005-05-10T15:54:21+12:00 (19 years ago)
Author:
kjdon
Message:

some changes due to SQLConnection now closing the previous statement before executing a new one - this was a memory leak. but it means that if you want to iterate through an sql resultset and do other sql processing, you must use a different connection for the other sql requests

Location:
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java

    r8742 r9851  
    389389        action = update;
    390390        }
    391         else
    392         { // Set result set to null, just in case next() didn't work above...
    393             resultSet = null;
    394            
    395             // It is a new node and needs writing
    396             action = new GS3SQLInsert("metadata");
    397            
    398             action.addValue("DocID", document.getID().toString());
    399             action.addValue("MetaID", this.ID);
    400         }
     391        else { // Set result set to null, just in case first() didn't work above...
     392        resultSet = null;
     393       
     394        // It is a new node and needs writing
     395        action = new GS3SQLInsert("metadata");
     396       
     397        action.addValue("DocID", document.getID().toString());
     398        action.addValue("MetaID", this.ID);
     399        }
    401400       
    402401        // always set the group identifier
     
    406405        connection.execute(action.toString());
    407406       
    408         // create a new resultset if necessary
    409         if (resultSet == null) {
    410         // now execute the select statement again to get the new identifier
    411         // 'MetadataRef'
    412         // System.out.println(select.toString());
    413         connection.execute(select.toString());
    414        
    415         resultSet = connection.getResultSet();
    416         resultSet.first();
    417         }
     407        // get the resultSet again
     408        // now execute the select statement again to get the new identifier
     409        // 'MetadataRef'
     410        // System.out.println(select.toString());
     411        connection.execute(select.toString());
     412       
     413        resultSet = connection.getResultSet();
     414        resultSet.first();
     415       
    418416       
    419417        // get the reference for this item...
    420418        sqlId = resultSet.getInt("MetadataRef");
     419        connection.closeStatement();
    421420    }
    422421    catch (SQLException sql){
     
    476475        // as it will
    477476        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
    478481        if (namespaceSet != null && namespaceSet.first()) {
    479482        do {
    480             METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet);
     483            METSNamespace namespace = METSNamespace.readSQL(cloned_connection, namespaceSet);
    481484            if (namespace != null) {
    482485            descriptive.addNamespace(namespace);
     
    488491        while (namespaceSet.next());
    489492        }
    490        
     493        cloned_connection.close();
     494        cloned_connection = null;
    491495        return descriptive;
    492496    }
    493497    catch (SQLException sqlEx){
    494498        System.out.println(sqlEx);
     499        sqlEx.printStackTrace();
    495500        System.exit(1);
    496501    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java

    r8742 r9851  
    238238    connection.execute(select.toString());
    239239   
     240    // clone the connection cos we are still using the old result set
     241    GS3SQLConnection cloned_connection = connection.cloneConnection();
     242
    240243    // start going through the matching metadata blocks
    241244    try {
     
    243246        resultSet.first();
    244247        do {
    245         METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet);
     248        METSDescriptive descriptive = METSDescriptive.readSQL(document, cloned_connection, resultSet);
    246249        if (descriptive != null) {
    247250            set.addDescriptive(descriptive);
     
    251254        }
    252255        } while (resultSet.next());
     256       
     257        connection.closeStatement();
    253258    }
    254259    catch (SQLException sqlEx) {
    255260        System.out.println(sqlEx);
     261        sqlEx.printStackTrace();
    256262        System.exit(1);
    257263    }
    258264   
     265   
    259266    return set;
    260267    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java

    r8742 r9851  
    484484        if (resultSet == null ||
    485485        !resultSet.first()) {
    486         resultSet = null;
     486        if (resultSet != null) {
     487            resultSet.close();
     488            resultSet = null;
     489        }
    487490       
    488491        GS3SQLInsert insert = new GS3SQLInsert("divisions");
     
    499502        GS3SQLUpdate update = new GS3SQLUpdate("divisions");
    500503        GS3SQLWhere  updateWhere =
    501             new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef),
    502                             GS3SQLField.INTEGER_TYPE));
     504            new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE));
    503505        update.setWhere(updateWhere);
    504506        action = update;
     
    637639        // circulate through to obtain further children
    638640        ResultSet childSet = connection.getResultSet();
     641        // clone the connection cos we are still usign the old result set
     642        GS3SQLConnection cloned_connection = connection.cloneConnection();
     643
    639644        if (childSet.first())
    640645        {
    641646            do {
    642             METSDivision childDivision = METSDivision.readSQL(connection, childSet);
     647            METSDivision childDivision = METSDivision.readSQL(cloned_connection, childSet);
    643648            division.addDivision(childDivision);
    644649            }
     
    646651        }
    647652
     653        cloned_connection.close();
     654        cloned_connection = null;
    648655        select = new GS3SQLSelect("divisionfilerefs");
    649656        select.addField("*");
     
    680687        }
    681688       
     689        connection.closeStatement();
    682690        return division;
    683691    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java

    r8742 r9851  
    230230    action.addValue("MIMEType", this.MIMEType);
    231231   
    232     return connection.execute(action.toString());
     232    boolean return_val = connection.execute(action.toString());
     233    connection.closeStatement();
     234    return return_val;
    233235    }
    234236   
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java

    r8742 r9851  
    375375        // parse through the child groups
    376376        ResultSet childSet = connection.getResultSet();
     377        // clone the connection cos we are still usign the old result set
     378        GS3SQLConnection cloned_connection = connection.cloneConnection();
    377379        if (childSet.first()) {
    378380        do {
    379             METSFileGroup fileGroup = METSFileGroup.readSQL(document, connection, childSet);
     381            METSFileGroup fileGroup = METSFileGroup.readSQL(document, cloned_connection, childSet);
    380382            if (fileGroup != null) {
    381383            group.addGroup(fileGroup);
     
    397399        if (childFileSet != null && childFileSet.first()) {
    398400        do {
    399             METSFile file = METSFile.readSQL(connection, childFileSet);
     401            METSFile file = METSFile.readSQL(cloned_connection, childFileSet);
    400402            if (file != null) {
    401403            group.addFile(file);
     
    404406        while (childFileSet.next());
    405407        }
    406        
     408        cloned_connection.close();
     409        cloned_connection = null;
    407410        return group;
    408411    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java

    r8742 r9851  
    310310   
    311311    // 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();
    312314    try {
    313315        ResultSet resultSet = connection.getResultSet();
    314316        resultSet.first();
    315317        do {
    316         METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet);
     318        METSFileGroup filegroup = METSFileGroup.readSQL(document, cloned_connection, resultSet);
    317319        if (filegroup != null) {
    318320            set.addGroup(filegroup);
    319321        }
    320322        } while (resultSet.next());
     323
     324        cloned_connection.close();
     325        cloned_connection = null;
    321326    }
    322327    catch (SQLException sqlEx) {
    323328        System.out.println(sqlEx);
     329        sqlEx.printStackTrace();
    324330        System.exit(1);
    325331    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java

    r8742 r9851  
    300300        // parse through the divisions
    301301        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();
    302304        if (divisionSet != null && divisionSet.first()) {
    303305        do {
    304             METSDivision division = METSDivision.readSQL(connection, divisionSet);
     306            METSDivision division = METSDivision.readSQL(cloned_connection, divisionSet);
    305307            if (division != null) {
    306308            structure.addDivision(division);
     
    309311        while (divisionSet.next());
    310312        }
    311 
     313        cloned_connection.close();
     314        cloned_connection = null;
    312315        return structure;
    313316    }
    314317    catch (SQLException sqlEx)
    315318        { System.out.println(sqlEx + " " + select.toString());
     319        sqlEx.printStackTrace();
    316320        System.exit(1);
    317321        }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java

    r8742 r9851  
    158158    select.setWhere(new GS3SQLWhere(whereItem));
    159159    connection.execute(select.toString());
     160    // clone the connection cos we are still usign the old result set
     161    GS3SQLConnection cloned_connection = connection.cloneConnection();
    160162
    161163    // start going through the matching metadata blocks
     
    164166        resultSet.first();
    165167        do {
    166         METSStructure structure = METSStructure.readSQL(document, connection, resultSet);
     168        METSStructure structure = METSStructure.readSQL(document, cloned_connection, resultSet);
    167169        if (structure != null) {
    168170            set.addStructure(structure);
    169171        }
    170172        } while (resultSet.next());
     173        cloned_connection.close();
     174        cloned_connection = null;
    171175    }
    172176    catch (SQLException sqlEx) {
    173177        System.out.println(sqlEx);
     178        sqlEx.printStackTrace();
    174179        System.exit(1);
    175180    }
Note: See TracChangeset for help on using the changeset viewer.