*/
package org.mxchange.pizzaapplication.application;
-import java.io.IOException;
import java.util.Iterator;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.mxchange.jcore.application.Application;
-import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.pizzaapplication.category.Category;
import org.mxchange.pizzaapplication.product.Product;
* Some "getter" for a an array of all products
*
* @return All products
- * @throws java.io.IOException If an IO error occurs
- * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws javax.servlet.ServletException If anything went wrong
*/
- public Iterator<Product> getProducts () throws IOException, BadTokenException;
+ public Iterator<Product> getProducts () throws ServletException;
/**
* Some "getter" for a an array of all categories
*
* @return All categories
- * @throws java.io.IOException If an IO error occurs
- * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws javax.servlet.ServletException If anything went wrong
*/
- public Iterator<Category> getCategories () throws IOException, BadTokenException;
+ public Iterator<Category> getCategories () throws ServletException;
/**
* Checks if given Product instance is available and returns a printable
// Init/declare total price and iterator
int totalAmount = 0;
- Iterator<Product> iterator;
-
- try {
- // Get iterator
- iterator = this.getProducts();
- } catch (final IOException | BadTokenException ex) {
- throw new ServletException(ex);
- }
+ Iterator<Product> iterator = this.getProducts();
// "Walk" over all products
while (iterator.hasNext()) {
float totalPrice = 0.00f;
// Get iterator
- Iterator<Product> iterator;
- try {
- iterator = this.getProducts();
- } catch (final IOException | BadTokenException ex) {
- throw new ServletException(ex);
- }
+ Iterator<Product> iterator = this.getProducts();
// "Walk" over all products
while (iterator.hasNext()) {
* @return All products
*/
@Override
- public Iterator<Product> getProducts () throws IOException, BadTokenException {
- // Ask frontend for a list of products
- return this.productFrontend.getProducts();
+ public Iterator<Product> getProducts () throws ServletException {
+ try {
+ // Ask frontend for a list of products
+ return this.productFrontend.getProducts();
+ } catch (final IOException | BadTokenException | SQLException ex) {
+ throw new ServletException(ex);
+ }
}
/**
* @return All categories
*/
@Override
- public Iterator<Category> getCategories () throws IOException, BadTokenException {
- // Ask frontend for a list of categories
- return this.categoryFrontend.getCategories();
+ public Iterator<Category> getCategories () throws ServletException {
+ try {
+ // Ask frontend for a list of categories
+ return this.categoryFrontend.getCategories();
+ } catch (final IOException | BadTokenException | SQLException ex) {
+ throw new ServletException(ex);
+ }
}
/**
this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session));
// Init iterator
- Iterator<Product> iterator;
-
- try {
- // Get iterator
- iterator = this.getProducts();
- } catch (final IOException | BadTokenException ex) {
- throw new ServletException(ex);
- }
+ Iterator<Product> iterator = this.getProducts();
// "Walk" over all products
while (iterator.hasNext()) {
try {
// Get iterator
iterator = this.getProducts();
- } catch (final IOException | BadTokenException ex) {
+ } catch (final ServletException ex) {
this.abortProgramWithException(ex);
}
package org.mxchange.pizzaapplication.database.frontend.category;
import java.io.IOException;
+import java.sql.SQLException;
import java.util.Iterator;
import org.mxchange.jcore.database.frontend.DatabaseFrontend;
import org.mxchange.jcore.exceptions.BadTokenException;
* @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 ... ;-)
+ * @throws java.sql.SQLException If any SQL error occurs
*/
- public Iterator<Category> getCategories () throws IOException, BadTokenException;
+ public Iterator<Category> getCategories () throws IOException, BadTokenException, SQLException;
}
package org.mxchange.pizzaapplication.database.frontend.category;
import java.io.IOException;
+import java.sql.ResultSet;
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.DatabaseResult;
import org.mxchange.jcore.database.result.Result;
import org.mxchange.jcore.database.storage.Storeable;
import org.mxchange.jcore.exceptions.BadTokenException;
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 {
+ public Iterator<Category> getCategories () throws IOException, BadTokenException, SQLException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
return (Iterator<Category>) iterator;
}
+ /**
+ * Gets a Result back from given ResultSet instance
+ *
+ * @param resultSet ResultSet instance from SQL driver
+ * @return A typorized Result instance
+ * @throws java.sql.SQLException If any SQL error occurs
+ */
+ @Override
+ public Result<? extends Storeable> getResultFromSet (final ResultSet resultSet) throws SQLException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("resultSet={0} - CALLED!", resultSet));
+
+ // Init result instance
+ Result<? extends Storeable> result = new DatabaseResult();
+
+ // Reset result set before first row
+ resultSet.beforeFirst();
+
+ // "Walk" through all entries
+ while (resultSet.next()) {
+ // Unwrap whole object
+ Category category = resultSet.unwrap(Category.class);
+
+ // Debug log
+ this.getLogger().debug(MessageFormat.format("category={0}", category));
+
+ // Add it to result
+ result.add(category);
+ }
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("result({0})={1} - EXIT!", result.size(), result));
+
+ // Return result
+ return result;
+ }
+
/**
* Parses given line from database backend into a Storeable instance. Please
* note that not all backends need this.
package org.mxchange.pizzaapplication.database.frontend.product;
import java.io.IOException;
+import java.sql.ResultSet;
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.DatabaseResult;
import org.mxchange.jcore.database.result.Result;
import org.mxchange.jcore.database.storage.Storeable;
import org.mxchange.jcore.exceptions.BadTokenException;
this.getLogger().trace("EXIT!"); //NOI18N
}
- /**
- * 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")
- public Iterator<Product> getProducts () throws IOException, BadTokenException {
+ public Iterator<Product> getProducts () throws IOException, BadTokenException, SQLException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
return (Iterator<Product>) iterator;
}
+ /**
+ * Gets a Result back from given ResultSet instance
+ *
+ * @param resultSet ResultSet instance from SQL driver
+ * @return A typorized Result instance
+ * @throws java.sql.SQLException If any SQL error occurs
+ */
+ @Override
+ public Result<? extends Storeable> getResultFromSet (final ResultSet resultSet) throws SQLException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("resultSet={0} - CALLED!", resultSet));
+
+ // Init result instance
+ Result<? extends Storeable> result = new DatabaseResult();
+
+ // Reset result set before first row
+ resultSet.beforeFirst();
+
+ // "Walk" through all entries
+ while (resultSet.next()) {
+ // Unwrap whole object
+ Product product = resultSet.unwrap(Product.class);
+
+ // Debug log
+ this.getLogger().debug(MessageFormat.format("product={0}", product));
+
+ // Add it to result
+ result.add(product);
+ }
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("result({0})={1} - EXIT!", result.size(), result));
+
+ // Return result
+ return result;
+ }
+
/**
* Parses given line from database backend into a Storeable instance. Please
* note that not all backends need this.
package org.mxchange.pizzaapplication.database.frontend.product;
import java.io.IOException;
+import java.sql.SQLException;
import java.util.Iterator;
import org.mxchange.jcore.database.frontend.DatabaseFrontend;
import org.mxchange.jcore.exceptions.BadTokenException;
* @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 ... ;-)
+ * @throws java.sql.SQLException If any SQL errors occur
*/
- public Iterator<Product> getProducts () throws IOException, BadTokenException;
+ public Iterator<Product> getProducts () throws IOException, BadTokenException, SQLException;
}