]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Rewrote item handling in BaseBasket to a database approach:
authorRoland Haeder <roland@mxchange.org>
Wed, 26 Aug 2015 08:24:20 +0000 (10:24 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 26 Aug 2015 08:24:20 +0000 (10:24 +0200)
- added method addItem() for adding items, please make sure to call ...
- added method isItemAdded() which checks if the given item is found by its id number
- added method getItem() to get an item from given Product instance
Signed-off-by:Roland Häder <roland@mxchange.org>

nbproject/project.properties
src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java
src/java/org/mxchange/pizzaapplication/basket/Basket.java
src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java

index d12b1f4843e232b72bd1e09f4021cbcfe30a5040..491a7d92c0f8f3bd573d291e45dc500e208b824b 100644 (file)
@@ -39,11 +39,11 @@ j2ee.compile.on.save=true
 j2ee.copy.static.files.on.save=true
 j2ee.deploy.on.save=true
 j2ee.platform=1.5
-j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/javax.persistence.jar
+j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar
 j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
 j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
-j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
-j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
+j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar
+j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar
 j2ee.platform.wsit.classpath=
 j2ee.server.type=gfv3ee6
 jar.compress=false
index 9e495f743b7fb6af0eb3a56b4b921937f63e4eec..f41837d2cca55bd7a39b7ba7bba4cbc524fe69b7 100644 (file)
@@ -19,8 +19,6 @@ package org.mxchange.pizzaapplication.basket;
 import java.io.Serializable;
 import java.sql.SQLException;
 import java.text.MessageFormat;
-import java.util.LinkedHashMap;
-import java.util.Map;
 import org.mxchange.jcore.BaseFrameworkSystem;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 import org.mxchange.pizzaapplication.database.frontend.basket.BasketDatabaseFrontend;
@@ -40,11 +38,6 @@ public class BaseBasket<T extends AddableBasketItem> extends BaseFrameworkSystem
         */
        private static final long serialVersionUID = 784396762230845717L;
 
-       /**
-        * Item map
-        */
-       private final Map<Long, T> items;
-
        /**
         * Protected constructor with session instance
         * 
@@ -55,9 +48,6 @@ public class BaseBasket<T extends AddableBasketItem> extends BaseFrameworkSystem
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
-               // Init item map instance
-               this.items = new LinkedHashMap<>();
-
                // Create frontend instance
                BasketFrontend frontend = new BasketDatabaseFrontend();
 
@@ -82,15 +72,15 @@ public class BaseBasket<T extends AddableBasketItem> extends BaseFrameworkSystem
                        throw new IllegalArgumentException("item has already been added. Did you miss to call isItemAdded()?"); //NOI18N
                }
 
-               // Add it to map
-               this.items.put(item.getId(), item);
+               // Add item to database
+               ((BasketFrontend) this.getFrontend()).addItem(item);
 
                // Trace call
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        @Override
-       public T getItem (final Product product) {
+       public AddableBasketItem getItem (final Product product) {
                // Trace message
                this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
 
@@ -104,7 +94,7 @@ public class BaseBasket<T extends AddableBasketItem> extends BaseFrameworkSystem
                this.getLogger().debug("Product " + product.getTitle() +  " has id " + product.getId()); //NOI18N
 
                // Get item instance from map by product's id number (both are the same)
-               T item = this.items.get(product.getId());
+               AddableBasketItem item = ((BasketFrontend) this.getFrontend()).getItem(product);
 
                // Is it null?
                if (item == null) {
@@ -131,7 +121,7 @@ public class BaseBasket<T extends AddableBasketItem> extends BaseFrameworkSystem
                }
 
                // Call map's method
-               boolean isAdded = this.items.containsKey(item.getId());
+               boolean isAdded = ((BasketFrontend) this.getFrontend()).isItemAdded(item);
 
                // Trace message
                this.getLogger().trace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N
index f7b69fadbd94ab5d1de10527af28fbac8d370184..fa7d7efd9f54bf852e7279e61f5d37396ace3f77 100644 (file)
@@ -50,5 +50,5 @@ public interface Basket<T extends AddableBasketItem> extends FrameworkInterface
         * @param product Product instance
         * @return Item instance or null
         */
-       public T getItem (final Product product);
+       public AddableBasketItem getItem (final Product product);
 }
index 5016dbe4d19ad6e9e47c1e585002b4204d809235..60aa675178b626f939b46ac9a658cb6a9f245fd3 100644 (file)
@@ -24,6 +24,8 @@ import java.util.Map;
 import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
 import org.mxchange.jcore.database.storage.Storeable;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+import org.mxchange.pizzaapplication.product.Product;
 
 /**
  * A database frontend for baskets
@@ -48,6 +50,11 @@ public class BasketDatabaseFrontend extends BaseDatabaseFrontend implements Bask
                this.initBackend();
        }
 
+       @Override
+       public void addItem (final AddableBasketItem item) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
        /**
         * Shuts down the database layer
         *
@@ -101,11 +108,21 @@ public class BasketDatabaseFrontend extends BaseDatabaseFrontend implements Bask
                throw new UnsupportedOperationException("Not supported yet.");
        }
 
+       @Override
+       public AddableBasketItem getItem (final Product product) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
        @Override
        public Storeable getStoreableAtRow (final int rowIndex) {
                throw new UnsupportedOperationException("Not supported yet: rowIndex=" + rowIndex);
        }
 
+       @Override
+       public boolean isItemAdded (final AddableBasketItem item) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
        @Override
        public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                throw new UnsupportedOperationException("Not supported yet: map=" + map);
index e1efd84f79cb29b2f16826dd3d96e02ba1508b41..5a472e2a274e459d769aa93ad3308c83b5e0b919 100644 (file)
@@ -17,6 +17,8 @@
 package org.mxchange.pizzaapplication.database.frontend.basket;
 
 import org.mxchange.jcore.database.frontend.DatabaseFrontend;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+import org.mxchange.pizzaapplication.product.Product;
 
 /**
  * An interface for basket database frontends
@@ -24,4 +26,27 @@ import org.mxchange.jcore.database.frontend.DatabaseFrontend;
  * @author Roland Haeder
  */
 public interface BasketFrontend extends DatabaseFrontend {
+       /**
+        * Adds given item instance to database. Please note that the item's id
+        * comes from product table.
+        *
+        * @param item Item instance to add
+        */
+       public void addItem (final AddableBasketItem item);
+
+       /**
+        * Gets an item instance for given Product instance
+        *
+        * @param product Prodduct instance
+        * @return An item instance
+        */
+       public AddableBasketItem getItem (final Product product);
+
+       /**
+        * Checks if given item instance is found in basket by its id number.
+        *
+        * @param item Item instance to check
+        * @return Whether the item is already added to the basket
+        */
+       public boolean isItemAdded (final AddableBasketItem item);
 }