From b4209434de9f52dbd9f2c37e3107dc5869f9c353 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 18 Aug 2015 14:58:26 +0200 Subject: [PATCH] =?utf8?q?Organized=20members=20Signed-off-by:Roland=20H?= =?utf8?q?=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../PizzaCategoryDatabaseFrontend.java | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) 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; - } } -- 2.39.5