- Timestamp:
- 02/25/10 20:57:43 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbFactory.java
r317 r318 18 18 19 19 import java.sql.Connection; 20 import java.sql.DriverManager; 20 21 import java.sql.ResultSet; 21 22 import java.sql.SQLException; 23 import java.sql.Statement; 22 24 23 25 import org.bridgedb.IDMapperException; … … 38 40 * <p> 39 41 * Use this instead of constructor to create an instance of SimpleGdb that matches the schema version. 40 * @param dbName The file containing the Gene Database. 41 * @param con An SQL Connection to the database 42 * @param props PROP_RECREATE if you want to create a new database, overwriting any existing ones. Otherwise, PROP_NONE. 42 * @param connectionString a JDBC Connection string 43 43 * @return a new Gdb 44 44 * @throws IDMapperException on failure 45 45 */ 46 public static SimpleGdb createInstance(String dbName, Connection con) throws IDMapperException46 public static SimpleGdb createInstance(String dbName, String connectionString) throws IDMapperException 47 47 { 48 if( dbName== null) throw new NullPointerException();48 if(connectionString == null) throw new NullPointerException(); 49 49 50 50 int version = 0; 51 Connection con = null; 52 ResultSet r = null; 53 Statement stmt = null; 51 54 try 52 55 { 53 ResultSet r = con.createStatement().executeQuery("SELECT schemaversion FROM info"); 56 con = DriverManager.getConnection(connectionString); 57 stmt = con.createStatement(); 58 r = stmt.executeQuery("SELECT schemaversion FROM info"); 54 59 if(r.next()) version = r.getInt(1); 55 60 } … … 57 62 { 58 63 //Ignore, older db's don't even have schema version 59 } 64 } 65 finally 66 { 67 if (r != null) try { r.close(); } catch (SQLException ignore) {} 68 if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {} 69 if (con != null) try { con.close(); } catch (SQLException ignore) {} 70 } 60 71 61 72 switch (version) 62 73 { 63 74 case 2: 64 return new SimpleGdbImpl2(dbName, con );75 return new SimpleGdbImpl2(dbName, connectionString); 65 76 case 3: 66 return new SimpleGdbImpl3(dbName, con );77 return new SimpleGdbImpl3(dbName, connectionString); 67 78 //NB add future schema versions here 68 79 default:
