]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 08:41:26 +0000 (10:41 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 13:36:11 +0000 (15:36 +0200)
- Added new frontend class and interface for categories + rewritings
- Used <c:forEach> instead of for-loop where possible, else a while() loop has to be used with iterator.hasNext() and iterator.next()

Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/category/Category.java
src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java
web/finished.jsp
web/form_handler/do_preview.jsp
web/index.jsp
web/preview.jsp

index 30e1368d54f7a2fc52020248356f5f3533ae1e6f..4c4335c9ca2366e60771a05de5665db169ccef5b 100644 (file)
@@ -34,6 +34,8 @@ import org.mxchange.pizzaapplication.BasePizzaServiceSystem;
 import org.mxchange.pizzaapplication.category.Category;
 import org.mxchange.pizzaapplication.customer.Customer;
 import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer;
+import org.mxchange.pizzaapplication.database.frontend.category.CategoryFrontend;
+import org.mxchange.pizzaapplication.database.frontend.category.PizzaCategoryDatabaseFrontend;
 import org.mxchange.pizzaapplication.database.frontend.product.PizzaProductDatabaseFrontend;
 import org.mxchange.pizzaapplication.database.frontend.product.ProductFrontend;
 import org.mxchange.pizzaapplication.product.Product;
@@ -54,6 +56,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         */
        private ProductFrontend productFrontend;
 
+       /**
+        * Frontend for categories
+        */
+       private CategoryFrontend categoryFrontend;
+
        /**
         * Some singleton getter for this instance. If the instance is not set in
         * given application, it will be created.
@@ -536,8 +543,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         * @return All categories
         */
        @Override
-       public Iterator<Category> getCategories () {
-               throw new UnsupportedOperationException("Needs refacturing ...");
+       public Iterator<Category> getCategories () throws IOException, BadTokenException {
+               // Ask frontend for a list of categories
+               return this.categoryFrontend.getCategories();
        }
 
        /**
@@ -1047,7 +1055,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         * Initializes database frontends.
         */
        private void initDatabaseFrontends () throws UnsupportedDatabaseBackendException, SQLException {
+               // Product frontend
                this.productFrontend = new PizzaProductDatabaseFrontend();
+
+               // Category frontend
+               this.categoryFrontend = new PizzaCategoryDatabaseFrontend();
        }
 
        /**
index c1b0fdf770116c843d1ce3ce7f463fe40fef8afb..6e1483625f6038137b1b38aa1ffcee9295c42b83 100644 (file)
  */
 package org.mxchange.pizzaapplication.category;
 
-import org.mxchange.jcore.FrameworkInterface;
+import org.mxchange.jcore.database.storage.Storeable;
 
 /**
  * An interface for categories
  *
  * @author Roland Haeder
  */
-public interface Category extends FrameworkInterface {
+public interface Category extends Storeable {
 }
diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java
new file mode 100644 (file)
index 0000000..baa6e14
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.database.frontend.category;
+
+import java.io.IOException;
+import java.util.Iterator;
+import org.mxchange.jcore.database.frontend.DatabaseFrontend;
+import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.pizzaapplication.category.Category;
+
+/**
+ * An interface for product database frontends
+ *
+ * @author Roland Häder
+ */
+public interface CategoryFrontend extends DatabaseFrontend {
+
+       /**
+        * An iterator on all categories
+        *
+        * @return Iterator on all categories
+        * @throws java.io.IOException If any IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+        */
+       public Iterator<Category> getCategories () throws IOException, BadTokenException;
+}
diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java
new file mode 100644 (file)
index 0000000..64ee960
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.database.frontend.category;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import org.mxchange.jcore.criteria.searchable.SearchCriteria;
+import org.mxchange.jcore.criteria.searchable.SearchableCritera;
+import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.jcore.database.result.Result;
+import org.mxchange.jcore.database.storage.Storeable;
+import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.category.Category;
+
+/**
+ * Stores and retrieves Contact instances
+ *
+ * @author Roland Haeder
+ */
+public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implements CategoryFrontend {
+
+       /**
+        * Default constrcutor
+        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured backend is not supported
+        * @throws java.sql.SQLException If any SQL error occurs
+        */
+       public PizzaCategoryDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Set "table" name
+               this.setTableName("category"); //NOI18N
+
+               // Initalize backend
+               this.initBackend();
+       }
+
+       /**
+        * Shuts down the database layer
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.io.IOException If any IO error occurs
+        */
+       @Override
+       public void doShutdown () throws SQLException, IOException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Shutdown backend
+               this.getBackend().doShutdown();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * An iterator on all products
+        *
+        * @return Iterator on all products
+        * @throws java.io.IOException If any IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+        */
+       @Override
+       @SuppressWarnings ("unchecked")
+       public Iterator<Category> getCategories () throws IOException, BadTokenException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Instance search criteria
+               SearchableCritera critera = new SearchCriteria();
+
+               // Run the query
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(critera);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
+
+               // Get iterator
+               Iterator<?> iterator = result.iterator();
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("iterator={0} - EXIT!", iterator)); //NOI18N
+
+               // Get iterator and return it
+               return (Iterator<Category>) iterator;
+       }
+
+       /**
+        * Parses given line from database backend into a Storeable instance. Please
+        * note that not all backends need this.
+        *
+        * @param line Line from database backend
+        * @return A Storeable instance
+        */
+       @Override
+       public Storeable parseLineToStoreable (final String line) throws BadTokenException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
+
+               // Call inner method
+               Category category = this.parseLineToCategory(line);
+
+               // Debug message
+               this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N
+
+               // Return it
+               return category;
+       }
+
+       /**
+        * Parses given line to a Category instance
+        *
+        * @param line Raw, decoded line from a file-based backend
+        * @return A Category instance from given line
+        */
+       private Category parseLineToCategory (final String line) {
+               throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N
+       }
+}
index 6830a0f88c08edfee9a7c5fc7a162f9555d98c29..1fc6fe5f760d40694677f2a996f95024de270410 100644 (file)
@@ -55,6 +55,9 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
        /**
         * Shuts down the database layer
+        * 
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.io.IOException If any IO error occurs
         */
        @Override
        public void doShutdown () throws SQLException, IOException {
@@ -72,6 +75,8 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
         * An iterator on all products
         *
         * @return Iterator on all products
+        * @throws org.mxchange.jcore.exceptions.BadTokenException
+        * @throws java.io.IOException If any IO error occurs
         */
        @Override
        @SuppressWarnings ("unchecked")
index c2ca53b6a45f09b73115d08b294a29ec37b82ed3..3a2430b4cd1b4d50b81f5d58bb2e60e9b87faf2d 100644 (file)
                                        </thead>
                                        <tbody class="table_body">
                                                <%
-                                               // "Walk" over all products
-                                               for (final Product product : app.getProducts()) {
+                                               // Get Iterator
+                                               Iterator<Product> iterator = app.getProducts();
+
+                                               // "Walk" through all products and unmark them as ordered
+                                               while (iterator.hasNext()) {
+                                                       // Get product instance
+                                                       Product product = iterator.next();
                                                        %>
                                                        <tr>
                                                                <td>
index f6e358224cdd28c58632ab4fd68d3c76f613495d..a1b20cb0e258cc11bea9a036796c5a9abc34cd4e 100644 (file)
 
        // Is it post?
        if ("POST".equals(request.getMethod())) { //NOI18N
+               // Get Iterator
+               Iterator<Product> iterator = app.getProducts();
+
                // "Walk" through all products and unmark them as ordered
-               for (final Product product : app.getUnmarkedProducts(session)) {
+               while (iterator.hasNext()) {
+                       // Get product instance
+                       Product product = iterator.next();
+
+                       // Mark product as not ordered
+                       app.unmarkProductAsOrdered(product, session);
+
                        // Is it choosen and amount set?
                        if (app.isProductChoosen(product, request, session)) {
                                // Then mark it as choosen
@@ -29,7 +38,6 @@
                        } else {
                                // Unmark it
                                app.unmarkProductAsChoosen(product, session);
-                               app.unmarkProductAsOrdered(product, session);
                        }
                }
                // Redirect to proper URL
index 05afdbfb1d0bb42c9014a18ff32aa53eeb3223c7..7dd9458f998549606c69ffb01a75005f82c47518 100644 (file)
 
                                        <tbody class="table_body">
                                                <%
+                                               // Get Iterator
+                                               Iterator<Product> iterator = app.getProducts();
+
                                                // "Walk" through all products and unmark them as ordered
-                                               for (final Product product : app.getProducts()) {
+                                               while (iterator.hasNext()) {
+                                                       // Get product instance
+                                                       Product product = iterator.next();
+
                                                        // Unmark as ordered
                                                        app.unmarkProductAsOrdered(product, session);
                                                        %>
index dd3007826bc0713103e5d6f8f89351ec80c43f8f..fb93d38627b62e12ed7fc6e189a390bf836c5c4c 100644 (file)
                                        </thead>
                                        <tbody class="table_body">
                                                <%
+                                               // Get Iterator
+                                               Iterator<Product> iterator = app.getProducts();
+
                                                // "Walk" through all products and unmark them as ordered
-                                               for (final Product product : app.getProducts()) {
+                                               while (iterator.hasNext()) {
+                                                       // Get product instance
+                                                       Product product = iterator.next();
+
                                                        // Unmark it as ordered
                                                        app.unmarkProductAsOrdered(product, session);
                                                        %>