Changeset 542 for trunk

Show
Ignore:
Timestamp:
08/26/11 15:49:49 (9 months ago)
Author:
thomas
Message:

added XrefIterator? interface and implemented for IDMapperRdb

Location:
trunk
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/IDMapperRdb.java

    r318 r542  
    1919import java.io.File; 
    2020import java.io.IOException; 
    21 import java.sql.Connection; 
    22 import java.sql.DriverManager; 
    23 import java.sql.SQLException; 
    2421import java.util.Collection; 
    2522import java.util.Map; 
     
    3330import org.bridgedb.IDMapperException; 
    3431import org.bridgedb.Xref; 
     32import org.bridgedb.XrefIterator; 
    3533import org.bridgedb.impl.InternalUtils; 
    3634 
     
    3937 * such as looking up cross-references and backpage text. 
    4038 */ 
    41 public abstract class IDMapperRdb implements IDMapper, AttributeMapper 
     39public abstract class IDMapperRdb implements IDMapper, AttributeMapper, XrefIterator 
    4240{ 
    4341        static 
     
    125123        { 
    126124                return InternalUtils.mapMultiFromSingle(this, srcXrefs, tgtDataSources); 
    127         }        
     125        } 
    128126} 
  • trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImplCommon.java

    r473 r542  
    7777                        "SELECT id, code, attrvalue FROM attribute WHERE " + 
    7878                        "attrname = ? AND LOWER(ID) LIKE ?" 
     79                ); 
     80        final SimpleGdb.QueryLifeCycle qAllXrefs = new SimpleGdb.QueryLifeCycle( 
     81                        "SELECT id, code FROM datanode" 
     82                ); 
     83        final SimpleGdb.QueryLifeCycle qAllXrefsByDatasource = new SimpleGdb.QueryLifeCycle( 
     84                        "SELECT id, code FROM datanode WHERE code = ?" 
    7985                ); 
    8086 
     
    375381        } 
    376382 
     383        @Override 
     384        public Iterable<Xref> getIterator() throws IDMapperException { 
     385                Set<Xref> xrefs = new HashSet<Xref>(); 
     386                final QueryLifeCycle pst = qAllXrefs; 
     387                synchronized (pst) {  
     388                try 
     389                { 
     390                        pst.init(); 
     391                        ResultSet rs = pst.executeQuery(); 
     392                        while (rs.next()) 
     393                        { 
     394                                xrefs.add(new Xref(rs.getString(1), DataSource.getBySystemCode(rs.getString(2)))); 
     395                        } 
     396                } 
     397                catch (SQLException ignore) 
     398                { 
     399                        throw new IDMapperException(ignore); 
     400                } 
     401                        finally {pst.cleanup(); } 
     402                return xrefs; 
     403                }                
     404        } 
     405         
     406        @Override 
     407        public Iterable<Xref> getIterator(DataSource ds) throws IDMapperException { 
     408                Set<Xref> xrefs = new HashSet<Xref>(); 
     409                final QueryLifeCycle pst = qAllXrefsByDatasource; 
     410                synchronized (pst) {  
     411                try 
     412                { 
     413                        pst.init(); 
     414                        pst.setString(1, ds.getSystemCode()); 
     415                        ResultSet rs = pst.executeQuery(); 
     416                        while (rs.next()) 
     417                        { 
     418                                xrefs.add(new Xref(rs.getString(1), ds)); 
     419                        } 
     420                } 
     421                catch (SQLException ignore) 
     422                { 
     423                        throw new IDMapperException(ignore); 
     424                } 
     425                        finally {pst.cleanup(); } 
     426                return xrefs; 
     427                } 
     428        } 
    377429}