From: Roland Haeder Date: Tue, 18 Aug 2015 12:58:26 +0000 (+0200) Subject: Organized members X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b4209434de9f52dbd9f2c37e3107dc5869f9c353;p=pizzaservice-war.git Organized members Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java index 7824c3c9..4b358b42 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java @@ -167,6 +167,72 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen return (Iterator) iterator; } + @Override + public Category getCategory (final Product product) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + // Trace message + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); + + // product must not be null + if (product == null) { + // Abort here + throw new NullPointerException("product is null"); + } + + // Get category id from it + Long id = product.getCategory(); + + // Debug message + this.getLogger().debug(MessageFormat.format("id={0}", id)); + + // It should be >0 here + assert(id > 0) : MessageFormat.format("id={0} must be larger zero", id); + + // Then construct a search instance + SearchableCriteria criteria = new SearchCriteria(); + + // Add id to it + criteria.addCriteria(PizzaCategoryDatabaseConstants.COLUMN_ID, id); + + // Only one entry is find + criteria.setLimit(1); + + // Run it on backend + Result result = this.getBackend().doSelectByCriteria(criteria); + + // Debug log + this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size())); + + // Init category instance + Category category = null; + + // Is there one entry? + if (result.hasNext()) { + // Read result from it + Storeable storeable = result.next(); + + // Debug message + this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); + + // Is it instance of Category? + if (storeable instanceof Category) { + // Then cast it + category = (Category) storeable; + } + } + + // Trace message + this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); + + // Return it + return category; + } + + @Override + public String getIdName () { + // Return column id + return PizzaCategoryDatabaseConstants.COLUMN_ID; + } + /** * Gets a Result back from given ResultSet instance * @@ -297,70 +363,4 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen // Return it return instance; } - - @Override - public String getIdName () { - // Return column id - return PizzaCategoryDatabaseConstants.COLUMN_ID; - } - - @Override - public Category getCategory (final Product product) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // Trace message - this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); - - // product must not be null - if (product == null) { - // Abort here - throw new NullPointerException("product is null"); - } - - // Get category id from it - Long id = product.getCategory(); - - // Debug message - this.getLogger().debug(MessageFormat.format("id={0}", id)); - - // It should be >0 here - assert(id > 0) : MessageFormat.format("id={0} must be larger zero", id); - - // Then construct a search instance - SearchableCriteria criteria = new SearchCriteria(); - - // Add id to it - criteria.addCriteria(PizzaCategoryDatabaseConstants.COLUMN_ID, id); - - // Only one entry is find - criteria.setLimit(1); - - // Run it on backend - Result result = this.getBackend().doSelectByCriteria(criteria); - - // Debug log - this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size())); - - // Init category instance - Category category = null; - - // Is there one entry? - if (result.hasNext()) { - // Read result from it - Storeable storeable = result.next(); - - // Debug message - this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); - - // Is it instance of Category? - if (storeable instanceof Category) { - // Then cast it - category = (Category) storeable; - } - } - - // Trace message - this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); - - // Return it - return category; - } }