private String addNewInteraction(String fingerprint, BiologicalInteraction interaction)
     throws SQLException {
   String sql =
       String.format(
           "INSERT IGNORE INTO interaction (fingerprint) VALUES (%s)",
           SqlUtil.toSqlVarchar(fingerprint));
   if (1 != DBUtil.update(sql)) {
     System.out.println("SQL update failed? " + sql);
   }
   String interaction_id = DBUtil.querySingle("SELECT LAST_INSERT_ID()");
   Iterator<BiologicalEntity> iter = interaction.getEntityIterator();
   StringBuffer sb =
       new StringBuffer(
           "INSERT IGNORE INTO interaction_pool (interaction_id, gene_id, entity_src_table, role) VALUES ");
   while (iter.hasNext()) {
     BiologicalEntity entity = iter.next();
     sb.append("(")
         .append(interaction_id)
         .append(", ")
         .append(SqlUtil.toSqlVarchar(entity.getId()))
         .append(", '")
         .append(srcTableLookup.get(entity.getId_src()))
         .append("', '")
         .append(entity.getRole())
         .append("')");
     if (iter.hasNext()) sb.append(", ");
   }
   if (DBUtil.update(sb.toString()) != interaction.getEnvolvedEntityCount()) {
     System.out.println("SQL update failed? " + sb);
   }
   return interaction_id;
 }
Beispiel #2
0
 public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
   String username = request.getParameter("username");
   String password = request.getParameter("password");
   if (username == null) {
     response.sendRedirect("index.html");
     return;
   }
   String sql =
       "SELECT id FROM curator WHERE name="
           + SqlUtil.toSqlVarchar(username)
           + " AND passwd=PASSWORD("
           + SqlUtil.toSqlVarchar(password)
           + ")";
   String id = DBUtil.querySingle(sql);
   if (id == null) {
     response.sendRedirect("index.html");
     return;
   }
   Cookie cookie = new Cookie("username", username);
   if (request.getParameter("remember_me") != null
       && request.getParameter("remember_me").equals("on")) {
     cookie.setMaxAge(86400 * 365);
   } else {
     cookie.setMaxAge(-1);
   }
   response.addCookie(cookie);
   cookie = new Cookie("userid", id);
   if (request.getParameter("remember_me") != null
       && request.getParameter("remember_me").equals("on")) {
     cookie.setMaxAge(86400 * 365);
   } else {
     cookie.setMaxAge(-1);
   }
   response.addCookie(cookie);
 }
  public void flush() throws SQLException {
    InteractionFingerprinter fingerprinter = new InteractionFingerprinter();
    for (BiologicalInteraction interaction : interactions) {
      String fingerprint = fingerprinter.getFingerprint(interaction);
      String sql =
          String.format(
              "SELECT interaction_id FROM interaction WHERE fingerprint=%s",
              SqlUtil.toSqlVarchar(fingerprint));
      String id = DBUtil.querySingle(sql);

      if (id == null) {
        id = addNewInteraction(fingerprint, interaction);
      }

      interaction.setInteractionId(Integer.valueOf(id));
    }
    System.out.println("Evidences count: " + evidences.size());
    for (Evidence evidence : evidences) {
      String sql =
          "INSERT INTO evidence SET "
              + "interaction_id="
              + evidence.getInteraction().getInteractionId()
              + ", "
              + "negative=0, "
              + "directed="
              + (evidence.getInteraction().isDirected() ? 1 : 0)
              + ", "
              + "interaction_type='"
              + evidence.getInteraction().getInteractionType()
              + "', "
              + "source='"
              + evidence.getDataSource()
              + "', "
              + "macro_id='"
              + evidence.getMacroId()
              + "', "
              + "micro_id='"
              + evidence.getMicroId()
              + "', "
              + "confidence=100, "
              + "evidence_text="
              + SqlUtil.toSqlVarchar(evidence.getEvidenceText())
              + ", "
              + "curator=0";
      DBUtil.update(sql);
    }
  }