- 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/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 }
