Changeset 551 for trunk

Show
Ignore:
Timestamp:
12/04/11 13:09:55 (6 months ago)
Author:
martijn
Message:

Improve GdbConstruct? to allow setting of info props

Location:
trunk/org.bridgedb.rdb.construct/src/org/bridgedb/rdb/construct
Files:
2 modified

Legend:

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

    r320 r551  
    5151    public int addLink(Xref left, Xref right); 
    5252     
     53    /**  
     54     * Set a database info property  
     55     * @throws IDMapperException  
     56     */ 
     57    public void setInfo(String key, String value) throws IDMapperException; 
     58     
    5359        /** 
    5460           Create indices on the database 
  • trunk/org.bridgedb.rdb.construct/src/org/bridgedb/rdb/construct/GdbConstructImpl3.java

    r320 r551  
    134134        } 
    135135 
     136        public void setInfo(String key, String value) throws IDMapperException 
     137        { 
     138                try 
     139                { 
     140                        /**  
     141                         * This is a bit awkward because we store keys as columns. 
     142                         * TODO: in a future schema version this should be a regular 2-column table. 
     143                         */ 
     144                        if (!key.matches("^\\w+$")) throw new IllegalArgumentException("key: '" + key + "' contains invalid characters"); 
     145                        PreparedStatement pstInfo1 = con.prepareStatement ( 
     146                                        "ALTER TABLE info " + 
     147                                        "ADD COLUMN " + key + " VARCHAR (50)" 
     148                                ); 
     149                        pstInfo1.execute(); 
     150                        PreparedStatement pstInfo2 = con.prepareStatement ( 
     151                                                "UPDATE info SET " + key + " = ? " + 
     152                                                "WHERE schemaversion = " + GDB_COMPAT_VERSION 
     153                                        ); 
     154                        pstInfo2.setString(1, value); 
     155                        pstInfo2.execute(); 
     156                } 
     157                catch (SQLException ex) 
     158                { 
     159                        throw new IDMapperException(ex); 
     160                } 
     161        } 
     162         
    136163         
    137164        /**