コード例 #1
0
  /**
   * @param accession
   * @param taxonomyId
   * @param dbConnection
   * @throws Exception
   */
  public void saveOrUpdateOnAccession(LocalCache_Swiss_prot_DTO item, Connection dbConnection)
      throws Exception {

    PreparedStatement pstmt = null;

    // CREATE TABLE local_cache_swiss_prot_data (
    //		  accession VARCHAR(255) NOT NULL,
    //		  taxonomy_id INT NULL,

    final String sql =
        "INSERT INTO local_cache_swiss_prot_data (accession, taxonomy_id)"
            + " VALUES ( ?, ? ) ON DUPLICATE KEY UPDATE taxonomy_id = ?";

    try {

      pstmt = dbConnection.prepareStatement(sql);

      int counter = 0;

      counter++;
      pstmt.setString(counter, item.getAccession());

      counter++;
      if (item.getTaxonomyId() != null) {
        pstmt.setInt(counter, item.getTaxonomyId());
      } else {
        pstmt.setNull(counter, java.sql.Types.INTEGER);
      }

      counter++;
      if (item.getTaxonomyId() != null) {
        pstmt.setInt(counter, item.getTaxonomyId());
      } else {
        pstmt.setNull(counter, java.sql.Types.INTEGER);
      }

      pstmt.executeUpdate();

    } catch (Exception e) {

      String msg = "Failed to insert LocalCache_Swiss_prot_DTO, sql: " + sql;

      log.error(msg, e);

      throw e;

    } finally {

      // be sure database handles are closed

      if (pstmt != null) {
        try {
          pstmt.close();
        } catch (Throwable t) {;
        }
        pstmt = null;
      }
    }
  }
コード例 #2
0
  /**
   * @param item
   * @throws Exception
   */
  public void updateTaxonomyId(LocalCache_Swiss_prot_DTO item) throws Exception {

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    final String sql = "UPDATE local_cache_swiss_prot_data SET taxonomy_id = ? WHERE accession = ?";

    // CREATE TABLE local_cache_swiss_prot_data (
    //		  accession VARCHAR(255) NOT NULL,
    //		  taxonomy_id INT NULL,

    try {

      conn = DBConnectionFactory.getConnection(DBConnectionFactory.NRSEQ_FASTA_IMPORTER);

      pstmt = conn.prepareStatement(sql);

      int counter = 0;

      counter++;
      if (item.getTaxonomyId() != null) {
        pstmt.setInt(counter, item.getTaxonomyId());
      } else {
        pstmt.setNull(counter, java.sql.Types.INTEGER);
      }

      counter++;
      pstmt.setString(counter, item.getAccession());

      pstmt.executeUpdate();

    } catch (Exception e) {

      String msg = "Failed to update taxonomy_id, sql: " + sql;

      log.error(msg, e);

      throw e;

    } finally {

      // be sure database handles are closed
      if (rs != null) {
        try {
          rs.close();
        } catch (Throwable t) {;
        }
        rs = null;
      }

      if (pstmt != null) {
        try {
          pstmt.close();
        } catch (Throwable t) {;
        }
        pstmt = null;
      }

      if (conn != null) {
        try {
          conn.close();
        } catch (Throwable t) {;
        }
        conn = null;
      }
    }
  }