Package com.din.din.model.util

Examples of com.din.din.model.util.EntityCachingManager


  public void setEntity(Recipe recipe) {
    super.setEntity(recipe);
   
    if(recipe != null) {
      EntityCachingManager cache = getCache();   
      final Project project = recipe.getProject();
      // Load QuantityTypes if not already loaded
      cache.get(QuantityType.class, true, new CacheLoader<QuantityType>() {
        public List<QuantityType> onCacheLoad() {
          return QuantityTypeDAO.getQuantityTypeByProject(project);
        }
      });
     
      foodItemSet.clear();
      if(recipe.getRecipeItems() != null) {
        Map<Key, KeyEntity> foodItemMap = cache.get(FoodItem.class);
        for(RecipeItem item : recipe.getRecipeItems()) {
          if(foodItemMap.containsKey(item.getFoodItemKey())) {
            FoodItem foodItem = (FoodItem)foodItemMap.get(item.getFoodItemKey());
            FoodItemWrapper foodItemWrapper = new FoodItemWrapper(project, foodItem, item);
            foodItemSet.add(foodItemWrapper);
View Full Code Here


    boolean success = true;
    Recipe selected = getSelected();
    if(selected != null) {
      EntityManager entityManager = EMFListener.get()
      EntityTransaction transaction = entityManager.getTransaction();
      EntityCachingManager cache = getCache();
      try {
        transaction.begin();
       
        for(RecipeItem item : selected.getRecipeItems()) {
          //RecipeItemDAO.delete(entityManager,  item, cache);
          selected = entityManager.merge(selected);
          item.setRecipe(selected);
        }
       
        RecipeDAO.delete(entityManager, selected, cache);
       
        transaction.commit();
        cache.commit();
        setSelected(null);
       
        refresh();
      } catch (Exception e) {
        success = false;
       
        Logger.getLogger(RecipeManager.class.getSimpleName()).log(Level.WARNING, "Error deleting recipe!", e);
        BeanUtil.addMessage(FacesMessage.SEVERITY_ERROR, "delete.error", e.getMessage());
      } finally {
        if(transaction.isActive()) {
          transaction.rollback();
          cache.rollback();
        }
        entityManager.close();
      }
    }
    if(success) {
View Full Code Here

TOP

Related Classes of com.din.din.model.util.EntityCachingManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.