From 0174e0addc2fad2cad16e80b3a30de0bb5bbc152 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 26 Aug 2015 10:24:20 +0200 Subject: [PATCH] =?utf8?q?Rewrote=20item=20handling=20in=20BaseBasket=20to?= =?utf8?q?=20a=20database=20approach:=20-=20added=20method=20addItem()=20f?= =?utf8?q?or=20adding=20items,=20please=20make=20sure=20to=20call=20...=20?= =?utf8?q?-=20added=20method=20isItemAdded()=20which=20checks=20if=20the?= =?utf8?q?=20given=20item=20is=20found=20by=20its=20id=20number=20-=20adde?= =?utf8?q?d=20method=20getItem()=20to=20get=20an=20item=20from=20given=20P?= =?utf8?q?roduct=20instance=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nbproject/project.properties | 6 ++--- .../pizzaapplication/basket/BaseBasket.java | 20 ++++----------- .../pizzaapplication/basket/Basket.java | 2 +- .../basket/BasketDatabaseFrontend.java | 17 +++++++++++++ .../frontend/basket/BasketFrontend.java | 25 +++++++++++++++++++ 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index d12b1f48..491a7d92 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -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 diff --git a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java index 9e495f74..f41837d2 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java @@ -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 extends BaseFrameworkSystem */ private static final long serialVersionUID = 784396762230845717L; - /** - * Item map - */ - private final Map items; - /** * Protected constructor with session instance * @@ -55,9 +48,6 @@ public class BaseBasket 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 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 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 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 diff --git a/src/java/org/mxchange/pizzaapplication/basket/Basket.java b/src/java/org/mxchange/pizzaapplication/basket/Basket.java index f7b69fad..fa7d7efd 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/Basket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/Basket.java @@ -50,5 +50,5 @@ public interface Basket extends FrameworkInterface * @param product Product instance * @return Item instance or null */ - public T getItem (final Product product); + public AddableBasketItem getItem (final Product product); } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java index 5016dbe4..60aa6751 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java @@ -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 map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { throw new UnsupportedOperationException("Not supported yet: map=" + map); diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java index e1efd84f..5a472e2a 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java @@ -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); } -- 2.39.5