- 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/SimpleGdb.java
r317 r318 18 18 19 19 import java.sql.Connection; 20 import java.sql.DriverManager; 20 21 import java.sql.PreparedStatement; 21 22 import java.sql.ResultSet; … … 52 53 public abstract class SimpleGdb extends IDMapperRdb 53 54 { 55 private final String connectionString; 54 56 /** 55 57 * Create IDMapper based on an existing SQL connection. 56 58 * @param con Existing SQL Connection. 57 59 */ 58 SimpleGdb(Connection con) 59 { 60 this.con = con; 61 } 62 63 private boolean keepConnection = true; 64 60 SimpleGdb(String dbName, String connectionString) 61 { 62 this.connectionString = connectionString; 63 this.dbName = dbName; 64 } 65 66 private boolean singleConnection = true; 67 private boolean neverCloseConnection = true; 68 65 69 /** 66 70 * helper class that handles the life cycle of a connection, query and resultset. … … 160 164 inited = false; 161 165 if (rs != null) try { rs.close(); } catch (SQLException ignore) {} 162 if ( keepConnection) return;166 if (neverCloseConnection) return; 163 167 if (pst != null) try { pst.close(); } catch (SQLException ignore) {} 168 pst = null; 164 169 if (con != null) try { con.close(); } catch (SQLException ignore) {} 165 } 166 } 167 168 protected Connection getConnection() throws SQLException 169 { 170 con = null; 171 } 172 } 173 174 private Connection con = null; 175 176 synchronized public Connection getConnection() throws SQLException 177 { 178 // if singleConnection is true, each call to getConnection() will return the same object. 179 // if singleConnection is false, each call to getConneciton() will lead to a new connection object being created. 180 if (!singleConnection || con == null) 181 { 182 con = DriverManager.getConnection(connectionString); 183 con.setReadOnly(true); 184 } 170 185 return con; 171 186 } … … 174 189 * The {@link Connection} to the Gene Database. 175 190 */ 176 protected Connection con = null; 191 192 //private Connection con = null; 177 193 178 194 /** {@inheritDoc} */ 179 final public boolean isConnected() { return con != null; } 180 181 protected String dbName; 195 final public boolean isConnected() { 196 //return con != null; 197 return true; 198 } 199 200 protected final String dbName; 182 201 183 202 /** {@inheritDoc} */ … … 187 206 final public void close() throws IDMapperException 188 207 { 189 if (con == null) throw new IDMapperException("Database connection already closed"); 190 try 191 { 192 con.close(); 193 } 194 catch (SQLException ex) 195 { 196 throw new IDMapperException (ex); 197 } 198 con = null; 208 // try 209 // { 210 // con.close(); 211 // } 212 // catch (SQLException ex) 213 // { 214 // throw new IDMapperException (ex); 215 // } 216 // con = null; 199 217 } 200 218 … … 212 230 try 213 231 { 214 ResultSet r = con.createStatement().executeQuery("SELECT COUNT(*) FROM " + "datanode");232 ResultSet r = getConnection().createStatement().executeQuery("SELECT COUNT(*) FROM " + "datanode"); 215 233 r.next(); 216 234 result = r.getInt (1); … … 234 252 try 235 253 { 236 ResultSet r = con.createStatement().executeQuery(254 ResultSet r = getConnection().createStatement().executeQuery( 237 255 "SELECT COUNT(*) FROM datanode WHERE code = '" + ds.getSystemCode() + "'"); 238 256 r.next();
