/**
   * This method returns the master language. todo - add attribute on repositoryLanguage to be able
   * to sort them... and then fetch the first
   */
  public LanguageVO getMasterLanguage(Integer repositoryId, Database db)
      throws SystemException, Exception {
    LanguageVO languageVO = null;

    String languageKey = "" + repositoryId;
    logger.info("languageKey:" + languageKey);
    languageVO = (LanguageVO) CacheController.getCachedObject("masterLanguageCache", languageKey);
    if (languageVO != null) {
      logger.info("There was an cached master language:" + languageVO.getName());
    } else {
      Language language = getMasterLanguage(db, repositoryId);

      if (language != null) {
        languageVO = language.getValueObject();
        CacheController.cacheObject("masterLanguageCache", languageKey, languageVO);
      }
    }

    return languageVO;
  }
  /**
   * This method returns the master language. todo - add attribute on repositoryLanguage to be able
   * to sort them... and then fetch the first
   */
  public LanguageVO getMasterLanguage(Integer repositoryId) throws SystemException, Exception {
    LanguageVO languageVO = null;

    String languageKey = "" + repositoryId;
    logger.info("languageKey:" + languageKey);
    languageVO = (LanguageVO) CacheController.getCachedObject("masterLanguageCache", languageKey);
    if (languageVO != null) {
      logger.info("There was an cached master language:" + languageVO.getName());
    } else {
      Database db = CastorDatabaseService.getDatabase();
      ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();

      Language language = null;

      beginTransaction(db);

      try {
        language = getMasterLanguage(db, repositoryId);

        // If any of the validations or setMethods reported an error, we throw them up now before
        // create.
        ceb.throwIfNotEmpty();

        if (language != null) {
          languageVO = language.getValueObject();
          CacheController.cacheObject("masterLanguageCache", languageKey, languageVO);
        }

        commitTransaction(db);
      } catch (Exception e) {
        logger.error("An error occurred so we should not complete the transaction:" + e, e);
        rollbackTransaction(db);
        throw new SystemException(e.getMessage());
      }
    }

    return languageVO;
  }