From a89ac369ea17d356130c01cf019f12297c0b3732 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 15 Aug 2015 00:47:29 +0200 Subject: [PATCH] =?utf8?q?toStoreable()=20is=20now=20"basicly=20finished"?= =?utf8?q?=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../product/PizzaProductDatabaseFrontend.java | 41 ++++++++++++++++++- .../product/pizza/PizzaProduct.java | 18 +------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java index decfe147..993d10a8 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java @@ -309,8 +309,45 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement * @return An instance of a Storeable implementation */ @Override - public Storeable toStoreable (final Map map) { - throw new UnsupportedOperationException("Not supported yet: map=" + map); + public Storeable toStoreable (final Map map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + // Trace message + this.getLogger().trace("map=" + map + " - CALLED!"); + + // Is map null? + if (map == null) { + // Is null + throw new NullPointerException("map is null"); + } else if (map.isEmpty()) { + // Map is empty + throw new IllegalArgumentException("map is empty."); + } + + // Debug message + this.getLogger().debug("Has to handle " + map.size() + " entries"); + + // Get iterator on all entries + Iterator> iterator = map.entrySet().iterator(); + + // Init object instance + Storeable instance = new PizzaProduct(); + + // Iterate over all + while (iterator.hasNext()) { + // Get next entry + Map.Entry entry = iterator.next(); + + // Debug message + this.getLogger().debug("entry:" + entry.getKey() + "=" + entry.getValue()); + + // Try to set value + instance.setValueFromColumn(entry.getKey(), entry.getValue()); + } + + // Trace message + this.getLogger().trace("instance=" + instance + " - EXIT!"); + + // Return it + return instance; } @Override diff --git a/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java b/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java index c6881a7f..7070029d 100644 --- a/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java +++ b/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java @@ -25,24 +25,10 @@ import org.mxchange.pizzaapplication.product.Product; * @author Roland Haeder */ public class PizzaProduct extends BaseProduct implements Product { - /** - * Constructor for products with a name and a price. - * - * @param id Id number of product - * @param title Name of product - * @param price Price - * @deprecated Please use constructor with category and available + * Default constructor */ - @Deprecated - public PizzaProduct (final Long id, final String title, final Float price) { - // Trace message - this.getLogger().trace("id=" + id + ",title=" + title + ",price=" + price + " - CALLED!"); - - // Set all - this.setId(id); - this.setTitle(title); - this.setPrice(price); + public PizzaProduct () { } /** -- 2.39.5