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;
*/
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.
* @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();
}
/**
* Initializes database frontends.
*/
private void initDatabaseFrontends () throws UnsupportedDatabaseBackendException, SQLException {
+ // Product frontend
this.productFrontend = new PizzaProductDatabaseFrontend();
+
+ // Category frontend
+ this.categoryFrontend = new PizzaCategoryDatabaseFrontend();
}
/**
*/
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 {
}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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
+ }
+}
/**
* 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 {
* 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")
</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>
// 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
} else {
// Unmark it
app.unmarkProductAsChoosen(product, session);
- app.unmarkProductAsOrdered(product, session);
}
}
// Redirect to proper URL
<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);
%>
</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);
%>