1 package uk.ac.ebi.intenz.mapper;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Statement;
8 import java.util.ArrayList;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.Set;
12 import java.util.TreeMap;
13 import java.util.TreeSet;
14
15 import org.apache.log4j.Logger;
16
17 import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant;
18 import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
19 import uk.ac.ebi.intenz.domain.constants.Status;
20 import uk.ac.ebi.intenz.domain.enzyme.EnzymaticReactions;
21 import uk.ac.ebi.intenz.domain.enzyme.EnzymeComment;
22 import uk.ac.ebi.intenz.domain.enzyme.EnzymeCommissionNumber;
23 import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
24 import uk.ac.ebi.intenz.domain.enzyme.EnzymeLink;
25 import uk.ac.ebi.intenz.domain.enzyme.EnzymeName;
26 import uk.ac.ebi.intenz.domain.exceptions.DomainException;
27 import uk.ac.ebi.intenz.domain.exceptions.EcException;
28 import uk.ac.ebi.intenz.domain.exceptions.EnzymeReactionException;
29 import uk.ac.ebi.intenz.domain.exceptions.EnzymeReferenceException;
30 import uk.ac.ebi.intenz.domain.history.HistoryGraph;
31 import uk.ac.ebi.intenz.domain.reference.Reference;
32 import uk.ac.ebi.intenz.domain.stats.EnzymeStatistics;
33 import uk.ac.ebi.rhea.mapper.MapperException;
34
35
36
37
38
39
40
41
42
43
44 public class EnzymeEntryMapper {
45
46 private static final Logger LOGGER = Logger.getLogger(EnzymeEntryMapper.class);
47
48
49
50
51
52 private static final String COLUMNS =
53 "e.enzyme_id, e.ec1, e.ec2, e.ec3, e.ec4, e.history, e.note, e.status, " +
54 "e.source, e.active, s1.name, s2.name, s3.name";
55
56 private static final String LIST_COLUMNS =
57 "enzyme_id, ec1, ec2, ec3, ec4, history, note, status, source, active";
58
59 private EnzymeReactionMapper enzymeReactionMapper;
60
61 public EnzymeEntryMapper() {
62 enzymeReactionMapper = new EnzymeReactionMapper();
63 }
64
65 public EnzymeEntryMapper(EnzymeReactionMapper enzymeReactionMapper){
66 this.enzymeReactionMapper = enzymeReactionMapper;
67 }
68
69 @Override
70 protected void finalize() throws Throwable {
71 close();
72 }
73
74 public void close() {
75 if (enzymeReactionMapper != null){
76 try {
77 enzymeReactionMapper.close();
78 } catch (MapperException e) {
79 LOGGER.error("Closing enzymeReactionMapper", e);
80 }
81 }
82 }
83
84
85
86
87
88
89 private String findByEcStatement() {
90 return new StringBuilder("SELECT ").append(COLUMNS)
91 .append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3")
92 .append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ? AND e.ec4 = ?")
93 .append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?")
94 .append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?")
95 .append(" AND e.status = ? AND enzyme_id NOT IN")
96 .append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')")
97 .toString();
98 }
99
100
101
102
103
104 private String findAllSubSubclassEntriesByEcStatement() {
105 return new StringBuilder("SELECT ").append(COLUMNS)
106 .append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3")
107 .append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ?")
108 .append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?")
109 .append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ? AND e.source = 'INTENZ'")
110 .append(" ORDER BY e.ec1, e.ec2, e.ec3, e.ec4").toString();
111 }
112
113
114
115
116
117
118
119 private String findAllByEcStatement(Boolean preliminary){
120 StringBuilder sb = new StringBuilder("SELECT ").append(COLUMNS)
121 .append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3")
122 .append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ? AND e.ec4 = ?")
123 .append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?")
124 .append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?");
125 if (preliminary != null){
126 sb.append(" AND e.status ").append(preliminary? "=" : "!=").append(" 'PM'");
127 }
128 return sb.toString();
129 }
130
131
132
133
134
135
136 private String findByIdStatement() {
137 return new StringBuilder("SELECT ").append(COLUMNS)
138 .append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3")
139 .append(" WHERE e.enzyme_id = ? AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?")
140 .append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?").toString();
141 }
142
143
144
145
146
147
148
149
150
151 private String findListStatement() {
152 return new StringBuilder("SELECT ").append(LIST_COLUMNS)
153 .append(" FROM enzymes WHERE ec1 = ? AND ec2 = ? AND ec3 = ?")
154 .append(" AND status IN ('OK','PM') AND enzyme_id NOT IN")
155 .append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')")
156 .append(" ORDER BY status, ec1, ec2, ec3, ec4").toString();
157 }
158
159
160
161
162
163
164
165
166
167
168 private String findAllStatement() {
169 return new StringBuilder("SELECT ").append(LIST_COLUMNS)
170 .append(" FROM enzymes WHERE status IN ('OK','PM') AND enzyme_id NOT IN")
171 .append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')")
172 .append(" ORDER BY ec1, ec2, ec3, status, ec4").toString();
173 }
174
175
176
177
178
179
180 private String findCoreListStatement() {
181 return new StringBuilder("SELECT ").append(LIST_COLUMNS)
182 .append(" FROM enzymes WHERE status = ?")
183 .append(" ORDER BY ec1, ec2, ec3, ec4").toString();
184 }
185
186
187
188
189
190 private String findEcStatement() {
191 return "SELECT ec1, ec2, ec3, ec4, status FROM enzymes WHERE enzyme_id = ?";
192 }
193
194 private String findIDInMappingTable() {
195 return "SELECT enzyme_id FROM id2ec WHERE ec = ? and status = ?";
196 }
197
198
199
200
201
202
203 private String findHistoryLineStatement() {
204 return "SELECT history FROM enzymes WHERE enzyme_id = ?";
205 }
206
207
208
209
210
211
212 private String findNoteStatement() {
213 return "SELECT note FROM enzymes WHERE enzyme_id = ?";
214 }
215
216
217
218
219
220
221 private String findNextEnzymeIdStatement() {
222 return "SELECT s_enzyme_id.nextval from DUAL";
223 }
224
225 private String countIUBMBEnzymesStatement() {
226 return new StringBuilder("SELECT status, active FROM enzymes")
227 .append(" WHERE source = 'IUBMB' AND enzyme_id NOT IN")
228 .append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')")
229 .append(" ORDER BY ec1, ec2, ec3, ec4").toString();
230 }
231
232 private String countClassesStatement() {
233 return "SELECT count(*) FROM classes";
234 }
235
236 private String countSubclassesStatement() {
237 return "SELECT count(*) FROM subclasses";
238 }
239
240 private String countSubSubclassesStatement() {
241 return "SELECT count(*) FROM subsubclasses";
242 }
243
244
245
246
247
248
249 private String insertStatement() {
250 return "INSERT INTO enzymes (enzyme_id, ec1, ec2, ec3, ec4, history, note, status, source, active)" +
251 " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
252 }
253
254
255
256
257
258
259 private String updateStatement() {
260 return "UPDATE enzymes SET ec1 = ?, ec2 = ?, ec3 = ?, ec4 = ?, status = ?," +
261 " source = ?, note = ?, history = ?, active = ? WHERE enzyme_id = ?";
262 }
263
264
265
266
267
268
269 private String updateEcStatement() {
270 return "UPDATE enzymes SET ec1 = ?, ec2 = ?, ec3 = ?, ec4 = ? WHERE enzyme_id = ?";
271 }
272
273
274
275
276
277
278 private String updateHistoryLineStatement() {
279 return "UPDATE enzymes SET history = ? WHERE enzyme_id = ?";
280 }
281
282
283
284
285
286
287 private String updateNoteStatement() {
288 return "UPDATE enzymes SET note = ? WHERE enzyme_id = ?";
289 }
290
291
292
293
294
295
296 private String updateStatusStatement() {
297 return "UPDATE enzymes SET status = ? WHERE enzyme_id = ?";
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 public EnzymeEntry findByEc(int ec1, int ec2, int ec3, int ec4, Status status,
316 Connection con)
317 throws SQLException, DomainException, MapperException {
318 PreparedStatement findStatement = null;
319 ResultSet rs = null;
320 EnzymeEntry result = null;
321 try {
322
323 findStatement = con.prepareStatement(findByEcStatement());
324 findStatement.setInt(1, ec1);
325 findStatement.setInt(2, ec2);
326 findStatement.setInt(3, ec3);
327 findStatement.setInt(4, ec4);
328 findStatement.setInt(5, ec1);
329 findStatement.setInt(6, ec1);
330 findStatement.setInt(7, ec2);
331 findStatement.setInt(8, ec1);
332 findStatement.setInt(9, ec2);
333 findStatement.setInt(10, ec3);
334 findStatement.setString(11, status == null? "OK" : status.getCode());
335 rs = findStatement.executeQuery();
336 if (rs.next()) {
337 result = doLoad(rs);
338 findEnzymeData(result, con);
339 }
340 } finally {
341 if (rs != null) rs.close();
342 if (findStatement != null) findStatement.close();
343 }
344
345 return result;
346 }
347
348
349
350
351
352
353
354
355
356
357
358
359 public EnzymeEntry findByEc(String ecString, Status status, Connection con)
360 throws NumberFormatException, SQLException, DomainException, MapperException{
361 EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf(ecString);
362 if (EnzymeCommissionNumber.isPreliminary(ecString)){
363 status = Status.PRELIMINARY;
364 }
365 return findByEc(ec.getEc1(), ec.getEc2(), ec.getEc3(), ec.getEc4(),
366 status, con);
367 }
368
369 public List<EnzymeEntry> findAllByEc(int ec1, int ec2, int ec3, int ec4,
370 Boolean preliminary, Connection con)
371 throws SQLException, DomainException {
372 if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
373 PreparedStatement findAllByEcStatement = null;
374 ResultSet rs = null;
375 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
376
377 try {
378
379 findAllByEcStatement = con.prepareStatement(findAllByEcStatement(preliminary));
380 findAllByEcStatement.setInt(1, ec1);
381 findAllByEcStatement.setInt(2, ec2);
382 findAllByEcStatement.setInt(3, ec3);
383 findAllByEcStatement.setInt(4, ec4);
384 findAllByEcStatement.setInt(5, ec1);
385 findAllByEcStatement.setInt(6, ec1);
386 findAllByEcStatement.setInt(7, ec2);
387 findAllByEcStatement.setInt(8, ec1);
388 findAllByEcStatement.setInt(9, ec2);
389 findAllByEcStatement.setInt(10, ec3);
390 rs = findAllByEcStatement.executeQuery();
391 while (rs.next()) {
392 EnzymeEntry enzymeEntry = doLoadGhost(rs);
393
394
395 loadHistoryGraph(enzymeEntry, con);
396
397
398 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
399 List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con);
400 if (commonNames != null) enzymeEntry.setCommonNames(commonNames);
401
402 result.add(enzymeEntry);
403 }
404 } finally {
405 if (rs != null) rs.close();
406 if (findAllByEcStatement != null) findAllByEcStatement.close();
407 }
408
409 if (result.size() == 0) return null;
410 return result;
411
412
413 }
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429 public List<EnzymeEntry> findAllByEc(int ec1, int ec2, int ec3, int ec4, Connection con)
430 throws SQLException, DomainException {
431 return findAllByEc(ec1, ec2, ec3, ec4, null, con);
432 }
433
434 private HistoryGraph getHistoryGraph(Connection con, EnzymeEntry enzymeEntry)
435 throws SQLException, DomainException {
436 HistoryGraph historyGraph;
437 switch (enzymeEntry.getStatus()){
438 case PRELIMINARY:
439 if (enzymeEntry.isActive()){
440
441 EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper();
442 historyGraph = futureEventsMapper.find(enzymeEntry, con);
443 break;
444 }
445
446 case APPROVED:
447 EnzymeHistoryMapper historyEventsMapper = new EnzymeHistoryMapper();
448 historyGraph = historyEventsMapper.find(enzymeEntry, con);
449 break;
450 default:
451 EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper();
452 historyGraph = futureEventsMapper.find(enzymeEntry, con);
453 }
454 return historyGraph;
455 }
456
457 public List<EnzymeEntry> findAllSubSubclassEntriesByEc(int ec1, int ec2, int ec3, Connection con)
458 throws SQLException, DomainException {
459 if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
460 PreparedStatement findAllByEcStatement = null;
461 ResultSet rs = null;
462 Map<EnzymeCommissionNumber, EnzymeEntry> map =
463 new TreeMap<EnzymeCommissionNumber, EnzymeEntry>();
464
465 try {
466
467 findAllByEcStatement = con.prepareStatement(findAllSubSubclassEntriesByEcStatement());
468 findAllByEcStatement.setInt(1, ec1);
469 findAllByEcStatement.setInt(2, ec2);
470 findAllByEcStatement.setInt(3, ec3);
471 findAllByEcStatement.setInt(4, ec1);
472 findAllByEcStatement.setInt(5, ec1);
473 findAllByEcStatement.setInt(6, ec2);
474 findAllByEcStatement.setInt(7, ec1);
475 findAllByEcStatement.setInt(8, ec2);
476 findAllByEcStatement.setInt(9, ec3);
477 rs = findAllByEcStatement.executeQuery();
478 while (rs.next()) {
479 EnzymeEntry enzymeEntry = doLoadGhost(rs);
480 if (map.containsKey(enzymeEntry.getEc())){
481 EnzymeEntry existing = (EnzymeEntry) map.get(enzymeEntry.getEc());
482
483
484 if (existing.getId().longValue() > enzymeEntry.getId().longValue())
485 continue;
486 }
487
488 loadHistoryGraph(enzymeEntry, con);
489
490
491 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
492 List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con);
493 if (commonNames != null) enzymeEntry.setCommonNames(commonNames);
494
495 map.put(enzymeEntry.getEc(), enzymeEntry);
496 }
497 } finally {
498 if (rs != null) rs.close();
499 if (findAllByEcStatement != null) findAllByEcStatement.close();
500 }
501
502 return map.isEmpty()? null : new ArrayList<EnzymeEntry>(map.values());
503 }
504
505
506
507
508
509
510
511
512
513
514
515
516
517 public EnzymeEntry findById(Long id, Connection con, boolean ghost)
518 throws SQLException, DomainException, MapperException {
519 PreparedStatement findStatement = null;
520 EnzymeEntry result = null;
521 ResultSet rsEc = null, rs = null;
522 int ec1, ec2, ec3;
523
524 try {
525
526 findStatement = con.prepareStatement(findEcStatement());
527 findStatement.setLong(1, id.longValue());
528 rsEc = findStatement.executeQuery();
529 if (rsEc.next()) {
530 if (rsEc.getInt("ec1") != 0)
531 ec1 = rsEc.getInt("ec1");
532 else
533 return result;
534 if (rsEc.getInt("ec2") != 0)
535 ec2 = rsEc.getInt("ec2");
536 else
537 return result;
538 if (rsEc.getInt("ec3") != 0)
539 ec3 = rsEc.getInt("ec3");
540 else
541 return result;
542 } else
543 return result;
544
545 if (findStatement != null) findStatement.close();
546
547
548 findStatement = con.prepareStatement(findByIdStatement());
549 findStatement.setLong(1, id.longValue());
550 findStatement.setInt(2, ec1);
551 findStatement.setInt(3, ec1);
552 findStatement.setInt(4, ec2);
553 findStatement.setInt(5, ec1);
554 findStatement.setInt(6, ec2);
555 findStatement.setInt(7, ec3);
556 rs = findStatement.executeQuery();
557 if (rs.next()) {
558 if (ghost){
559 result = doLoadGhost(rs);
560 } else {
561 result = doLoad(rs);
562 findEnzymeData(result, con);
563 }
564 }
565 } finally {
566 if (rsEc != null) rsEc.close();
567 if (rs != null) rs.close();
568 if (findStatement != null) findStatement.close();
569 }
570
571 return result;
572 }
573
574
575
576
577
578
579
580
581
582
583
584 public EnzymeEntry findById(long id, Connection con)
585 throws SQLException, DomainException, MapperException{
586 return findById(id, con, false);
587 }
588
589
590
591
592
593
594
595
596
597
598 public EnzymeEntry findGhostById(int id, Connection con)
599 throws SQLException, DomainException {
600 EnzymeEntry entry = null;
601 try {
602 entry = findById((long) id, con, true);
603 } catch (MapperException e) {
604
605 }
606 return entry;
607 }
608
609 public Long findIDInMappingTable(String ec, Status status, Connection con)
610 throws SQLException {
611 if (con == null || ec == null) throw new NullPointerException();
612 PreparedStatement findStatement = null;
613 ResultSet rs = null;
614 try {
615
616 findStatement = con.prepareStatement(findIDInMappingTable());
617 findStatement.setString(1, ec);
618 findStatement.setString(2, status.getCode());
619 rs = findStatement.executeQuery();
620 if (rs.next()) {
621 return new Long(rs.getLong(1));
622 }
623 return new Long(-1);
624 } finally {
625 if (rs != null) rs.close();
626 if (findStatement != null) findStatement.close();
627 }
628 }
629
630
631
632
633
634
635
636
637
638
639 public List<EnzymeEntry> findAll(Connection con) throws SQLException, DomainException {
640 Statement findListStatement = null;
641 ResultSet rs = null;
642 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
643 boolean noResult = true;
644
645 try {
646 findListStatement = con.createStatement();
647 rs = findListStatement.executeQuery(findAllStatement());
648
649 while (rs.next()) {
650 noResult = false;
651 EnzymeEntry enzymeEntry = doLoadGhost(rs);
652
653
654 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
655 List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con);
656 if (commonNames != null) enzymeEntry.setCommonNames(commonNames);
657 result.add(enzymeEntry);
658 }
659 } finally {
660 if (rs != null) rs.close();
661 if (findListStatement != null) findListStatement.close();
662 }
663
664 if (noResult) return null;
665 return result;
666 }
667
668
669
670
671
672
673
674
675
676
677
678
679
680 public List<EnzymeEntry> findList(String ec1, String ec2, String ec3,
681 Connection con)
682 throws SQLException, DomainException {
683 PreparedStatement findListStatement = null;
684 ResultSet rs = null;
685 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
686 boolean noResult = true;
687
688 try {
689 findListStatement = con.prepareStatement(findListStatement());
690 findListStatement.setString(1, ec1);
691 findListStatement.setString(2, ec2);
692 findListStatement.setString(3, ec3);
693 rs = findListStatement.executeQuery();
694
695 while (rs.next()) {
696 noResult = false;
697 EnzymeEntry enzymeEntry = doLoadGhost(rs);
698
699
700 loadHistoryGraph(enzymeEntry, con);
701
702
703 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
704 List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con);
705 if (commonNames != null) enzymeEntry.setCommonNames(commonNames);
706 result.add(enzymeEntry);
707 }
708 } finally {
709 if (rs != null) rs.close();
710 if (findListStatement != null) findListStatement.close();
711 }
712
713 if (noResult) return null;
714 return result;
715 }
716
717
718
719
720
721
722
723
724
725 public List<EnzymeEntry> findByStatus(Connection con, Status status)
726 throws SQLException, DomainException{
727 PreparedStatement findListStatement = null;
728 ResultSet rs = null;
729 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
730 try {
731 findListStatement = con.prepareStatement(findCoreListStatement());
732 findListStatement.setString(1, status.getCode());
733 rs = findListStatement.executeQuery();
734
735 while (rs.next()) {
736 EnzymeEntry enzymeEntry = doLoadGhost(rs);
737
738 loadHistoryGraph(enzymeEntry, con);
739
740 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
741 List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con);
742 if (commonNames != null) enzymeEntry.setCommonNames(commonNames);
743 result.add(enzymeEntry);
744 }
745 } finally {
746 if (rs != null) rs.close();
747 if (findListStatement != null) findListStatement.close();
748 }
749 return result;
750 }
751
752
753
754
755
756
757
758
759
760
761 public List<EnzymeEntry> findProposedList(Connection con)
762 throws SQLException, DomainException {
763 return findByStatus(con, Status.PROPOSED);
764 }
765
766
767
768
769
770
771
772
773
774
775 public List<EnzymeEntry> findSuggestedList(Connection con)
776 throws SQLException, DomainException {
777 return findByStatus(con, Status.SUGGESTED);
778 }
779
780
781
782
783
784
785
786
787 public List<EnzymeEntry> findPreliminaryEcsList(Connection con)
788 throws SQLException, DomainException{
789 return findByStatus(con, Status.PRELIMINARY);
790 }
791
792
793
794
795
796
797
798
799
800 public List<EnzymeEntry> exportAllEntries(Connection con)
801 throws SQLException, DomainException, MapperException{
802 List<EnzymeEntry> entries = new ArrayList<EnzymeEntry>();
803 Statement findListStatement = null;
804 ResultSet rs = null;
805 try {
806 findListStatement = con.createStatement();
807 rs = findListStatement.executeQuery(findAllStatement());
808 while (rs.next()){
809 EnzymeEntry entry = doLoadCore(rs);
810 findEnzymeData(entry, con);
811 entries.add(entry);
812 }
813 } finally {
814 if (rs != null) rs.close();
815 if (findListStatement != null) findListStatement.close();
816 }
817 return entries.isEmpty()? null : entries;
818 }
819
820
821
822
823
824
825
826
827
828
829
830
831
832 public List<EnzymeEntry> exportApprovedSibEntries(Connection con)
833 throws SQLException, DomainException, MapperException {
834 Statement findListStatement = null;
835 ResultSet rs = null;
836 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
837 try {
838 findListStatement = con.createStatement();
839 rs = findListStatement.executeQuery(findAllStatement());
840 while (rs.next()) {
841 EnzymeEntry enzymeEntry = doLoadCore(rs);
842 exportSIBEnzymeData(enzymeEntry, con);
843 result.add(enzymeEntry);
844 }
845 } finally {
846 if (rs != null) rs.close();
847 if (findListStatement != null) findListStatement.close();
848 }
849 return result.isEmpty()? null: result;
850 }
851
852
853
854
855
856
857
858
859
860
861
862
863
864 public List<EnzymeEntry> findFullProposedList(Connection con)
865 throws SQLException, DomainException, MapperException {
866 PreparedStatement findListStatement = null;
867 ResultSet rs = null;
868 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
869 boolean noResult = true;
870
871 try {
872 findListStatement = con.prepareStatement(findCoreListStatement());
873 findListStatement.setString(1, "PR");
874 rs = findListStatement.executeQuery();
875
876 while (rs.next()) {
877 noResult = false;
878 EnzymeEntry enzymeEntry = doLoadCore(rs);
879 findEnzymeData(enzymeEntry, con);
880 result.add(enzymeEntry);
881 }
882 } finally {
883 if (rs != null) rs.close();
884 if (findListStatement != null) findListStatement.close();
885 }
886
887 if (noResult) return null;
888 return result;
889 }
890
891
892
893
894
895
896
897
898
899
900
901
902
903 public List<EnzymeEntry> findFullSuggestedList(Connection con)
904 throws SQLException, DomainException, MapperException {
905 PreparedStatement findListStatement = null;
906 ResultSet rs = null;
907 List<EnzymeEntry> result = new ArrayList<EnzymeEntry>();
908 boolean noResult = true;
909
910 try {
911 findListStatement = con.prepareStatement(findCoreListStatement());
912 findListStatement.setString(1, "SU");
913 rs = findListStatement.executeQuery();
914
915 while (rs.next()) {
916 noResult = false;
917 EnzymeEntry enzymeEntry = doLoadCore(rs);
918 findEnzymeData(enzymeEntry, con);
919 result.add(enzymeEntry);
920 }
921 } finally {
922 if (rs != null) rs.close();
923 if (findListStatement != null) findListStatement.close();
924 }
925
926 if (noResult) return null;
927 return result;
928 }
929
930
931
932
933
934
935
936
937
938
939 public EnzymeCommissionNumber findEC(String id, Connection con)
940 throws SQLException, DomainException {
941 int ec1 = 0, ec2 = 0, ec3 = 0, ec4 = 0;
942 Status status = null;
943 PreparedStatement findEcStatement = null;
944 ResultSet rs = null;
945 try {
946 findEcStatement = con.prepareStatement(findEcStatement());
947 findEcStatement.setString(1, id);
948 rs = findEcStatement.executeQuery();
949
950 while (rs.next()) {
951 ec1 = rs.getInt("ec1");
952 ec2 = rs.getInt("ec2");
953 ec3 = rs.getInt("ec3");
954 ec4 = rs.getInt("ec4");
955 status = Status.fromCode(rs.getString("status"));
956 }
957 } finally {
958 if (rs != null) rs.close();
959 if (findEcStatement != null) findEcStatement.close();
960 }
961
962 return EnzymeCommissionNumber.valueOf(
963 ec1, ec2, ec3, ec4, status.equals(Status.PRELIMINARY));
964 }
965
966
967
968
969
970
971
972
973
974
975 public static boolean ecExists(EnzymeCommissionNumber ec, Connection con)
976 throws SQLException {
977 if (ec == null) throw new NullPointerException("Parameter 'ec' must not be null.");
978 if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
979
980 PreparedStatement findStatement = null;
981 ResultSet rs = null;
982 try {
983 switch (ec.getType()) {
984 case CLASS:
985 findStatement = con.prepareStatement("SELECT ec1 FROM classes WHERE ec1 = ?");
986 findStatement.setInt(1, ec.getEc1());
987 break;
988 case SUBCLASS:
989 findStatement = con.prepareStatement("SELECT ec1 FROM subclasses" +
990 " WHERE ec1 = ? AND ec2 = ?");
991 findStatement.setInt(1, ec.getEc1());
992 findStatement.setInt(2, ec.getEc2());
993 break;
994 case SUBSUBCLASS:
995 findStatement = con.prepareStatement("SELECT ec1 FROM subsubclasses" +
996 " WHERE ec1 = ? AND ec2 = ? AND ec3 = ?");
997 findStatement.setInt(1, ec.getEc1());
998 findStatement.setInt(2, ec.getEc2());
999 findStatement.setInt(3, ec.getEc3());
1000 break;
1001 case ENZYME:
1002 findStatement = con.prepareStatement("SELECT ec1 FROM enzymes " +
1003 "WHERE ec1 = ? AND ec2 = ? AND ec3 = ? AND ec4 = ? AND status != 'PM'");
1004 findStatement.setInt(1, ec.getEc1());
1005 findStatement.setInt(2, ec.getEc2());
1006 findStatement.setInt(3, ec.getEc3());
1007 findStatement.setInt(4, ec.getEc4());
1008 break;
1009 case PRELIMINARY:
1010 findStatement = con.prepareStatement("SELECT ec1 FROM enzymes " +
1011 "WHERE ec1 = ? AND ec2 = ? AND ec3 = ? AND ec4 = ? AND status = 'PM'");
1012 findStatement.setInt(1, ec.getEc1());
1013 findStatement.setInt(2, ec.getEc2());
1014 findStatement.setInt(3, ec.getEc3());
1015 findStatement.setInt(4, ec.getEc4());
1016 break;
1017 }
1018 rs = findStatement.executeQuery();
1019 return rs.next();
1020 } finally {
1021 if (rs != null) rs.close();
1022 if (findStatement != null) findStatement.close();
1023 }
1024 }
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034 public String findHistoryLine(Long id, Connection con) throws SQLException {
1035 String historyLine = "";
1036 PreparedStatement findHistoryLineStatement = null;
1037 ResultSet rs = null;
1038 try {
1039 findHistoryLineStatement = con.prepareStatement(findHistoryLineStatement());
1040 findHistoryLineStatement.setLong(1, id.longValue());
1041 rs = findHistoryLineStatement.executeQuery();
1042
1043 while (rs.next()) {
1044 if (rs.getString("history") != null) historyLine = rs.getString("history");
1045 }
1046 } finally {
1047 if (rs != null) rs.close();
1048 if (findHistoryLineStatement != null) findHistoryLineStatement.close();
1049 }
1050
1051 return historyLine;
1052 }
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062 public String findNote(Long id, Connection con) throws SQLException {
1063 String note = "";
1064 PreparedStatement findNoteStatement = null;
1065 ResultSet rs = null;
1066
1067 try {
1068 findNoteStatement = con.prepareStatement(findNoteStatement());
1069 findNoteStatement.setLong(1, id.longValue());
1070 rs = findNoteStatement.executeQuery();
1071
1072 while (rs.next()) {
1073 if (rs.getString("note") != null) note = rs.getString("note");
1074 }
1075 } finally {
1076 if (rs != null) rs.close();
1077 if (findNoteStatement != null) findNoteStatement.close();
1078 }
1079
1080 return note;
1081 }
1082
1083
1084
1085
1086
1087
1088 public EnzymeStatistics findStats(Connection con) throws SQLException {
1089 PreparedStatement countIUBMBEnzymes = null, countClasses = null,
1090 countSubclasses = null, countSubSubclasses = null;
1091 EnzymeStatistics result = new EnzymeStatistics();
1092 ResultSet rs = null;
1093
1094 int allEnzymes = 0;
1095 int approved = 0;
1096 int proposed = 0;
1097 int suggested = 0;
1098 int approvedDeleted = 0;
1099 int proposedDeleted = 0;
1100 int suggestedDeleted = 0;
1101
1102 try {
1103 countIUBMBEnzymes = con.prepareStatement(countIUBMBEnzymesStatement());
1104 rs = countIUBMBEnzymes.executeQuery();
1105 while (rs.next()) {
1106 allEnzymes++;
1107 if (rs.getString(1).equals("OK")) {
1108 approved++;
1109 if (rs.getString(2).equals("N")) approvedDeleted++;
1110 }
1111 if (rs.getString(1).equals("PR")) {
1112 proposed++;
1113 if (rs.getString(2).equals("N")) proposedDeleted++;
1114 }
1115 if (rs.getString(1).equals("SU")) {
1116 suggested++;
1117 if (rs.getString(2).equals("N")) suggestedDeleted++;
1118 }
1119 }
1120
1121 result.setAllEnzymes(allEnzymes);
1122 result.setApprovedEnzymes(approved);
1123 result.setApprovedDeletedEnzymes(approvedDeleted);
1124 result.setProposedEnzymes(proposed);
1125 result.setProposedDeletedEnzymes(proposedDeleted);
1126 result.setSuggestedEnzymes(suggested);
1127 result.setSuggestedDeletedEnzymes(suggestedDeleted);
1128
1129 countClasses = con.prepareStatement(countClassesStatement());
1130 rs = countClasses.executeQuery();
1131 if (rs.next()) {
1132 result.setClasses(rs.getInt(1));
1133 }
1134
1135 countSubclasses = con.prepareStatement(countSubclassesStatement());
1136 rs = countSubclasses.executeQuery();
1137 if (rs.next()) {
1138 result.setSubclasses(rs.getInt(1));
1139 }
1140
1141 countSubSubclasses = con.prepareStatement(countSubSubclassesStatement());
1142 rs = countSubSubclasses.executeQuery();
1143 if (rs.next()) {
1144 result.setSubsubclasses(rs.getInt(1));
1145 }
1146
1147 } finally {
1148 if (rs != null) rs.close();
1149 countIUBMBEnzymes.close();
1150 countClasses.close();
1151 countSubclasses.close();
1152 countSubSubclasses.close();
1153 }
1154
1155 return result;
1156 }
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 public void insert(Long enzymeId, EnzymeCommissionNumber ec, Status status,
1176 EnzymeSourceConstant source, String note, String historyLine,
1177 boolean isActive, Connection con)
1178 throws SQLException {
1179 PreparedStatement insertStatement = null;
1180 try {
1181 insertStatement = con.prepareStatement(insertStatement());
1182 insertStatement.setLong(1, enzymeId.longValue());
1183 insertStatement.setInt(2, ec.getEc1());
1184 insertStatement.setInt(3, ec.getEc2());
1185 insertStatement.setInt(4, ec.getEc3());
1186 insertStatement.setInt(5, ec.getEc4());
1187 insertStatement.setString(6, historyLine);
1188 insertStatement.setString(7, note);
1189 insertStatement.setString(8, status.getCode());
1190 insertStatement.setString(9, source.toString());
1191 insertStatement.setString(10, isActive ? "Y" : "N");
1192 insertStatement.execute();
1193 } finally {
1194 insertStatement.close();
1195 }
1196 }
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218 public void update(Long enzymeId, EnzymeCommissionNumber ec, Status status,
1219 EnzymeSourceConstant source, String note, String historyLine,
1220 boolean active, Connection con)
1221 throws SQLException {
1222 if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
1223 if (ec == null) throw new NullPointerException("Parameter 'ec' must not be null.");
1224 if (status == null) throw new NullPointerException("Parameter 'status' must not be null.");
1225 if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
1226 if (note == null) throw new NullPointerException("Parameter 'note' must not be null.");
1227 if (historyLine == null) throw new NullPointerException("Parameter 'historyLine' must not be null.");
1228 if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
1229
1230 PreparedStatement updateStatement = null;
1231 try {
1232 updateStatement = con.prepareStatement(updateStatement());
1233 updateStatement.setInt(1, ec.getEc1());
1234 updateStatement.setInt(2, ec.getEc2());
1235 updateStatement.setInt(3, ec.getEc3());
1236 updateStatement.setInt(4, ec.getEc4());
1237 updateStatement.setString(5, status.getCode());
1238 updateStatement.setString(6, source.toString());
1239 updateStatement.setString(7, note);
1240 updateStatement.setString(8, historyLine);
1241 updateStatement.setString(9, active? "Y" : "N");
1242 updateStatement.setLong(10, enzymeId.longValue());
1243 updateStatement.execute();
1244 } finally {
1245 updateStatement.close();
1246 }
1247 }
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257 public void updateEc(Long enzymeId, EnzymeCommissionNumber newEc, Connection con) throws SQLException {
1258 PreparedStatement updateEcStatement = null;
1259
1260 try {
1261 updateEcStatement = con.prepareStatement(updateEcStatement());
1262 updateEcStatement.setInt(1, newEc.getEc1());
1263 updateEcStatement.setInt(2, newEc.getEc2());
1264 updateEcStatement.setInt(3, newEc.getEc3());
1265 updateEcStatement.setInt(4, newEc.getEc4());
1266 updateEcStatement.setLong(5, enzymeId.longValue());
1267 updateEcStatement.execute();
1268 } finally {
1269 updateEcStatement.close();
1270 }
1271 }
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281 public void updateNote(Long enzymeId, String note, Connection con) throws SQLException {
1282 PreparedStatement updateNoteStatement = null;
1283
1284 try {
1285 updateNoteStatement = con.prepareStatement(updateNoteStatement());
1286 updateNoteStatement.setString(1, note);
1287 updateNoteStatement.setLong(2, enzymeId.longValue());
1288 updateNoteStatement.execute();
1289 } finally {
1290 updateNoteStatement.close();
1291 }
1292 }
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302 public void updateStatus(Long enzymeId, Status status, Connection con) throws SQLException {
1303 PreparedStatement updateStatusStatement = null;
1304
1305 try {
1306 updateStatusStatement = con.prepareStatement(updateStatusStatement());
1307 updateStatusStatement.setString(1, status.getCode());
1308 updateStatusStatement.setLong(2, enzymeId.longValue());
1309 updateStatusStatement.execute();
1310 } finally {
1311 updateStatusStatement.close();
1312 }
1313 }
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323 public void updateHistoryLine(Long enzymeId, String historyLine, Connection con) throws SQLException {
1324 PreparedStatement updateHistoryLineStatement = null;
1325
1326 try {
1327 updateHistoryLineStatement = con.prepareStatement(updateHistoryLineStatement());
1328 updateHistoryLineStatement.setString(1, historyLine);
1329 updateHistoryLineStatement.setLong(2, enzymeId.longValue());
1330 updateHistoryLineStatement.execute();
1331 } finally {
1332 updateHistoryLineStatement.close();
1333 }
1334 }
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344 public boolean cloneExists(Long id, Connection con) throws SQLException {
1345 EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper();
1346 return futureEventsMapper.futureEventExists(id, con);
1347 }
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360 private EnzymeEntry doLoad(ResultSet rs) throws SQLException, EcException {
1361 Long enzymeId = null;
1362 int ec1 = 0;
1363 int ec2 = 0;
1364 int ec3 = 0;
1365 int ec4 = 0;
1366 String history = "";
1367 String note = "";
1368 String status = "";
1369 String source = "";
1370 String active = "";
1371 String className = "";
1372 String subclassName = "";
1373 String subSubclassName = "";
1374
1375 if (rs.getInt(1) > 0) enzymeId = new Long(rs.getLong(1));
1376 if (rs.getInt(2) > 0) ec1 = rs.getInt(2);
1377 if (rs.getInt(3) > 0) ec2 = rs.getInt(3);
1378 if (rs.getInt(4) > 0) ec3 = rs.getInt(4);
1379 if (rs.getInt(5) > 0) ec4 = rs.getInt(5);
1380 if (rs.getString(6) != null) history = rs.getString(6);
1381 if (rs.getString(7) != null) note = rs.getString(7);
1382 if (rs.getString(8) != null) status = rs.getString(8);
1383 if (rs.getString(9) != null) source = rs.getString(9);
1384 if (rs.getString(10) != null) active = rs.getString(10);
1385 if (rs.getString(11) != null) className = rs.getString(11);
1386 if (rs.getString(12) != null) subclassName = rs.getString(12);
1387 if (rs.getString(13) != null) subSubclassName = rs.getString(13);
1388
1389 EnzymeEntry enzymeEntry = new EnzymeEntry();
1390 Status st = Status.fromCode(status);
1391 enzymeEntry.setId(enzymeId);
1392 EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf(
1393 ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY));
1394 enzymeEntry.setEc(ec);
1395 enzymeEntry.getHistory().getRootNode().setHistoryLine(history);
1396 enzymeEntry.setNote(note);
1397 enzymeEntry.setStatus(st);
1398 enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source));
1399 enzymeEntry.setActive(active.charAt(0) == 'Y');
1400 enzymeEntry.setSubSubclassName(subSubclassName);
1401 enzymeEntry.setSubclassName(subclassName);
1402 enzymeEntry.setClassName(className);
1403
1404 return enzymeEntry;
1405 }
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415 private EnzymeEntry doLoadCore(ResultSet rs) throws SQLException, DomainException {
1416 Long enzymeId = null;
1417 int ec1 = 0;
1418 int ec2 = 0;
1419 int ec3 = 0;
1420 int ec4 = 0;
1421 String history = "";
1422 String note = "";
1423 String status = "";
1424 String source = "";
1425 String active = "";
1426
1427 if (rs.getInt(1) > 0) enzymeId = new Long(rs.getLong(1));
1428 if (rs.getInt(2) > 0) ec1 = rs.getInt(2);
1429 if (rs.getInt(3) > 0) ec2 = rs.getInt(3);
1430 if (rs.getInt(4) > 0) ec3 = rs.getInt(4);
1431 if (rs.getInt(5) > 0) ec4 = rs.getInt(5);
1432 if (rs.getString(6) != null) history = rs.getString(6);
1433 if (rs.getString(7) != null) note = rs.getString(7);
1434 if (rs.getString(8) != null) status = rs.getString(8);
1435 if (rs.getString(9) != null) source = rs.getString(9);
1436 if (rs.getString(10) != null) active = rs.getString(10);
1437
1438 EnzymeEntry enzymeEntry = new EnzymeEntry();
1439 enzymeEntry.setId(enzymeId);
1440 Status st = Status.fromCode(status);
1441 EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf(
1442 ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY));
1443 enzymeEntry.setEc(ec);
1444 enzymeEntry.getHistory().getRootNode().setHistoryLine(history);
1445 enzymeEntry.setNote(note);
1446 enzymeEntry.setStatus(st);
1447 enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source));
1448 enzymeEntry.setActive(active.charAt(0) == 'Y');
1449
1450 return enzymeEntry;
1451 }
1452
1453
1454
1455
1456
1457
1458
1459
1460 private void doLoadNames(EnzymeEntry entry, List<EnzymeName> names) throws DomainException {
1461 for (int iii = 0; iii < names.size(); iii++) {
1462 EnzymeName enzymeName = names.get(iii);
1463 if (enzymeName.getType().equals(EnzymeNameTypeConstant.COMMON_NAME)) {
1464 entry.addCommonName(enzymeName);
1465 }
1466 if (enzymeName.getType().equals(EnzymeNameTypeConstant.SYSTEMATIC_NAME)) {
1467 entry.setSystematicName(enzymeName);
1468 }
1469 if (enzymeName.getType().equals(EnzymeNameTypeConstant.OTHER_NAME)) {
1470 entry.addSynonym(enzymeName);
1471 }
1472 }
1473 }
1474
1475
1476
1477
1478
1479
1480
1481
1482 private EnzymeEntry doLoadGhost(ResultSet rs) throws SQLException, DomainException {
1483 Long enzymeId = null;
1484 int ec1 = 0;
1485 int ec2 = 0;
1486 int ec3 = 0;
1487 int ec4 = 0;
1488 String status = "";
1489 String source = "";
1490 String active = "";
1491 String history = "";
1492
1493 if (rs.getInt("enzyme_id") > 0) enzymeId = new Long(rs.getLong("enzyme_id"));
1494 if (rs.getInt("ec1") > 0) ec1 = rs.getInt("ec1");
1495 if (rs.getInt("ec2") > 0) ec2 = rs.getInt("ec2");
1496 if (rs.getInt("ec3") > 0) ec3 = rs.getInt("ec3");
1497 if (rs.getInt("ec4") > 0) ec4 = rs.getInt("ec4");
1498 if (rs.getString("history") != null) history = rs.getString("history");
1499 if (rs.getString("status") != null) status = rs.getString("status");
1500 if (rs.getString("source") != null) source = rs.getString("source");
1501 if (rs.getString("active") != null) active = rs.getString("active");
1502
1503 EnzymeEntry enzymeEntry = new EnzymeEntry();
1504 Status st = Status.fromCode(status);
1505 enzymeEntry.setId(enzymeId);
1506 EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf(
1507 ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY));
1508 enzymeEntry.setEc(ec);
1509 enzymeEntry.getHistory().getRootNode().setHistoryLine(history);
1510 enzymeEntry.setStatus(st);
1511 if (!source.equals("")) enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source));
1512 if (!active.equals("")) enzymeEntry.setActive(active.charAt(0) == 'Y');
1513 enzymeEntry.setGhost(true);
1514 return enzymeEntry;
1515 }
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525 private void findEnzymeData(EnzymeEntry enzymeEntry, Connection con)
1526 throws SQLException, DomainException, EnzymeReactionException,
1527 EnzymeReferenceException, MapperException {
1528 loadHistoryGraph(enzymeEntry, con);
1529
1530
1531 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
1532 List<EnzymeName> names = nameMapper.find(enzymeEntry.getId(), con);
1533 if (names != null) doLoadNames(enzymeEntry, names);
1534
1535
1536 EnzymaticReactions reactions =
1537 enzymeReactionMapper.find(enzymeEntry.getId(), con);
1538 if (reactions != null) enzymeEntry.setEnzymaticReactions(reactions);
1539
1540
1541 EnzymeCofactorMapper cofactorMapper = new EnzymeCofactorMapper();
1542 Set<Object> cofactors = cofactorMapper.find(enzymeEntry.getId(), con);
1543 cofactorMapper.close();
1544 if (cofactors != null) enzymeEntry.setCofactors(cofactors);
1545
1546
1547 EnzymeLinkMapper linkMapper = new EnzymeLinkMapper();
1548 List<EnzymeLink> links = linkMapper.find(enzymeEntry.getId(), con);
1549 if (links != null) {
1550 enzymeEntry.setLinks(new TreeSet<EnzymeLink>(links));
1551 }
1552
1553
1554 EnzymeCommentMapper commentMapper = new EnzymeCommentMapper();
1555 List<EnzymeComment> comments = commentMapper.find(enzymeEntry.getId(), con);
1556 if (comments != null) enzymeEntry.setComments(comments);
1557
1558
1559 EnzymeReferenceMapper referenceMapper = new EnzymeReferenceMapper();
1560 List<Reference> references = referenceMapper.find(enzymeEntry.getId(), con);
1561 if (references != null) enzymeEntry.setReferences(references);
1562 }
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576 private void exportSIBEnzymeData(EnzymeEntry enzymeEntry, Connection con)
1577 throws SQLException, DomainException,
1578 EnzymeReactionException, MapperException {
1579 assert enzymeEntry != null : "Parameter 'enzymeEntry' must not be null.";
1580 assert con != null : "Parameter 'con' must not be null.";
1581
1582 loadHistoryGraph(enzymeEntry, con);
1583
1584
1585 EnzymeNameMapper nameMapper = new EnzymeNameMapper();
1586 List<EnzymeName> names = nameMapper.exportSibNames(enzymeEntry.getId(), con);
1587 if (names != null) doLoadNames(enzymeEntry, names);
1588
1589
1590 EnzymaticReactions reactions =
1591 enzymeReactionMapper.exportSibReactions(enzymeEntry.getId(), con);
1592 if (reactions != null) enzymeEntry.setEnzymaticReactions(reactions);
1593
1594
1595 EnzymeCofactorMapper cofactorMapper = new EnzymeCofactorMapper();
1596 Set<Object> cofactors = cofactorMapper.exportSibCofactors(enzymeEntry.getId(), con);
1597 cofactorMapper.close();
1598 if (cofactors != null) enzymeEntry.setCofactors(cofactors);
1599
1600
1601 EnzymeLinkMapper linkMapper = new EnzymeLinkMapper();
1602 List<EnzymeLink> links = linkMapper.exportSibLinks(enzymeEntry.getId(), con);
1603 if (links != null)
1604 enzymeEntry.setLinks(new TreeSet<EnzymeLink>(links));
1605
1606
1607 EnzymeCommentMapper commentMapper = new EnzymeCommentMapper();
1608 List<EnzymeComment> comments = commentMapper.exportSibComments(enzymeEntry.getId(), con);
1609 if (comments != null) enzymeEntry.setComments(comments);
1610 }
1611
1612
1613
1614
1615
1616
1617
1618
1619 public Long findNextEnzymeId(Connection con) throws SQLException {
1620 if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
1621 long enzymeId = 0;
1622 PreparedStatement findNextEnzymeId = null;
1623
1624 try {
1625 findNextEnzymeId = con.prepareStatement(findNextEnzymeIdStatement());
1626 ResultSet rs = findNextEnzymeId.executeQuery();
1627 if (rs.next()) {
1628 enzymeId = rs.getLong(1);
1629 }
1630 } finally {
1631 findNextEnzymeId.close();
1632 }
1633
1634 return new Long(enzymeId);
1635 }
1636
1637 private void loadHistoryGraph(EnzymeEntry enzymeEntry, Connection con)
1638 throws SQLException, DomainException {
1639 HistoryGraph historyGraph = getHistoryGraph(con, enzymeEntry);
1640 if (historyGraph != null) enzymeEntry.setHistory(historyGraph);
1641 }
1642
1643 }