]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Made administrative product list cached to save EJB calls.
authorRoland Haeder <roland@mxchange.org>
Tue, 12 Apr 2016 21:52:34 +0000 (23:52 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 12 Apr 2016 21:52:34 +0000 (23:52 +0200)
src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java

index faa17b4b126322c716bfe13f86d28cc290175115..d477617b42439778d73d54c8ec976ed3a5030758 100644 (file)
@@ -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<Product> 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<Product> 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)
         */