Ejemplo n.º 1
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;
  }