Exemplo n.º 1
0
  /**
   * This method returns all languages for a certain repository.
   *
   * @param repositoryId
   * @return
   * @throws SystemException
   * @throws Exception
   */
  public List getLanguageVOList(Integer repositoryId, Database db)
      throws SystemException, Exception {
    String key = "" + repositoryId + "_allLanguages";
    logger.info("key:" + key);
    List list = (List) CacheController.getCachedObject("languageCache", key);
    if (list != null) {
      logger.info("There was an cached list:" + list);
    } else {
      list = new ArrayList();

      OQLQuery oql =
          db.getOQLQuery(
              "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
      oql.bind(repositoryId);

      QueryResults results = oql.execute(Database.ReadOnly);
      while (results.hasMore()) {
        Language language = (Language) results.next();
        list.add(language.getValueObject());
      }

      results.close();
      oql.close();

      if (list.size() > 0) CacheController.cacheObject("languageCache", key, list);
    }

    return list;
  }
Exemplo n.º 2
0
  /**
   * Returns the LanguageVO with the given languageCode.
   *
   * @param code
   * @return
   * @throws SystemException
   * @throws Bug
   */
  public LanguageVO getLanguageVOWithCode(String code) throws SystemException, Bug {
    String key = "" + code;
    LanguageVO languageVO = (LanguageVO) CacheController.getCachedObject("languageCache", key);
    if (languageVO != null) {
      logger.info("There was an cached languageVO:" + languageVO);
    } else {
      Database db = CastorDatabaseService.getDatabase();

      try {
        beginTransaction(db);

        Language language = getLanguageWithCode(code, db);
        if (language != null) languageVO = language.getValueObject();

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

      CacheController.cacheObject("languageCache", key, languageVO);
    }

    return languageVO;
  }
Exemplo n.º 3
0
  /** This method return a LanguageVO */
  public LanguageVO getLanguageVOWithId(Integer languageId) throws SystemException, Exception {
    String key = "" + languageId;
    logger.info("key:" + key);
    LanguageVO languageVO = (LanguageVO) CacheController.getCachedObject("languageCache", key);
    if (languageVO != null) {
      logger.info("There was an cached languageVO:" + languageVO);
    } else {
      languageVO = (LanguageVO) getVOWithId(LanguageImpl.class, languageId);

      CacheController.cacheObject("languageCache", key, languageVO);
    }

    return languageVO;
  }
Exemplo n.º 4
0
  public List getLanguageVOList(Database db) throws SystemException, Bug {
    String key = "allLanguageVOList";
    List languageVOList = (List) CacheController.getCachedObject("languageCache", key);
    if (languageVOList != null) {
      if (logger.isInfoEnabled())
        logger.info("There was an cached languageVOList:" + languageVOList.size());
    } else {
      languageVOList = getAllVOObjects(LanguageImpl.class, "languageId", db);
      CacheController.cacheObject("languageCache", key, languageVOList);
    }

    return languageVOList;

    // return getAllVOObjects(LanguageImpl.class, "languageId", db);
  }
Exemplo n.º 5
0
  /**
   * 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;
  }
Exemplo n.º 6
0
  /**
   * 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;
  }
  /** Gets and precaches all propertycategory-objects. */
  public void preCacheAllPropertiesCategoryVOList() throws SystemException, Exception {
    Database db = CastorDatabaseService.getDatabase();

    beginTransaction(db);

    try {
      Timer t = new Timer();
      Map<Integer, CategoryVO> categoriesMap = new HashMap<Integer, CategoryVO>();
      OQLQuery oql1 =
          db.getOQLQuery(
              "SELECT c FROM org.infoglue.cms.entities.management.impl.simple.CategoryImpl c ORDER BY c.categoryId");

      QueryResults results1 = oql1.execute(Database.ReadOnly);
      while (results1.hasMore()) {
        Category category = (Category) results1.next();
        categoriesMap.put(category.getId(), category.getValueObject());
      }

      results1.close();
      oql1.close();
      logger.warn("Categories took: " + t.getElapsedTime());
      // getCastorCategory().setLevel(Level.DEBUG);
      // getCastorJDOCategory().setLevel(Level.DEBUG);

      OQLQuery oql =
          db.getOQLQuery(
              "SELECT c FROM org.infoglue.cms.entities.management.impl.simple.SmallPropertiesCategoryImpl c ORDER BY c.propertiesCategoryId");

      QueryResults results = oql.execute(Database.ReadOnly);
      while (results.hasMore()) {
        PropertiesCategory propertiesCategory = (PropertiesCategory) results.next();

        String key =
            "categoryVOList_"
                + propertiesCategory.getAttributeName()
                + "_"
                + propertiesCategory.getEntityName()
                + "_"
                + propertiesCategory.getEntityId();
        List<CategoryVO> categoryVOList =
            (List<CategoryVO>) CacheController.getCachedObject("propertiesCategoryCache", key);
        if (categoryVOList == null) {
          categoryVOList = new ArrayList<CategoryVO>();
          CacheController.cacheObject("propertiesCategoryCache", key, categoryVOList);
        }

        if (propertiesCategory.getValueObject().getCategoryId() != null) {
          CategoryVO categoryVO =
              categoriesMap.get(propertiesCategory.getValueObject().getCategoryId());
          if (categoryVO != null) categoryVOList.add(categoryVO);
          else
            logger.info(
                "An inconsistency found. The propertyCategory "
                    + propertiesCategory.getId()
                    + " pointed to a missing categoryID: "
                    + propertiesCategory.getValueObject().getCategoryId());
          /*
          			try
          			{
          				CategoryVO categoryVO = CategoryController.getController().findById(propertiesCategory.getValueObject().getCategoryId(), db).getValueObject();
          				categoryVOList.add(categoryVO);
          			}
          			catch (Exception e)
          			{
          				logger.error("An inconsistency found. The propertyCategory " + propertiesCategory.getId() + " pointed to a missing category:" + e.getMessage());
          }
          */
        }

        /*
        if(propertiesCategory.getCategory() != null)
        {
        	categoryVOList.add(propertiesCategory.getCategory().getValueObject());
        	//System.out.println("Category was ok for: " + key);
        }
        //else
        	//System.out.println("Category was null for: " + key);
        */
      }

      // getCastorCategory().setLevel(Level.WARN);
      // getCastorJDOCategory().setLevel(Level.WARN);

      results.close();
      oql.close();

      CacheController.cacheObject("propertiesCategoryCache", "allValuesCached", true);

      logger.warn("PropCategories took: " + t.getElapsedTime());

      commitTransaction(db);
    } catch (Exception e) {
      logger.error("An error occurred when we tried to fetch the list of PropertiesCategory:" + e);
      rollbackTransaction(db);
      throw new SystemException(e.getMessage());
    }
  }