Changeset 318
- Timestamp:
- 02/25/10 20:57:43 (2 years ago)
- Location:
- trunk/org.bridgedb.rdb/src/org/bridgedb/rdb
- Files:
-
- 6 modified
-
IDMapperRdb.java (modified) (3 diffs)
-
SimpleGdb.java (modified) (7 diffs)
-
SimpleGdbFactory.java (modified) (3 diffs)
-
SimpleGdbImpl2.java (modified) (5 diffs)
-
SimpleGdbImpl3.java (modified) (4 diffs)
-
SimpleGdbImplCommon.java (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/IDMapperRdb.java
r317 r318 56 56 public IDMapper connect(String location) throws IDMapperException 57 57 { 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 } 58 String url = "jdbc:derby:jar:(" + location + ")database"; 59 return SimpleGdbFactory.createInstance(location, url); 68 60 } 69 61 } … … 77 69 public IDMapper connect(String location) throws IDMapperException 78 70 { 79 try 80 { 81 String url = "jdbc:" + location; 82 Connection con = DriverManager.getConnection(url); 83 return SimpleGdbFactory.createInstance(location, con); 84 } 85 catch (SQLException ex) 86 { 87 throw new IDMapperException(ex); 88 } 71 String url = "jdbc:" + location; 72 return SimpleGdbFactory.createInstance(location, url); 89 73 } 90 74 } … … 115 99 116 100 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); 101 return SimpleGdbFactory.createInstance(location, url); 123 102 } 124 103 catch (IOException e) -
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(); -
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: -
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImpl2.java
r317 r318 51 51 { 52 52 final QueryLifeCycle pst = qBackpage; 53 try { 54 pst.init(); 55 pst.setString (1, ref.getId()); 56 pst.setString (2, ref.getDataSource().getSystemCode()); 57 ResultSet r = pst.executeQuery(); 58 String result = null; 59 if (r.next()) 60 { 61 result = r.getString(1); 62 } 63 return result; 64 } catch (SQLException e) { throw new IDMapperException (e); } //Gene not found 65 finally {pst.cleanup(); } 53 synchronized (pst) 54 { 55 try { 56 pst.init(); 57 pst.setString (1, ref.getId()); 58 pst.setString (2, ref.getDataSource().getSystemCode()); 59 ResultSet r = pst.executeQuery(); 60 String result = null; 61 if (r.next()) 62 { 63 result = r.getString(1); 64 } 65 return result; 66 } catch (SQLException e) { throw new IDMapperException (e); } //Gene not found 67 finally {pst.cleanup(); } 68 } 66 69 } 67 70 … … 75 78 * @throws IDMapperException when the database could not be created or connected to 76 79 */ 77 public SimpleGdbImpl2(String dbName, Connection con) throws IDMapperException 78 { 79 super (con); 80 81 if(dbName == null) throw new NullPointerException(); 82 this.dbName = dbName; 83 84 try 85 { 86 con.setReadOnly(true); 87 } 88 catch (SQLException e) 89 { 90 throw new IDMapperException (e); 91 } 80 public SimpleGdbImpl2(String dbName, String connectionString) throws IDMapperException 81 { 82 super (dbName, connectionString); 83 84 if(dbName == null) throw new NullPointerException(); 92 85 checkSchemaVersion(); 93 86 } … … 102 95 try 103 96 { 104 ResultSet r = con.createStatement().executeQuery("SELECT schemaversion FROM info");97 ResultSet r = getConnection().createStatement().executeQuery("SELECT schemaversion FROM info"); 105 98 if(r.next()) version = r.getInt(1); 106 99 } … … 148 141 } 149 142 150 try { 151 pst.init(); 152 pst.setString (1, ref.getId()); 153 pst.setString (2, ref.getDataSource().getSystemCode()); 154 pst.setString (3, attrname); 155 ResultSet r = pst.executeQuery(); 156 if (r.next()) 157 { 158 result.add (r.getString(1)); 159 } 160 return result; 161 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref + ", Attribute: " + attrname, e); } // Database unavailable 162 finally {pst.cleanup(); } 143 synchronized (pst) 144 { 145 try { 146 pst.init(); 147 pst.setString (1, ref.getId()); 148 pst.setString (2, ref.getDataSource().getSystemCode()); 149 pst.setString (3, attrname); 150 ResultSet r = pst.executeQuery(); 151 if (r.next()) 152 { 153 result.add (r.getString(1)); 154 } 155 return result; 156 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref + ", Attribute: " + attrname, e); } // Database unavailable 157 finally {pst.cleanup(); } 158 } 163 159 } 164 160 … … 186 182 } 187 183 188 try { 189 pst.init(); 190 pst.setString (1, ref.getId()); 191 pst.setString (2, ref.getDataSource().getSystemCode()); 192 ResultSet r = pst.executeQuery(); 193 if (r.next()) 194 { 195 String key = r.getString(1); 196 String value = r.getString(2); 197 if (result.containsKey (key)) 198 { 199 result.get(key).add (value); 200 } 201 else 202 { 203 Set<String> valueSet = new HashSet<String>(); 204 valueSet.add (value); 205 result.put (key, valueSet); 206 } 207 } 208 return result; 209 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref, e); } // Database unavailable 210 finally {pst.cleanup(); } 184 synchronized (pst) 185 { 186 try { 187 pst.init(); 188 pst.setString (1, ref.getId()); 189 pst.setString (2, ref.getDataSource().getSystemCode()); 190 ResultSet r = pst.executeQuery(); 191 if (r.next()) 192 { 193 String key = r.getString(1); 194 String value = r.getString(2); 195 if (result.containsKey (key)) 196 { 197 result.get(key).add (value); 198 } 199 else 200 { 201 Set<String> valueSet = new HashSet<String>(); 202 valueSet.add (value); 203 result.put (key, valueSet); 204 } 205 } 206 return result; 207 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref, e); } // Database unavailable 208 finally {pst.cleanup(); } 209 } 211 210 } 212 211 } -
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImpl3.java
r317 r318 42 42 * @throws IDMapperException when the database could not be created or connected to 43 43 */ 44 public SimpleGdbImpl3(String dbName, Connection con) throws IDMapperException44 public SimpleGdbImpl3(String dbName, String connectionString) throws IDMapperException 45 45 { 46 super(con); 47 if(dbName == null) throw new NullPointerException(); 48 49 this.dbName = dbName; 50 51 try 52 { 53 con.setReadOnly(true); 54 } 55 catch (SQLException e) 56 { 57 throw new IDMapperException (e); 58 } 46 super(dbName, connectionString); 59 47 checkSchemaVersion(); 60 48 } … … 69 57 try 70 58 { 71 ResultSet r = con.createStatement().executeQuery("SELECT schemaversion FROM info");59 ResultSet r = getConnection().createStatement().executeQuery("SELECT schemaversion FROM info"); 72 60 if(r.next()) version = r.getInt(1); 73 61 } … … 88 76 Set<String> result = new HashSet<String>(); 89 77 final QueryLifeCycle pst = qAttribute; 90 try { 91 pst.init(); 92 pst.setString (1, ref.getId()); 93 pst.setString (2, ref.getDataSource().getSystemCode()); 94 pst.setString (3, attrname); 95 ResultSet r = pst.executeQuery(); 96 if (r.next()) 97 { 98 result.add (r.getString(1)); 99 } 100 return result; 101 } catch (SQLException e) { throw new IDMapperException (e); } // Database unavailable 102 finally {pst.cleanup(); } 78 synchronized (pst) 79 { 80 try { 81 pst.init(); 82 pst.setString (1, ref.getId()); 83 pst.setString (2, ref.getDataSource().getSystemCode()); 84 pst.setString (3, attrname); 85 ResultSet r = pst.executeQuery(); 86 if (r.next()) 87 { 88 result.add (r.getString(1)); 89 } 90 return result; 91 } catch (SQLException e) { throw new IDMapperException (e); } // Database unavailable 92 finally {pst.cleanup(); } 93 } 103 94 } 104 95 … … 109 100 Map<String, Set<String>> result = new HashMap<String, Set<String>>(); 110 101 final QueryLifeCycle pst = qAllAttributes; 111 try { 112 pst.init(); 113 pst.setString (1, ref.getId()); 114 pst.setString (2, ref.getDataSource().getSystemCode()); 115 ResultSet r = pst.executeQuery(); 116 if (r.next()) 117 { 118 String key = r.getString(1); 119 String value = r.getString(2); 120 if (result.containsKey (key)) 102 synchronized (pst) 103 { 104 try { 105 pst.init(); 106 pst.setString (1, ref.getId()); 107 pst.setString (2, ref.getDataSource().getSystemCode()); 108 ResultSet r = pst.executeQuery(); 109 if (r.next()) 121 110 { 122 result.get(key).add (value); 111 String key = r.getString(1); 112 String value = r.getString(2); 113 if (result.containsKey (key)) 114 { 115 result.get(key).add (value); 116 } 117 else 118 { 119 Set<String> valueSet = new HashSet<String>(); 120 valueSet.add (value); 121 result.put (key, valueSet); 122 } 123 123 } 124 else 125 { 126 Set<String> valueSet = new HashSet<String>(); 127 valueSet.add (value); 128 result.put (key, valueSet); 129 } 130 } 131 return result; 132 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref, e); } // Database unavailable 133 finally {pst.cleanup(); } 124 return result; 125 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref, e); } // Database unavailable 126 finally {pst.cleanup(); } 127 } 134 128 } 135 129 } -
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImplCommon.java
r317 r318 1 1 package org.bridgedb.rdb; 2 2 3 import java.sql.Connection;4 3 import java.sql.ResultSet; 5 4 import java.sql.ResultSetMetaData; … … 24 23 public abstract class SimpleGdbImplCommon extends SimpleGdb 25 24 { 26 SimpleGdbImplCommon( Connection con) throws IDMapperException27 { 28 super( con);25 SimpleGdbImplCommon(String dbName, String connectionString) throws IDMapperException 26 { 27 super(dbName, connectionString); 29 28 caps = new SimpleGdbCapabilities(); 30 29 } … … 83 82 { 84 83 final QueryLifeCycle pst = qXrefExists; 85 try 86 { 87 pst.init(); 88 pst.setString(1, xref.getId()); 89 pst.setString(2, xref.getDataSource().getSystemCode()); 90 ResultSet r = pst.executeQuery(); 91 92 while(r.next()) 93 { 94 return true; 95 } 96 } 97 catch (SQLException e) 98 { 99 throw new IDMapperException (e); 100 } 101 finally {pst.cleanup(); } 102 return false; 84 synchronized (pst) { 85 try 86 { 87 pst.init(); 88 pst.setString(1, xref.getId()); 89 pst.setString(2, xref.getDataSource().getSystemCode()); 90 ResultSet r = pst.executeQuery(); 91 92 while(r.next()) 93 { 94 return true; 95 } 96 } 97 catch (SQLException e) 98 { 99 throw new IDMapperException (e); 100 } 101 finally {pst.cleanup(); } 102 return false; 103 } 103 104 } 104 105 … … 110 111 Map<String, String> getInfo() throws IDMapperException 111 112 { 113 Map<String, String> result = new HashMap<String, String>(); 112 114 final QueryLifeCycle pst = qInfo; 113 Map<String, String> result = new HashMap<String, String>(); 114 try 115 { 116 pst.init(); 117 ResultSet rs = pst.executeQuery(); 115 synchronized (pst) { 116 try 117 { 118 pst.init(); 119 ResultSet rs = pst.executeQuery(); 120 121 if (rs.next()) 122 { 123 ResultSetMetaData rsmd = rs.getMetaData(); 124 for (int i = 1; i <= rsmd.getColumnCount(); ++i) 125 { 126 String key = rsmd.getColumnName(i); 127 String val = rs.getString(i); 128 result.put (key, val); 129 } 130 } 131 } 132 catch (SQLException ex) 133 { 134 throw new IDMapperException (ex); 135 } 118 136 119 if (rs.next()) 120 { 121 ResultSetMetaData rsmd = rs.getMetaData(); 122 for (int i = 1; i <= rsmd.getColumnCount(); ++i) 123 { 124 String key = rsmd.getColumnName(i); 125 String val = rs.getString(i); 126 result.put (key, val); 127 } 128 } 129 } 130 catch (SQLException ex) 131 { 132 throw new IDMapperException (ex); 133 } 134 135 return result; 137 return result; 138 } 136 139 } 137 140 … … 144 147 145 148 if (idc.getDataSource() == null) return refs; 146 try 147 { 148 pst.init(); 149 pst.setString(1, idc.getId()); 150 pst.setString(2, idc.getDataSource().getSystemCode()); 151 if (resultDs.length == 1) pst.setString(3, resultDs[0].getSystemCode()); 152 153 Set<DataSource> dsFilter = new HashSet<DataSource>(Arrays.asList(resultDs)); 154 155 ResultSet rs = pst.executeQuery(); 156 while (rs.next()) 157 { 158 DataSource ds = DataSource.getBySystemCode(rs.getString(2)); 159 if (resultDs.length == 0 || dsFilter.contains(ds)) 149 synchronized (pst) { 150 try 151 { 152 pst.init(); 153 pst.setString(1, idc.getId()); 154 pst.setString(2, idc.getDataSource().getSystemCode()); 155 if (resultDs.length == 1) pst.setString(3, resultDs[0].getSystemCode()); 156 157 Set<DataSource> dsFilter = new HashSet<DataSource>(Arrays.asList(resultDs)); 158 159 ResultSet rs = pst.executeQuery(); 160 while (rs.next()) 160 161 { 161 refs.add (new Xref (rs.getString(1), ds)); 162 } 163 } 164 } 165 catch (SQLException e) 166 { 167 throw new IDMapperException (e); 168 } 169 finally {pst.cleanup(); } 162 DataSource ds = DataSource.getBySystemCode(rs.getString(2)); 163 if (resultDs.length == 0 || dsFilter.contains(ds)) 164 { 165 refs.add (new Xref (rs.getString(1), ds)); 166 } 167 } 168 } 169 catch (SQLException e) 170 { 171 throw new IDMapperException (e); 172 } 173 finally {pst.cleanup(); } 170 174 171 return refs; 175 return refs; 176 } 172 177 } 173 178 … … 178 183 179 184 final QueryLifeCycle pst = qRefsByAttribute; 180 try { 181 pst.init(); 182 pst.setString(1, attrName); 183 pst.setString(2, attrValue); 184 ResultSet r = pst.executeQuery(); 185 while(r.next()) { 186 Xref ref = new Xref(r.getString(1), DataSource.getBySystemCode(r.getString(2))); 187 refs.add(ref); 188 } 189 } catch(SQLException e) { 190 throw new IDMapperException (e); 191 } 192 finally {pst.cleanup(); } 193 // Logger.log.trace("End fetching cross references by attribute"); 194 return refs; 185 synchronized (pst) { 186 try { 187 pst.init(); 188 pst.setString(1, attrName); 189 pst.setString(2, attrValue); 190 ResultSet r = pst.executeQuery(); 191 while(r.next()) { 192 Xref ref = new Xref(r.getString(1), DataSource.getBySystemCode(r.getString(2))); 193 refs.add(ref); 194 } 195 } catch(SQLException e) { 196 throw new IDMapperException (e); 197 } 198 finally {pst.cleanup(); } 199 // Logger.log.trace("End fetching cross references by attribute"); 200 return refs; 201 } 195 202 } 196 203 … … 200 207 Set<Xref> result = new HashSet<Xref>(); 201 208 final QueryLifeCycle pst = qFreeSearch; 202 try { 203 pst.init(limit); 204 pst.setString(1, "%" + text.toLowerCase() + "%"); 205 ResultSet r = pst.executeQuery(); 206 while(r.next()) { 207 String id = r.getString(1); 208 DataSource ds = DataSource.getBySystemCode(r.getString(2)); 209 Xref ref = new Xref (id, ds); 210 result.add (ref); 211 } 212 } 213 catch (SQLException e) 214 { 215 throw new IDMapperException(e); 216 } 217 finally {pst.cleanup(); } 218 return result; 209 synchronized (pst) { 210 try { 211 pst.init(limit); 212 pst.setString(1, "%" + text.toLowerCase() + "%"); 213 ResultSet r = pst.executeQuery(); 214 while(r.next()) { 215 String id = r.getString(1); 216 DataSource ds = DataSource.getBySystemCode(r.getString(2)); 217 Xref ref = new Xref (id, ds); 218 result.add (ref); 219 } 220 } 221 catch (SQLException e) 222 { 223 throw new IDMapperException(e); 224 } 225 finally {pst.cleanup(); } 226 return result; 227 } 219 228 } 220 229 … … 227 236 Set<DataSource> result = new HashSet<DataSource>(); 228 237 final QueryLifeCycle pst = qDatasources; 229 try 230 { 231 pst.init(); 232 ResultSet rs = pst.executeQuery(); 233 while (rs.next()) 234 { 235 DataSource ds = DataSource.getBySystemCode(rs.getString(1)); 236 result.add (ds); 237 } 238 } 239 catch (SQLException ignore) 240 { 241 throw new IDMapperException(ignore); 242 } 243 finally {pst.cleanup(); } 244 return result; 238 synchronized (pst) { 239 try 240 { 241 pst.init(); 242 ResultSet rs = pst.executeQuery(); 243 while (rs.next()) 244 { 245 DataSource ds = DataSource.getBySystemCode(rs.getString(1)); 246 result.add (ds); 247 } 248 } 249 catch (SQLException ignore) 250 { 251 throw new IDMapperException(ignore); 252 } 253 finally {pst.cleanup(); } 254 return result; 255 } 245 256 } 246 257 … … 288 299 final QueryLifeCycle pst = (MATCH_ID.equals (attrType)) ? 289 300 qIdSearchWithAttributes : qAttributeSearch; 290 try { 291 pst.init(limit); 292 pst.setString(1, "%" + query.toLowerCase() + "%"); 293 ResultSet r = pst.executeQuery(); 294 295 while(r.next()) 296 { 297 String id = r.getString("id"); 298 String code = r.getString("code"); 299 String symbol = r.getString("attrValue"); 300 result.put(new Xref (id, DataSource.getBySystemCode(code)), symbol); 301 } 302 } catch (SQLException e) { 303 throw new IDMapperException (e); 304 } 305 finally {pst.cleanup(); } 306 return result; 301 synchronized (pst) { 302 try { 303 pst.init(limit); 304 pst.setString(1, "%" + query.toLowerCase() + "%"); 305 ResultSet r = pst.executeQuery(); 306 307 while(r.next()) 308 { 309 String id = r.getString("id"); 310 String code = r.getString("code"); 311 String symbol = r.getString("attrValue"); 312 result.put(new Xref (id, DataSource.getBySystemCode(code)), symbol); 313 } 314 } catch (SQLException e) { 315 throw new IDMapperException (e); 316 } 317 finally {pst.cleanup(); } 318 return result; 319 } 307 320 } 308 321 … … 312 325 Set<String> result = new HashSet<String>(); 313 326 final QueryLifeCycle pst = qAttributesSet; 314 try 315 { 316 pst.init(); 317 ResultSet rs = pst.executeQuery(); 318 while (rs.next()) 319 { 320 result.add (rs.getString(1)); 321 } 322 } 323 catch (SQLException ignore) 324 { 325 throw new IDMapperException(ignore); 326 } 327 finally {pst.cleanup(); } 328 return result; 327 synchronized (pst) { 328 try 329 { 330 pst.init(); 331 ResultSet rs = pst.executeQuery(); 332 while (rs.next()) 333 { 334 result.add (rs.getString(1)); 335 } 336 } 337 catch (SQLException ignore) 338 { 339 throw new IDMapperException(ignore); 340 } 341 finally {pst.cleanup(); } 342 return result; 343 } 329 344 } 330 345
