- Timestamp:
- 02/25/10 20:57:30 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImpl3.java
r308 r316 42 42 private static final int GDB_COMPAT_VERSION = 3; //Preferred schema version 43 43 44 private final SimpleGdb. LazyPst pstDatasources = new SimpleGdb.LazyPst(44 private final SimpleGdb.QueryLifeCycle qDatasources = new SimpleGdb.QueryLifeCycle( 45 45 "SELECT codeRight FROM link GROUP BY codeRight" 46 46 ); 47 private final SimpleGdb. LazyPst pstInfo = new SimpleGdb.LazyPst(47 private final SimpleGdb.QueryLifeCycle qInfo = new SimpleGdb.QueryLifeCycle( 48 48 "SELECT * FROM info" 49 49 ); 50 private final SimpleGdb. LazyPst pstXrefExists = new SimpleGdb.LazyPst(50 private final SimpleGdb.QueryLifeCycle qXrefExists = new SimpleGdb.QueryLifeCycle( 51 51 "SELECT id FROM " + "datanode" + " WHERE " + 52 52 "id = ? AND code = ?" 53 53 ); 54 private final SimpleGdb. LazyPst pstAttribute = new SimpleGdb.LazyPst(54 private final SimpleGdb.QueryLifeCycle qAttribute = new SimpleGdb.QueryLifeCycle( 55 55 "SELECT attrvalue FROM attribute " + 56 56 " WHERE id = ? AND code = ? AND attrname = ?" 57 57 ); 58 private final SimpleGdb. LazyPst pstAllAttributes = new SimpleGdb.LazyPst(58 private final SimpleGdb.QueryLifeCycle qAllAttributes = new SimpleGdb.QueryLifeCycle( 59 59 "SELECT attrname, attrvalue FROM attribute " + 60 60 " WHERE id = ? AND code = ?" 61 61 ); 62 private final SimpleGdb. LazyPst pstAttributesSet = new SimpleGdb.LazyPst(62 private final SimpleGdb.QueryLifeCycle qAttributesSet = new SimpleGdb.QueryLifeCycle( 63 63 "SELECT attrname FROM attribute GROUP BY attrname" 64 64 ); 65 private final SimpleGdb. LazyPst pstCrossRefs = new SimpleGdb.LazyPst(65 private final SimpleGdb.QueryLifeCycle qCrossRefs = new SimpleGdb.QueryLifeCycle ( 66 66 "SELECT dest.idRight, dest.codeRight FROM link AS src JOIN link AS dest " + 67 67 "ON src.idLeft = dest.idLeft and src.codeLeft = dest.codeLeft " + 68 68 "WHERE src.idRight = ? AND src.codeRight = ?" 69 69 ); 70 private final SimpleGdb. LazyPst pstCrossRefsWithCode = new SimpleGdb.LazyPst(70 private final SimpleGdb.QueryLifeCycle qCrossRefsWithCode = new SimpleGdb.QueryLifeCycle ( 71 71 "SELECT dest.idRight, dest.codeRight FROM link AS src JOIN link AS dest " + 72 72 "ON src.idLeft = dest.idLeft and src.codeLeft = dest.codeLeft " + 73 73 "WHERE src.idRight = ? AND src.codeRight = ? AND dest.codeRight = ?" 74 74 ); 75 private final SimpleGdb. LazyPst pstRefsByAttribute = new SimpleGdb.LazyPst(75 private final SimpleGdb.QueryLifeCycle qRefsByAttribute = new SimpleGdb.QueryLifeCycle ( 76 76 "SELECT datanode.id, datanode.code FROM datanode " + 77 77 " LEFT JOIN attribute ON attribute.code = datanode.code AND attribute.id = datanode.id " + 78 78 "WHERE attrName = ? AND attrValue = ?" 79 79 ); 80 private final SimpleGdb. LazyPst pstFreeSearch = new SimpleGdb.LazyPst(80 private final SimpleGdb.QueryLifeCycle qFreeSearch = new SimpleGdb.QueryLifeCycle ( 81 81 "SELECT id, code FROM datanode WHERE " + 82 82 "LOWER(ID) LIKE ?" 83 83 ); 84 private final SimpleGdb. LazyPst pstAttributeSearch = new SimpleGdb.LazyPst(84 private final SimpleGdb.QueryLifeCycle qAttributeSearch = new SimpleGdb.QueryLifeCycle ( 85 85 "SELECT id, code, attrvalue FROM attribute WHERE " + 86 86 "attrname = 'Symbol' AND LOWER(attrvalue) LIKE ?" 87 87 ); 88 private final SimpleGdb. LazyPst pstIdSearchWithAttributes = new SimpleGdb.LazyPst(88 private final SimpleGdb.QueryLifeCycle qIdSearchWithAttributes = new SimpleGdb.QueryLifeCycle ( 89 89 "SELECT id, code, attrvalue FROM attribute WHERE " + 90 90 "attrname = 'Symbol' AND LOWER(ID) LIKE ?" 91 91 ); 92 92 93 93 /** {@inheritDoc} */ 94 94 public boolean xrefExists(Xref xref) throws IDMapperException 95 95 { 96 final QueryLifeCycle pst = qXrefExists; 96 97 try 97 98 { 98 PreparedStatement pst = pstXrefExists.getPreparedStatement();99 pst.init(); 99 100 pst.setString(1, xref.getId()); 100 101 pst.setString(2, xref.getDataSource().getSystemCode()); … … 110 111 throw new IDMapperException (e); 111 112 } 113 finally {pst.cleanup(); } 112 114 return false; 113 115 } … … 117 119 { 118 120 Set<Xref> refs = new HashSet<Xref>(); 119 121 final QueryLifeCycle pst = resultDs.length != 1 ? qCrossRefs : qCrossRefsWithCode; 120 122 try 121 123 { 122 PreparedStatement pst; 123 if (resultDs.length != 1) 124 { 125 pst = pstCrossRefs.getPreparedStatement(); 126 } 127 else 128 { 129 pst = pstCrossRefsWithCode.getPreparedStatement(); 130 pst.setString(3, resultDs[0].getSystemCode()); 131 } 132 124 pst.init(); 133 125 pst.setString(1, idc.getId()); 134 126 pst.setString(2, idc.getDataSource().getSystemCode()); 127 if (resultDs.length == 1) 128 { 129 pst.setString(3, resultDs[0].getSystemCode()); 130 } 135 131 136 132 Set<DataSource> dsFilter = new HashSet<DataSource>(Arrays.asList(resultDs)); … … 150 146 throw new IDMapperException (e); 151 147 } 148 finally {pst.cleanup(); } 152 149 153 150 return refs; … … 159 156 List<Xref> refs = new ArrayList<Xref>(); 160 157 158 final QueryLifeCycle pst = qRefsByAttribute; 161 159 try { 162 PreparedStatement pst = pstRefsByAttribute.getPreparedStatement();160 pst.init(); 163 161 pst.setString(1, attrName); 164 162 pst.setString(2, attrValue); … … 171 169 throw new IDMapperException (e); 172 170 } 171 finally {pst.cleanup(); } 173 172 // Logger.log.trace("End fetching cross references by attribute"); 174 173 return refs; … … 308 307 { 309 308 Set<Xref> result = new HashSet<Xref>(); 309 final QueryLifeCycle pst = qFreeSearch; 310 310 try { 311 PreparedStatement ps1 = pstFreeSearch.getPreparedStatement(); 312 ps1.setQueryTimeout(QUERY_TIMEOUT); 313 if(limit > NO_LIMIT) 314 { 315 ps1.setMaxRows(limit); 316 } 317 318 ps1.setString(1, "%" + text.toLowerCase() + "%"); 319 ResultSet r = ps1.executeQuery(); 311 pst.init(limit); 312 pst.setString(1, "%" + text.toLowerCase() + "%"); 313 ResultSet r = pst.executeQuery(); 320 314 while(r.next()) { 321 315 String id = r.getString(1); … … 329 323 throw new IDMapperException(e); 330 324 } 325 finally {pst.cleanup(); } 331 326 return result; 332 327 } … … 465 460 { 466 461 Map<String, String> result = new HashMap<String, String>(); 462 final QueryLifeCycle pst = qInfo; 467 463 try 468 464 { 469 PreparedStatement pst = pstInfo.getPreparedStatement();465 pst.init(); 470 466 ResultSet rs = pst.executeQuery(); 471 467 … … 496 492 { 497 493 Set<DataSource> result = new HashSet<DataSource>(); 494 final QueryLifeCycle pst = qDatasources; 498 495 try 499 496 { 500 PreparedStatement pst = pstDatasources.getPreparedStatement();497 pst.init(); 501 498 ResultSet rs = pst.executeQuery(); 502 499 while (rs.next()) … … 539 536 { 540 537 Set<String> result = new HashSet<String>(); 538 final QueryLifeCycle pst = qAttribute; 541 539 try { 542 PreparedStatement pst = pstAttribute.getPreparedStatement();540 pst.init(); 543 541 pst.setString (1, ref.getId()); 544 542 pst.setString (2, ref.getDataSource().getSystemCode()); … … 551 549 return result; 552 550 } catch (SQLException e) { throw new IDMapperException (e); } // Database unavailable 551 finally {pst.cleanup(); } 553 552 } 554 553 … … 558 557 { 559 558 Map<String, Set<String>> result = new HashMap<String, Set<String>>(); 559 final QueryLifeCycle pst = qAllAttributes; 560 560 try { 561 PreparedStatement pst = pstAllAttributes.getPreparedStatement();561 pst.init(); 562 562 pst.setString (1, ref.getId()); 563 563 pst.setString (2, ref.getDataSource().getSystemCode()); … … 580 580 return result; 581 581 } catch (SQLException e) { throw new IDMapperException ("Xref:" + ref, e); } // Database unavailable 582 finally {pst.cleanup(); } 582 583 } 583 584 … … 602 603 { 603 604 Map<Xref, String> result = new HashMap<Xref, String>(); 605 final QueryLifeCycle pst = (MATCH_ID.equals (attrType)) ? 606 qIdSearchWithAttributes : qAttributeSearch; 604 607 try { 605 PreparedStatement pst = (MATCH_ID.equals (attrType)) ? 606 pstIdSearchWithAttributes.getPreparedStatement() : pstAttributeSearch.getPreparedStatement(); 607 pst.setQueryTimeout(QUERY_TIMEOUT); 608 if(limit > NO_LIMIT) pst.setMaxRows(limit); 608 pst.init(limit); 609 609 pst.setString(1, "%" + query.toLowerCase() + "%"); 610 610 ResultSet r = pst.executeQuery(); … … 620 620 throw new IDMapperException (e); 621 621 } 622 finally {pst.cleanup(); } 622 623 return result; 623 624 } … … 627 628 { 628 629 Set<String> result = new HashSet<String>(); 630 final QueryLifeCycle pst = qAttributesSet; 629 631 try 630 632 { 631 PreparedStatement pst = pstAttributesSet.getPreparedStatement();633 pst.init(); 632 634 ResultSet rs = pst.executeQuery(); 633 635 while (rs.next()) … … 640 642 throw new IDMapperException(ignore); 641 643 } 644 finally {pst.cleanup(); } 642 645 return result; 643 646 }
