From 862b1f1ac9f8109162caf0cecc24abb9f68ce3a7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 12 Apr 2016 23:52:34 +0200 Subject: [PATCH] Made administrative product list cached to save EJB calls. --- .../PizzaAdminProductWebRequestBean.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java index faa17b4b..d477617b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java @@ -16,7 +16,9 @@ */ package org.mxchange.pizzaapplication.beans.product; +import java.util.Collections; import java.util.List; +import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; @@ -81,6 +83,11 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ */ private String productTitle; + /** + * Cache for all products + */ + private List products; + /** * Default constructor */ @@ -113,6 +120,9 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ // Call bean Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product); + // Add updated product to local list + this.products.add(updatedProduct); + // Fire event this.addedProductEvent.fire(new ShopProductAddedEvent(updatedProduct)); @@ -127,7 +137,7 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ @Override public List getAllProducts () throws FaceletException { // Call bean - return this.productRemoteBean.getAllProducts(); + return Collections.unmodifiableList(this.products); } @Override @@ -170,6 +180,15 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ this.productTitle = productTitle; } + /** + * Initializer method + */ + @PostConstruct + public void init () { + // Initialize list + this.products = this.productRemoteBean.getAllProducts(); + } + /** * Clears this bean (example: product has been added) */ -- 2.39.5