예제 #1
0
 public int typeId(String cvName, String cvTermName) {
   Integer result = idByCvNameAndTermName.get(cvName, cvTermName);
   if (result == null)
     throw new IllegalArgumentException(
         String.format("Term '%s' not found in CV '%s'", cvTermName, cvName));
   return result;
 }
예제 #2
0
  /**
   * Fetch a synonym from the local cache. Failing that, create a new one.
   *
   * @param synonymType the synonym type (should be a term in the <code>genedb_synonym_type</code>
   *     CV).
   * @param synonymString the actual synonym
   * @return the cached or newly-created synonym object
   */
  public synchronized Synonym getSynonym(String synonymType, String synonymString) {
    logger.debug(String.format("Looking for synonym '%s:%s'", synonymType, synonymString));
    if (session == null) {
      throw new IllegalStateException("getSynonym called with no session");
    }

    if (synonymsByType.containsKey(synonymType, synonymString)) {
      logger.debug("Synonym found in cache");
      return synonymsByType.get(synonymType, synonymString);
    }

    if (detachedSynonymsByType.containsKey(synonymType, synonymString)) {
      logger.debug("Synonym found in detached cache. Merging");
      Synonym mergedSynonym =
          (Synonym) session.merge(detachedSynonymsByType.get(synonymType, synonymString));
      detachedSynonymsByType.remove(synonymType, synonymString);
      synonymsByType.put(synonymType, synonymString, mergedSynonym);
      return mergedSynonym;
    }

    logger.debug(String.format("Synonym '%s:%s' not found in cache", synonymType, synonymString));
    CvTerm synonymTypeCvTerm =
        (CvTerm)
            session.load(
                CvTerm.class,
                objectManager.getIdOfExistingCvTerm("genedb_synonym_type", synonymType));
    Synonym synonym = new Synonym(synonymTypeCvTerm, synonymString, synonymString);
    synonymsByType.put(synonymType, synonymString, synonym);
    return synonym;
  }
예제 #3
0
  public TypeCodes(Connection conn) throws SQLException {
    PreparedStatement st =
        conn.prepareStatement(
            "select cvterm_id"
                + "      , cv.name as cv_name"
                + "      , cvterm.name as cvterm_name"
                + " from cvterm"
                + " join cv using (cv_id)"
                + " join ("
                + "    select distinct type_id as cvterm_id from feature"
                + "    union"
                + "    select distinct type_id as cvterm_id from organismprop"
                + "    union"
                + "    select distinct type_id as cvterm_id from featureprop"
                + ") feature_types using (cvterm_id)");
    try {
      ResultSet rs = st.executeQuery();
      logger.trace("Loading CV terms from database");
      while (rs.next()) {
        int cvTermId = rs.getInt("cvterm_id");
        String cvName = rs.getString("cv_name");
        String cvTermName = rs.getString("cvterm_name");

        idByCvNameAndTermName.put(cvName, cvTermName, cvTermId);
        cvNameById.put(cvTermId, cvName);
        termNameById.put(cvTermId, cvTermName);
      }
      logger.trace("CV terms loaded");
    } finally {
      try {
        st.close();
      } catch (SQLException e) {
        System.err.println("SQLException from close(), probably caused by a previous exception");
        e.printStackTrace(System.err);
      }
    }
  }