Exemplo n.º 1
0
    /**
     * Save the given biblio record in the database. Transaction management is the caller's
     * responsibility.
     *
     * @param bibliosDAO the data to be saved
     */
    @Override
    public void save(BibliosDAO bibliosDAO) {
      java.sql.Date sqlDate = Utils.tryParseToDbDate(bibliosDAO.getLast_change());

      final String statement =
          "UPDATE biblios SET title = ?, author1 = ?, author2 = ?, year = ?, journal = ?, username = ?, "
              + "volume = ?, pages = ?, pubmed_id = ?, updated = ?, last_change = ?, notes = ?"
              + "WHERE id_biblio = ?";

      jdbcTemplate.update(
          statement,
          new Object[] {
            bibliosDAO.getTitle(),
            bibliosDAO.getAuthor1(),
            bibliosDAO.getAuthor2(),
            bibliosDAO.getYear(),
            bibliosDAO.getJournal(),
            bibliosDAO.getUsername(),
            bibliosDAO.getVolume(),
            bibliosDAO.getPages(),
            bibliosDAO.getPubmed_id(),
            bibliosDAO.getUpdated(),
            sqlDate,
            bibliosDAO.getNotes(),
            bibliosDAO.getId_biblio()
          });
    }
Exemplo n.º 2
0
  /**
   * This method replaces any null <code>BibliosDAO</code> fields with the string '&lt;null&gt;' so
   * that proper length computations and display can be performed against null fields. A throw-away
   * copy of the biblio is returned and may be used for field length computations and display
   * without fear of null pointer exceptions.
   *
   * @param biblio the biblio record to be patched
   * @return a new <code>BibliosDAO</code> instance with any null fields replaced by the string
   *     '&lt;null&gt;'
   */
  private BibliosDAO patchNullFields(BibliosDAO biblio) {
    BibliosDAO newBiblio = new BibliosDAO();

    newBiblio.setId_biblio(biblio.getId_biblio());
    newBiblio.setPubmed_id(biblio.getPubmed_id() == null ? "<null>" : biblio.getPubmed_id());
    newBiblio.setYear(biblio.getYear() == null ? "<null>" : biblio.getYear());
    newBiblio.setJournal(biblio.getJournal() == null ? "<null>" : biblio.getJournal());
    newBiblio.setVolume(biblio.getVolume() == null ? "<null>" : biblio.getVolume());
    newBiblio.setPages(biblio.getPages() == null ? "<null>" : biblio.getPages());
    newBiblio.setUsername(biblio.getUsername() == null ? "<null>" : biblio.getUsername());
    newBiblio.setUpdated(biblio.getUpdated() == null ? "<null>" : biblio.getUpdated());
    newBiblio.setLast_change(biblio.getLast_change() == null ? "<null>" : biblio.getLast_change());
    newBiblio.setTitle(biblio.getTitle() == null ? "<null>" : biblio.getTitle());
    newBiblio.setAuthor1(biblio.getAuthor1() == null ? "<null>" : biblio.getAuthor1());
    newBiblio.setAuthor2(biblio.getAuthor2() == null ? "<null>" : biblio.getAuthor2());

    return newBiblio;
  }
Exemplo n.º 3
0
  /**
   * This method computes the maximum field widths for all logged fields. It is needed for proper
   * logfile formatting output for correctly aligning the old and new <code>BibliosDAO</code>
   * records.
   *
   * @param oldBiblio the old [existing] biblio record
   * @param newBiblio the new biblio record
   * @param allowForQuotes If true, two extra bytes are added to each required field length to
   *     account for leading and trailing quotation marks.
   */
  private void accumulateMaxWidths(BibliosDAO oldBiblio, BibliosDAO newBiblio) {
    String sId_biblio = Integer.toString(oldBiblio.getId_biblio());

    // Add two bytes to each biblio field (old and new) to account for leading and trailing quotes.
    maxWidths[0] = Math.max(Math.max(sId_biblio.length(), heading1[0].length()), maxWidths[0]);
    maxWidths[1] =
        Math.max(
            Math.max(
                Math.max(
                    oldBiblio.getPubmed_id().length() + 2, newBiblio.getPubmed_id().length() + 2),
                heading1[1].length()),
            maxWidths[1]);
    maxWidths[2] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getYear().length() + 2, newBiblio.getYear().length() + 2),
                heading1[2].length()),
            maxWidths[2]);
    maxWidths[3] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getJournal().length() + 2, newBiblio.getJournal().length() + 2),
                heading1[3].length()),
            maxWidths[3]);
    maxWidths[4] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getVolume().length() + 2, newBiblio.getVolume().length() + 2),
                heading1[4].length()),
            maxWidths[4]);
    maxWidths[5] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getPages().length() + 2, newBiblio.getPages().length() + 2),
                heading1[5].length()),
            maxWidths[5]);
    maxWidths[6] =
        Math.max(
            Math.max(
                Math.max(
                    oldBiblio.getUsername().length() + 2, newBiblio.getUsername().length() + 2),
                heading1[6].length()),
            maxWidths[6]);
    maxWidths[7] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getUpdated().length() + 2, newBiblio.getUpdated().length() + 2),
                heading1[7].length()),
            maxWidths[7]);
    maxWidths[8] =
        Math.max(
            Math.max(
                Math.max(
                    oldBiblio.getLast_change().length() + 2,
                    newBiblio.getLast_change().length() + 2),
                heading1[8].length()),
            maxWidths[8]);
    maxWidths[9] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getTitle().length() + 2, newBiblio.getTitle().length()),
                heading1[9].length() + 2),
            maxWidths[9]);
    maxWidths[10] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getAuthor1().length() + 2, newBiblio.getAuthor1().length()),
                heading1[10].length() + 2),
            maxWidths[10]);
    maxWidths[11] =
        Math.max(
            Math.max(
                Math.max(oldBiblio.getAuthor2().length() + 2, newBiblio.getAuthor2().length()),
                heading1[11].length() + 2),
            maxWidths[11]);
  }