Пример #1
0
  /**
   * Adds a paper to the papers table, adds keywords to paper_keywords table
   *
   * @param keywords
   * @param facultyId
   * @throws DLException
   */
  public void addPaper(String keywords, int facultyId) throws DLException {
    MySQLDatabase db = MySQLDatabase.getInstance();
    try {
      ArrayList values = new ArrayList();
      values.add(this.id);
      values.add(title);
      values.add(pAbstract);
      values.add(citation);

      ArrayList authorship = new ArrayList();
      authorship.add(facultyId);
      authorship.add(this.id);

      ArrayList keywordList = new ArrayList();
      String[] kws = keywords.split(",");
      keywordList.add(this.id);
      keywordList.add(kws[0]);

      db.startTrans();
      db.setData("INSERT INTO papers(id, title, abstract, citation) VALUES(?, ?, ?, ?);", values);
      db.setData("INSERT INTO authorship(facultyId, paperId) VALUES(?, ?)", authorship);
      for (String kw : kws) {
        keywordList.set(1, kw);
        db.setData("INSERT INTO paper_keywords VALUES(?, ?);", keywordList);
      }
      db.endTrans();
    } catch (RuntimeException e) {
      throw new DLException(
          e,
          "Unix time: " + String.valueOf(System.currentTimeMillis() / 1000),
          "Error in addPaper() of Papers");
    }
  }
Пример #2
0
  /**
   * Updates the papers table to reflect updated details for a paper. Updates keywords in
   * paper_keywords.
   *
   * @param title
   * @param pAbstract
   * @param citation
   * @param keywords
   * @param facultyId
   * @throws DLException
   */
  public void save(String title, String pAbstract, String citation, String keywords, int facultyId)
      throws DLException {
    MySQLDatabase db = MySQLDatabase.getInstance();
    try {
      ArrayList values = new ArrayList();
      values.add(title);
      values.add(pAbstract);
      values.add(citation);
      values.add(this.id);

      ArrayList oldKeywords = new ArrayList();
      oldKeywords.add(this.id);

      String[] kws = keywords.split(",");
      ArrayList keywordList = new ArrayList();
      keywordList.add(this.id);
      keywordList.add(kws[0]);

      db.startTrans();
      db.setData("UPDATE papers SET title = ?, abstract = ?, citation = ? WHERE id = ?;", values);
      db.setData("DELETE FROM paper_keywords WHERE id = ?", oldKeywords);
      for (String kw : kws) {
        keywordList.set(1, kw);
        db.setData("INSERT INTO paper_keywords VALUES(?, ?);", keywordList);
      }
      db.endTrans();
    } catch (RuntimeException e) {
      throw new DLException(
          e,
          "Unix time: " + String.valueOf(System.currentTimeMillis() / 1000),
          "Error in save() of Papers");
    }
  }