Show
Ignore:
Timestamp:
02/25/10 20:57:40 (2 years ago)
Author:
martijn
Message:

Refactoring dead code:
Removed all methods pertaining to constructing Derby databases
to a separate package (org.bridgedb.rdb.construct). Also
factored out common code between SimpleGdbImpl?2/3 into
SimpleGdbImplCommon?

Files:
1 modified

Legend:

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

    r308 r317  
    1717package org.bridgedb.rdb; 
    1818 
     19import java.io.File; 
     20import java.io.IOException; 
    1921import java.sql.Connection; 
    2022import java.sql.DriverManager; 
     
    2224import java.util.Collection; 
    2325import java.util.Map; 
     26import java.util.Properties; 
    2427import java.util.Set; 
    2528 
     
    5356                public IDMapper connect(String location) throws IDMapperException  
    5457                { 
    55                         return SimpleGdbFactory.createInstance(location, new DataDerby(), 0); 
     58                        try 
     59                        { 
     60                                String url = "jdbc:derby:jar:(" + location + ")database"; 
     61                                Connection con = DriverManager.getConnection(url); 
     62                                return SimpleGdbFactory.createInstance(location, con); 
     63                        } 
     64                        catch (SQLException ex) 
     65                        { 
     66                                throw new IDMapperException(ex); 
     67                        } 
    5668                } 
    5769        } 
     
    6779                        try 
    6880                        { 
    69                                 Connection con = DriverManager.getConnection("jdbc:" + location); 
    70                          
    71                                 return SimpleGdbFactory.createInstance(location, con, 0); 
     81                                String url = "jdbc:" + location; 
     82                                Connection con = DriverManager.getConnection(url); 
     83                                return SimpleGdbFactory.createInstance(location, con); 
    7284                        } 
    7385                        catch (SQLException ex) 
     
    8698                public IDMapper connect(String location) throws IDMapperException  
    8799                { 
    88                         //TODO: make port and host configurable 
    89                         DBConnectorDerbyServer.init ("wikipathways.org", 1527); 
    90                         return SimpleGdbFactory.createInstance(location, new DBConnectorDerbyServer(), 0); 
     100                        try 
     101                        { 
     102                    Map<String, String> args =  
     103                        InternalUtils.parseLocation(location, "host", "port"); 
     104 
     105                    if (!args.containsKey("BASE"))  
     106                        throw new IllegalArgumentException("Expected species name in connection string: " + location); 
     107 
     108                    String host = args.containsKey("host") ? args.get("host") : "wikipathways.org"; 
     109                    String port = args.containsKey("port") ? args.get("port") : "1527"; 
     110                     
     111                                Class.forName("org.apache.derby.jdbc.ClientDriver"); 
     112                                Properties sysprop = System.getProperties(); 
     113                                sysprop.setProperty("derby.storage.tempDirectory", System.getProperty("java.io.tmpdir")); 
     114                                sysprop.setProperty("derby.stream.error.file", File.createTempFile("derby",".log").toString()); 
     115                                 
     116                                String url = "jdbc:derby://" + host + ":" + port + "/" + args.get("BASE"); 
     117                                Connection con = DriverManager.getConnection(url); 
     118                                return SimpleGdbFactory.createInstance(location, con); 
     119                        } 
     120                        catch (SQLException f) 
     121                        { 
     122                                throw new IDMapperException (f); 
     123                        } 
     124                        catch (IOException e) 
     125                        { 
     126                                throw new IDMapperException (e); 
     127                        } 
     128                        catch (ClassNotFoundException e) 
     129                        { 
     130                                throw new IDMapperException (e); 
     131                        } 
    91132                } 
    92133        }