Coverage Report - uk.ac.ebi.intenz.mapper.EnzymeReferenceMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
EnzymeReferenceMapper
52%
173/330
31%
79/252
4.189
 
 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.util.ArrayList;
 8  
 import java.util.List;
 9  
 
 10  
 import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
 11  
 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
 12  
 import uk.ac.ebi.intenz.domain.constants.Status;
 13  
 import uk.ac.ebi.intenz.domain.reference.Book;
 14  
 import uk.ac.ebi.intenz.domain.reference.Journal;
 15  
 import uk.ac.ebi.intenz.domain.reference.Patent;
 16  
 import uk.ac.ebi.intenz.domain.reference.Reference;
 17  
 
 18  
 /**
 19  
  * Maps reference information to the corresponding database tables.
 20  
  *
 21  
  * @author Michael Darsow
 22  
  * @version $Revision: 1.3 $ $Date: 2009/05/26 14:59:09 $
 23  
  */
 24  1
 public class EnzymeReferenceMapper {
 25  
 
 26  
   private static final String COLUMNS = "p.pub_id, p.medline_id, p.pubmed_id, p.pub_type, p.author, " +
 27  
                                         "p.pub_year, p.title, p.journal_book, p.volume, p.first_page, p.last_page, " +
 28  
                                         "p.edition, p.editor, p.pub_company, p.pub_place, p.web_view, p.source";
 29  
 
 30  
 //  private static final Logger LOGGER = Logger.getLogger(EnzymeReferenceMapper.class);
 31  
 
 32  2
   public EnzymeReferenceMapper() {
 33  2
   }
 34  
 
 35  
   private String findStatement() {
 36  2
     return "SELECT " + COLUMNS +
 37  
            " FROM citations c, publications p" +
 38  
            " WHERE c.enzyme_id = ? AND c.pub_id = p.pub_id ORDER BY c.order_in";
 39  
   }
 40  
 
 41  
   private String findPubIdsStatement() {
 42  2
     return "SELECT pub_id FROM citations WHERE enzyme_id = ?";
 43  
   }
 44  
 
 45  
   private String findNextPubIdStatement() {
 46  0
     return "SELECT s_pub_id.nextval FROM DUAL";
 47  
   }
 48  
 
 49  
   private String findNextOrderInStatement() {
 50  1
     return "SELECT MAX(order_in) FROM citations WHERE enzyme_id = ?";
 51  
   }
 52  
 
 53  
   private String insertJournalStatement() {
 54  1
     return "INSERT INTO publications " +
 55  
            "(pub_id, medline_id, pubmed_id, pub_type, author, pub_year, title, journal_book, volume, first_page, last_page, web_view, source) " +
 56  
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 57  
   }
 58  
 
 59  
   private String updateJournalStatement() {
 60  0
     return "UPDATE publications " +
 61  
            "SET medline_id = ?, pubmed_id = ?, pub_type = ?, author = ?, pub_year = ?, title = ?, journal_book = ?, " +
 62  
            "volume = ?, first_page = ?, last_page = ?, web_view = ?, source = ? " +
 63  
            "WHERE pub_id = ?";
 64  
   }
 65  
 
 66  
   private String insertBookStatement() {
 67  1
     return "INSERT INTO publications " +
 68  
            "(pub_id, pub_type, author, pub_year, title, journal_book, volume, first_page, last_page, edition, editor, pub_company, pub_place, web_view, source) " +
 69  
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 70  
   }
 71  
 
 72  
   private String updateBookStatement() {
 73  0
     return "UPDATE publications " +
 74  
            "SET pub_type = ?, author = ?, pub_year = ?, title = ?, journal_book = ?, volume = ?, first_page = ?, " +
 75  
            "last_page = ?, edition = ?, editor = ?, pub_company = ?, pub_place = ?, web_view = ?, source = ? " +
 76  
            "WHERE pub_id = ?";
 77  
   }
 78  
 
 79  
   private String insertPatentStatement() {
 80  1
     return "INSERT INTO publications " +
 81  
            "(pub_id, pub_type, author, pub_year, title, journal_book, web_view, source) " +
 82  
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
 83  
   }
 84  
 
 85  
   private String updatePatentStatement() {
 86  0
     return "UPDATE publications " +
 87  
            "SET pub_type = ?, author = ?, pub_year = ?, title = ?, journal_book = ?, web_view = ?, source = ? " +
 88  
            "WHERE pub_id = ?";
 89  
   }
 90  
 
 91  
   private String insertCitationStatement() {
 92  1
     return "INSERT INTO citations (enzyme_id, pub_id, order_in, status, source) VALUES (?, ?, ?, ?, ?)";
 93  
   }
 94  
 
 95  
   private String deleteCitationStatement() {
 96  1
     return "DELETE citations WHERE enzyme_id = ? AND order_in = ?";
 97  
   }
 98  
 
 99  
   private String deletePublicationStatement() {
 100  3
     return "DELETE publications WHERE pub_id = ?";
 101  
   }
 102  
 
 103  
   private String deleteCitationsStatement() {
 104  2
     return "DELETE citations WHERE enzyme_id = ?";
 105  
   }
 106  
 
 107  
   private String deleteCitationByPubIdStatement() {
 108  0
     return "DELETE citations WHERE enzyme_id = ? AND pub_id = ?";
 109  
   }
 110  
 
 111  
   /**
 112  
    * Tries to find comment information about an enzyme.
 113  
    *
 114  
    * @param enzymeId Enzyme ID of entry.
 115  
    * @param con      The logical connection.
 116  
    * @return a <code>Vector</code> containing <code>Reference</code>instances or <code>null</code> if nothing has been found.
 117  
    * @throws SQLException
 118  
    */
 119  
   public List<Reference> find(Long enzymeId, Connection con) throws SQLException {
 120  2
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 121  2
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 122  
 
 123  2
     PreparedStatement findStatement = null;
 124  2
     ResultSet rs = null;
 125  2
     List<Reference> result = new ArrayList<Reference>();
 126  2
     boolean noResult = true;
 127  
     try {
 128  
       // Core information.
 129  2
       findStatement = con.prepareStatement(findStatement());
 130  2
       findStatement.setLong(1, enzymeId.longValue());
 131  2
       rs = findStatement.executeQuery();
 132  8
       while (rs.next()) {
 133  6
         noResult = false;
 134  6
         Reference reference = doLoad(rs);
 135  6
         if (reference == null) continue;
 136  6
         result.add(reference);
 137  6
       }
 138  
     } finally {
 139  2
             if (rs != null) rs.close();
 140  2
       if (findStatement != null) findStatement.close();
 141  
     }
 142  
 
 143  2
     if (noResult) return null;
 144  2
     return result;
 145  
   }
 146  
 
 147  
   public List<Long> findPubIds(Long enzymeId, Connection con) throws SQLException {
 148  2
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 149  2
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 150  
 
 151  2
     PreparedStatement findPubIdsStatement = null;
 152  2
     ResultSet rs = null;
 153  2
     List<Long> result = new ArrayList<Long>();
 154  
     try {
 155  
       // Core information.
 156  2
       findPubIdsStatement = con.prepareStatement(findPubIdsStatement());
 157  2
       findPubIdsStatement.setLong(1, enzymeId.longValue());
 158  2
       rs = findPubIdsStatement.executeQuery();
 159  4
       while (rs.next()) {
 160  2
         result.add(new Long(rs.getLong(1)));
 161  
       }
 162  
     } finally {
 163  2
             if (rs != null) rs.close();
 164  2
       if (findPubIdsStatement != null) findPubIdsStatement.close();
 165  
     }
 166  
 
 167  2
     return result;
 168  
   }
 169  
 
 170  
   public void insert(Reference reference, Long enzymeId, Status status, Connection con) throws SQLException {
 171  1
     if (reference == null) throw new NullPointerException("Parameter 'reference' must not be null.");
 172  1
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 173  1
     if (status == null) throw new NullPointerException("Parameter 'status' must not be null.");
 174  1
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 175  
 
 176  1
     PreparedStatement insertJournalStatement = null, insertBookStatement = null,
 177  1
                     insertPatentStatement = null, insertCitationStatement = null,
 178  1
                     deleteCitationStatement = null;
 179  
 
 180  
     try {
 181  1
       insertCitationStatement = con.prepareStatement(insertCitationStatement());
 182  1
       deleteCitationStatement = con.prepareStatement(deleteCitationStatement());
 183  1
       insertJournalStatement = con.prepareStatement(insertJournalStatement());
 184  1
       insertBookStatement = con.prepareStatement(insertBookStatement());
 185  1
       insertPatentStatement = con.prepareStatement(insertPatentStatement());
 186  1
       int orderIn = findNextOrderIn(enzymeId, con);
 187  
 
 188  1
       Long oldPubId = reference.getPubId();
 189  
       // Give it a new Id only when it has none yet:
 190  1
       Long newPubId = (oldPubId == null)? findNextPubId(con) : oldPubId;
 191  
 
 192  1
       doInsertCitation(enzymeId, newPubId, orderIn, status, reference.getSource(), insertCitationStatement);
 193  1
       insertCitationStatement.execute();
 194  
 //      con.commit();
 195  1
       orderIn++;
 196  
 
 197  1
       if (reference instanceof Journal) {
 198  1
         Journal journal = (Journal) reference;
 199  1
         doInsertJournal(newPubId, journal, insertJournalStatement);
 200  1
         insertJournalStatement.execute();
 201  
 //        con.commit();
 202  
       }
 203  1
       if (reference instanceof Book) {
 204  0
         Book book = (Book) reference;
 205  0
         doInsertBook(newPubId, book, insertBookStatement);
 206  0
         insertBookStatement.execute();
 207  
 //        con.commit();
 208  
       }
 209  1
       if (reference instanceof Patent) {
 210  0
         Patent patent = (Patent) reference;
 211  0
         doInsertPatent(newPubId, patent, insertPatentStatement);
 212  0
         insertPatentStatement.execute();
 213  
 //        con.commit();
 214  
       }
 215  
 //    } catch (SQLException e) {
 216  
 //      con.rollback();
 217  
 //      throw e;
 218  
     } finally {
 219  1
       if (insertJournalStatement != null) insertJournalStatement.close();
 220  1
       if (insertBookStatement != null) insertBookStatement.close();
 221  1
       if (insertPatentStatement != null) insertPatentStatement.close();
 222  1
       if (insertCitationStatement != null) insertCitationStatement.close();
 223  1
       if (deleteCitationStatement != null) deleteCitationStatement.close();
 224  
     }
 225  1
   }
 226  
 
 227  
   /**
 228  
    * Stores the given list of references into the database.
 229  
    *
 230  
    * @param references The enzyme's references.
 231  
    * @param enzymeId   The enzyme ID.
 232  
    * @param status     ...
 233  
    * @param con        ...
 234  
    * @throws SQLException
 235  
    */
 236  
   public void insert(List<Reference> references, Long enzymeId, Status status, Connection con)
 237  
   throws SQLException {
 238  0
     if (references == null) throw new NullPointerException("Parameter 'references' must not be null.");
 239  0
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 240  0
     if (status == null) throw new NullPointerException("Parameter 'status' must not be null.");
 241  0
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 242  
 
 243  0
     for (int iii = 0; iii < references.size(); iii++) {
 244  0
       Reference reference = references.get(iii);
 245  0
       insert(reference, enzymeId, status, con);
 246  
     }
 247  0
   }
 248  
 
 249  
   public void reload(List<Reference> references, Long enzymeId, Status status, Connection con)
 250  
   throws SQLException {
 251  0
     deleteAll(enzymeId, con);
 252  0
     insert(references, enzymeId, status, con);
 253  0
   }
 254  
 
 255  
   public void update(Reference reference, Long enzymeId, Status status, Connection con) throws SQLException {
 256  0
     if (reference == null) throw new NullPointerException("Parameter 'reference' must not be null.");
 257  0
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 258  0
     if (status == null) throw new NullPointerException("Parameter 'status' must not be null.");
 259  0
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 260  
 
 261  0
     PreparedStatement updateJournalStatement = null, updateBookStatement = null,
 262  0
                     updatePatentStatement = null;
 263  
     try {
 264  0
       updateJournalStatement = con.prepareStatement(updateJournalStatement());
 265  0
       updateBookStatement = con.prepareStatement(updateBookStatement());
 266  0
       updatePatentStatement = con.prepareStatement(updatePatentStatement());
 267  
 
 268  0
       if (reference instanceof Journal) {
 269  0
         Journal journal = (Journal) reference;
 270  0
         doUpdateJournal(journal, updateJournalStatement);
 271  0
         updateJournalStatement.execute();
 272  
 //        con.commit();
 273  
       }
 274  0
       if (reference instanceof Book) {
 275  0
         Book book = (Book) reference;
 276  0
         doUpdateBook(book, updateBookStatement);
 277  0
         updateBookStatement.execute();
 278  
 //        con.commit();
 279  
       }
 280  0
       if (reference instanceof Patent) {
 281  0
         Patent patent = (Patent) reference;
 282  0
         doUpdatePatent(patent, updatePatentStatement);
 283  0
         updatePatentStatement.execute();
 284  
 //        con.commit();
 285  
       }
 286  
 //    } catch (SQLException e) {
 287  
 //      con.rollback();
 288  
 //      throw e;
 289  
     } finally {
 290  0
       if (updateJournalStatement != null) updateJournalStatement.close();
 291  0
       if (updateBookStatement != null) updateBookStatement.close();
 292  0
       if (updatePatentStatement != null) updatePatentStatement.close();
 293  
     }
 294  0
   }
 295  
 
 296  
   public void update(List<Reference> references, Long enzymeId, Status status, Connection con)
 297  
   throws SQLException {
 298  0
     if (references == null) throw new NullPointerException("Parameter 'references' must not be null.");
 299  0
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 300  0
     if (status == null) throw new NullPointerException("Parameter 'status' must not be null.");
 301  0
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 302  
 
 303  0
     for (int iii = 0; iii < references.size(); iii++) {
 304  0
       Reference reference = references.get(iii);
 305  0
       update(reference, enzymeId, status, con);
 306  
     }
 307  0
   }
 308  
 
 309  
   public void deleteAll(Long enzymeId, Connection con) throws SQLException {
 310  2
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 311  2
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 312  
 
 313  
     // Only delete publications, which will be inserted afterwards (deletion of references only requires the deletion
 314  
     // of the citation).
 315  2
     List<Long> pubIds = findPubIds(enzymeId, con);
 316  4
     for (int iii = 0; iii < pubIds.size(); iii++) {
 317  2
       deletePublication(pubIds.get(iii), con);
 318  
     }
 319  2
     deleteCitations(enzymeId, con);
 320  2
   }
 321  
 
 322  
   public void deleteCitations(Long enzymeId, Connection con) throws SQLException {
 323  2
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 324  2
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 325  
 
 326  2
     PreparedStatement deleteCitationsStatement = null;
 327  
     try {
 328  2
       deleteCitationsStatement = con.prepareStatement(deleteCitationsStatement());
 329  2
       deleteCitationsStatement.setLong(1, enzymeId.longValue());
 330  2
       deleteCitationsStatement.execute();
 331  
 //      con.commit();
 332  
 //    } catch (SQLException e) {
 333  
 //      con.rollback();
 334  
 //      throw e;
 335  
     } finally {
 336  2
       if (deleteCitationsStatement != null) deleteCitationsStatement.close();
 337  
     }
 338  2
   }
 339  
 
 340  
   /**
 341  
    * Deletes enzyme relations to publications (internally called citations).
 342  
    *
 343  
    * @param pubIds   The pub ID of the relation to be deleted.
 344  
    * @param enzymeId The enzyme ID.
 345  
    * @param con      Database connection.
 346  
    * @throws SQLException             if any database error occurred.
 347  
    * @throws NullPointerException     if any of the parameters is <code>null</code>.
 348  
    * @throws IllegalArgumentException if <code>enzymeId</code> < 1.
 349  
    */
 350  
   public void deleteCitations(List<Long> pubIds, Long enzymeId, Connection con) throws SQLException {
 351  0
     if (pubIds == null) throw new NullPointerException("Parameter 'pubIds' must not be null.");
 352  0
     if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null.");
 353  0
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 354  
 
 355  0
     PreparedStatement deleteCitationStatement = null;
 356  
     try {
 357  0
       for (int iii = 0; iii < pubIds.size(); iii++) {
 358  0
         Long pubId = pubIds.get(iii);
 359  0
         deleteCitationStatement = con.prepareStatement(deleteCitationByPubIdStatement());
 360  0
         deleteCitationStatement.setLong(1, enzymeId.longValue());
 361  0
         deleteCitationStatement.setLong(2, pubId.longValue());
 362  0
         deleteCitationStatement.execute();
 363  
       }
 364  
 //      con.commit();
 365  
 //    } catch (SQLException e) {
 366  
 //      con.rollback();
 367  
 //      throw e;
 368  
     } finally {
 369  0
       if (deleteCitationStatement != null) deleteCitationStatement.close();
 370  
     }
 371  0
   }
 372  
 
 373  
   public void deletePublication(Long pubId, Connection con) throws SQLException {
 374  3
     if (pubId == null) throw new NullPointerException("Parameter 'pubId' must not be null.");
 375  3
     if (con == null) throw new NullPointerException("Parameter 'con' must not be null.");
 376  
 
 377  3
     PreparedStatement deletePublicationStatement = null;
 378  
     try {
 379  3
       deletePublicationStatement = con.prepareStatement(deletePublicationStatement());
 380  3
       deletePublicationStatement.setLong(1, pubId.longValue());
 381  3
       deletePublicationStatement.execute();
 382  
 //      con.commit();
 383  
 //    } catch (SQLException e) {
 384  
 //      con.rollback();
 385  
 //      throw e;
 386  
     } finally {
 387  3
       if (deletePublicationStatement != null) deletePublicationStatement.close();
 388  
     }
 389  3
   }
 390  
 
 391  
 
 392  
   // ------------------- PRIVATE METHODS ------------------------
 393  
 
 394  
   /**
 395  
    * Creates the <code>Reference</code> object from the given result set.
 396  
    *
 397  
    * @param rs The result set object.
 398  
    * @return an <code>Reference</code> instance.
 399  
    * @throws SQLException
 400  
    */
 401  
   private Reference doLoad(ResultSet rs) throws SQLException {
 402  6
     assert rs != null : "Parameter 'rs' must not be null.";
 403  
 
 404  6
     Long pubId = null;
 405  6
     String medlineId = "";
 406  6
     String pubMedId = "";
 407  6
     String pubType = "";
 408  6
     String authors = "";
 409  6
     String pubYear = "";
 410  6
     String title = "";
 411  6
     String pubName = "";
 412  6
     String volume = "";
 413  6
     String firstPage = "";
 414  6
     String lastPage = "";
 415  6
     String edition = "";
 416  6
     String editor = "";
 417  6
     String publisher = "";
 418  6
     String pubPlace = "";
 419  6
     String webView = "";
 420  6
     String source = "";
 421  
 
 422  6
     if (rs.getLong("pub_id") > 0) pubId = new Long(rs.getLong("pub_id"));
 423  6
     if (rs.getString("medline_id") != null) medlineId = rs.getString("medline_id");
 424  6
     if (rs.getString("pubmed_id") != null) pubMedId = rs.getString("pubmed_id");
 425  6
     if (rs.getString("pub_type") != null) pubType = rs.getString("pub_type");
 426  6
     if (rs.getString("author") != null) authors = rs.getString("author");
 427  6
     if (rs.getString("pub_year") != null) pubYear = rs.getString("pub_year");
 428  6
     if (rs.getString("title") != null) title = rs.getString("title");
 429  6
     if (rs.getString("journal_book") != null) pubName = rs.getString("journal_book");
 430  6
     if (rs.getString("volume") != null) volume = rs.getString("volume");
 431  6
     if (rs.getString("first_page") != null) firstPage = rs.getString("first_page");
 432  6
     if (rs.getString("last_page") != null) lastPage = rs.getString("last_page");
 433  6
     if (rs.getString("edition") != null) edition = rs.getString("edition");
 434  6
     if (rs.getString("editor") != null) editor = rs.getString("editor");
 435  6
     if (rs.getString("pub_company") != null) publisher = rs.getString("pub_company");
 436  6
     if (rs.getString("pub_place") != null) pubPlace = rs.getString("pub_place");
 437  6
     if (rs.getString("web_view") != null) webView = rs.getString("web_view");
 438  6
     if (rs.getString("source") != null) source = rs.getString("source");
 439  
 
 440  6
     if (pubType.equals("B"))
 441  2
       return new Book(pubId, authors, title, pubYear, firstPage, lastPage, pubName,
 442  
                       edition, editor, volume, publisher, pubPlace, EnzymeViewConstant.valueOf(webView),
 443  
                       EnzymeSourceConstant.valueOf(source));
 444  
 
 445  4
     if (pubType.equals("J"))
 446  4
       return new Journal(pubId, authors, title, pubYear, pubName, firstPage, lastPage, volume, pubMedId, medlineId,
 447  
                          EnzymeViewConstant.valueOf(webView), EnzymeSourceConstant.valueOf(source));
 448  
 
 449  0
     if (pubType.equals("P"))
 450  0
       return new Patent(pubId, authors, title, pubYear, pubName, EnzymeViewConstant.valueOf(webView),
 451  
                         EnzymeSourceConstant.valueOf(source)); // the patent number is currently stored in the journal_book column.
 452  
 
 453  0
     return null;
 454  
   }
 455  
 
 456  
   /**
 457  
    * Returns the next available pub ID.
 458  
    *
 459  
    * @param con The connection.
 460  
    * @return The next pub ID.
 461  
    * @throws SQLException
 462  
    */
 463  
   private Long findNextPubId(Connection con) throws SQLException {
 464  0
     assert con != null : "Parameter 'con' must not be null.";
 465  
 
 466  0
     Long pubId = null;
 467  0
     PreparedStatement findNextPubId = null;
 468  0
     ResultSet rs = null;
 469  
     try {
 470  0
       findNextPubId = con.prepareStatement(findNextPubIdStatement());
 471  0
       rs = findNextPubId.executeQuery();
 472  0
       if (rs.next()) {
 473  0
         pubId = new Long(rs.getLong(1));
 474  
       }
 475  
     } finally {
 476  0
             if (rs != null) rs.close();
 477  0
       if (findNextPubId != null) findNextPubId.close();
 478  
     }
 479  
 
 480  0
     return pubId;
 481  
   }
 482  
 
 483  
   private int findNextOrderIn(Long enzymeId, Connection con) throws SQLException {
 484  1
     assert enzymeId != null : "Parameter 'enzymeId' must not be null.";
 485  1
     assert con != null : "Parameter 'con' must not be null.";
 486  
 
 487  1
     int orderIn = 0;
 488  1
     PreparedStatement findNextOrderIn = null;
 489  1
     ResultSet rs = null;
 490  
     try {
 491  1
       findNextOrderIn = con.prepareStatement(findNextOrderInStatement());
 492  1
       findNextOrderIn.setLong(1, enzymeId.longValue());
 493  1
       rs = findNextOrderIn.executeQuery();
 494  1
       if (rs.next()) {
 495  1
         orderIn = rs.getInt(1);
 496  
       }
 497  
     } finally {
 498  1
             if (rs != null) rs.close();
 499  1
       if (findNextOrderIn != null) findNextOrderIn.close();
 500  
     }
 501  
 
 502  1
     return ++orderIn;
 503  
   }
 504  
 
 505  
   /**
 506  
    * Sets the citation's prepared statement parameters.
 507  
    *
 508  
    * @param enzymeId                ...
 509  
    * @param pubId                   ...
 510  
    * @param orderIn                 ...
 511  
    * @param status                  ...
 512  
    * @param source                  ...
 513  
    * @param insertCitationStatement ...
 514  
    * @throws SQLException
 515  
    */
 516  
   private void doInsertCitation(Long enzymeId, Long pubId, int orderIn, Status status, EnzymeSourceConstant source,
 517  
                                 PreparedStatement insertCitationStatement) throws SQLException {
 518  1
     insertCitationStatement.setLong(1, enzymeId.longValue());
 519  1
     insertCitationStatement.setLong(2, pubId.longValue());
 520  1
     insertCitationStatement.setInt(3, orderIn);
 521  1
     insertCitationStatement.setString(4, status.getCode());
 522  1
     insertCitationStatement.setString(5, source.toString());
 523  1
   }
 524  
 
 525  
   private void doInsertJournal(Long newPubId, Journal journal, PreparedStatement insertJournalStatement) throws SQLException {
 526  1
     assert newPubId != null : "Parameter 'newPubId' must not be null.";
 527  1
     assert journal != null : "Parameter 'journal' must not be null.";
 528  1
     assert insertJournalStatement != null : "Parameter 'insertJournalStatement' must not be null.";
 529  
 
 530  1
     insertJournalStatement.setLong(1, newPubId.longValue());
 531  1
     insertJournalStatement.setString(2, journal.getMedlineId());
 532  1
     insertJournalStatement.setString(3, journal.getPubMedId());
 533  1
     insertJournalStatement.setString(4, "J");
 534  1
     insertJournalStatement.setString(5, journal.getAuthors());
 535  1
     insertJournalStatement.setString(6, journal.getYear());
 536  1
     insertJournalStatement.setString(7, journal.getTitle());
 537  1
     insertJournalStatement.setString(8, journal.getPubName());
 538  1
     insertJournalStatement.setString(9, journal.getVolume());
 539  1
     insertJournalStatement.setString(10, journal.getFirstPage());
 540  1
     insertJournalStatement.setString(11, journal.getLastPage());
 541  1
     insertJournalStatement.setString(12, journal.getView().toString());
 542  1
     insertJournalStatement.setString(13, journal.getSource().toString());
 543  1
   }
 544  
 
 545  
   private void doUpdateJournal(Journal journal, PreparedStatement updateJournalStatement) throws SQLException {
 546  0
     assert journal != null : "Parameter 'journal' must not be null.";
 547  0
     assert updateJournalStatement != null : "Parameter 'updateJournalStatement' must not be null.";
 548  
 
 549  0
     updateJournalStatement.setString(1, journal.getMedlineId());
 550  0
     updateJournalStatement.setString(2, journal.getPubMedId());
 551  0
     updateJournalStatement.setString(3, "J");
 552  0
     updateJournalStatement.setString(4, journal.getAuthors());
 553  0
     updateJournalStatement.setString(5, journal.getYear());
 554  0
     updateJournalStatement.setString(6, journal.getTitle());
 555  0
     updateJournalStatement.setString(7, journal.getPubName());
 556  0
     updateJournalStatement.setString(8, journal.getVolume());
 557  0
     updateJournalStatement.setString(9, journal.getFirstPage());
 558  0
     updateJournalStatement.setString(10, journal.getLastPage());
 559  0
     updateJournalStatement.setLong(11, journal.getPubId().longValue());
 560  0
     updateJournalStatement.setString(12, journal.getView().toString());
 561  0
     updateJournalStatement.setString(13, journal.getSource().toString());
 562  0
   }
 563  
 
 564  
   private void doInsertBook(Long newPubId, Book book, PreparedStatement insertBookStatement) throws SQLException {
 565  0
     assert newPubId != null : "Parameter 'newPubId' must not be null.";
 566  0
     assert book != null : "Parameter 'book' must not be null.";
 567  0
     assert insertBookStatement != null : "Parameter 'insertBookStatement' must not be null.";
 568  
 
 569  0
     insertBookStatement.setLong(1, newPubId.longValue());
 570  0
     insertBookStatement.setString(2, "B");
 571  0
     insertBookStatement.setString(3, book.getAuthors());
 572  0
     insertBookStatement.setString(4, book.getYear());
 573  0
     insertBookStatement.setString(5, book.getTitle());
 574  0
     insertBookStatement.setString(6, book.getPubName());
 575  0
     insertBookStatement.setString(7, book.getVolume());
 576  0
     insertBookStatement.setString(8, book.getFirstPage());
 577  0
     insertBookStatement.setString(9, book.getLastPage());
 578  0
     insertBookStatement.setString(10, book.getEdition(false));
 579  0
     insertBookStatement.setString(11, book.getEditor(false));
 580  0
     insertBookStatement.setString(12, book.getPublisher());
 581  0
     insertBookStatement.setString(13, book.getPublisherPlace());
 582  0
     insertBookStatement.setString(14, book.getView().toString());
 583  0
     insertBookStatement.setString(15, book.getSource().toString());
 584  0
   }
 585  
 
 586  
   private void doUpdateBook(Book book, PreparedStatement updateBookStatement) throws SQLException {
 587  0
     assert book != null : "Parameter 'book' must not be null.";
 588  0
     assert updateBookStatement != null : "Parameter 'updateBookStatement' must not be null.";
 589  
 
 590  0
     updateBookStatement.setString(1, "B");
 591  0
     updateBookStatement.setString(2, book.getAuthors());
 592  0
     updateBookStatement.setString(3, book.getYear());
 593  0
     updateBookStatement.setString(4, book.getTitle());
 594  0
     updateBookStatement.setString(5, book.getPubName());
 595  0
     updateBookStatement.setString(6, book.getVolume());
 596  0
     updateBookStatement.setString(7, book.getFirstPage());
 597  0
     updateBookStatement.setString(8, book.getLastPage());
 598  0
     updateBookStatement.setString(9, book.getEdition(false));
 599  0
     updateBookStatement.setString(10, book.getEditor(false));
 600  0
     updateBookStatement.setString(11, book.getPublisher());
 601  0
     updateBookStatement.setString(12, book.getPublisherPlace());
 602  0
     updateBookStatement.setLong(13, book.getPubId().longValue());
 603  0
     updateBookStatement.setString(14, book.getView().toString());
 604  0
     updateBookStatement.setString(15, book.getSource().toString());
 605  0
   }
 606  
 
 607  
   private void doInsertPatent(Long newPubId, Patent patent, PreparedStatement insertPatentStatement) throws SQLException {
 608  0
     assert newPubId != null : "Parameter 'newPubId' must not be null.";
 609  0
     assert patent != null : "Parameter 'patent' must not be null.";
 610  0
     assert insertPatentStatement != null : "Parameter 'insertPatentStatement' must not be null.";
 611  
 
 612  0
     insertPatentStatement.setLong(1, newPubId.longValue());
 613  0
     insertPatentStatement.setString(2, "P");
 614  0
     insertPatentStatement.setString(3, patent.getAuthors());
 615  0
     insertPatentStatement.setString(4, patent.getYear());
 616  0
     insertPatentStatement.setString(5, patent.getTitle());
 617  0
     insertPatentStatement.setString(6, patent.getPatentNumber());
 618  0
     insertPatentStatement.setString(7, patent.getView().toString());
 619  0
     insertPatentStatement.setString(8, patent.getSource().toString());
 620  0
   }
 621  
 
 622  
   private void doUpdatePatent(Patent patent, PreparedStatement updatePatentStatement) throws SQLException {
 623  0
     assert patent != null : "Parameter 'patent' must not be null.";
 624  0
     assert updatePatentStatement != null : "Parameter 'updatePatentStatement' must not be null.";
 625  
 
 626  0
     updatePatentStatement.setString(1, "P");
 627  0
     updatePatentStatement.setString(2, patent.getAuthors());
 628  0
     updatePatentStatement.setString(3, patent.getYear());
 629  0
     updatePatentStatement.setString(4, patent.getTitle());
 630  0
     updatePatentStatement.setString(5, patent.getPatentNumber());
 631  0
     updatePatentStatement.setLong(6, patent.getPubId().longValue());
 632  0
     updatePatentStatement.setString(7, patent.getView().toString());
 633  0
     updatePatentStatement.setString(8, patent.getSource().toString());
 634  0
   }
 635  
 
 636  
 }