From: Roland Haeder Date: Fri, 14 Aug 2015 18:36:36 +0000 (+0200) Subject: Continued with project: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=717821bf20ce358cf0a374ec1b9653515cd20bf2;p=pizzaservice-war.git Continued with project: - moved PizzaProduct to own package and created BaseProduct from it. This class and interface Product are possible candidates for jcore - Added Apache commons jar (for new jcore changes for having a non-proprietary implementation of BASE64 encoding and decoding - Added newly thrown exception CorruptedDatabaseFileException - Ignored some strings for internationalization - Id needs to be initialized with zero, not null - Method toStoreable() has been fully rewritten to a more flexible solution - Removed some deprecated/unused methods Signed-off-by:Roland Häder --- diff --git a/lib/commons-codec-1.10.jar b/lib/commons-codec-1.10.jar new file mode 100644 index 00000000..1d7417c4 Binary files /dev/null and b/lib/commons-codec-1.10.jar differ diff --git a/lib/commons-codec-LICENSE.txt b/lib/commons-codec-LICENSE.txt new file mode 100644 index 00000000..75b52484 --- /dev/null +++ b/lib/commons-codec-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/lib/log4j-LICENSE.txt b/lib/log4j-LICENSE.txt new file mode 100644 index 00000000..6279e520 --- /dev/null +++ b/lib/log4j-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 1999-2005 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 9974a16e..9de51868 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1033,6 +1033,7 @@ exists or setup the property manually. For example like this: + @@ -1040,6 +1041,7 @@ exists or setup the property manually. For example like this: + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 94bacb0c..83606fbe 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=40f8a45c +build.xml.data.CRC32=ec514056 build.xml.script.CRC32=a6f5a733 build.xml.stylesheet.CRC32=651128d4@1.68.1.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=40f8a45c -nbproject/build-impl.xml.script.CRC32=63e11c78 +nbproject/build-impl.xml.data.CRC32=ec514056 +nbproject/build-impl.xml.script.CRC32=ea019def nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index da2f35bc..74da2f65 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -27,6 +27,7 @@ dist.javadoc.dir=${dist.dir}/javadoc dist.war=${dist.dir}/${war.name} endorsed.classpath= excludes= +file.reference.commons-codec-1.10.jar=lib/commons-codec-1.10.jar file.reference.log4j-api-2.3.jar=lib\\log4j-api-2.3.jar file.reference.log4j-core-2.3.jar=lib\\log4j-core-2.3.jar includes=** @@ -45,7 +46,8 @@ jar.compress=false javac.classpath=\ ${reference.jcore.jar}:\ ${file.reference.log4j-api-2.3.jar}:\ - ${file.reference.log4j-core-2.3.jar} + ${file.reference.log4j-core-2.3.jar}:\ + ${file.reference.commons-codec-1.10.jar} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked javac.debug=true @@ -67,6 +69,7 @@ javadoc.nonavbar=false javadoc.notree=false javadoc.preview=true javadoc.private=false +javadoc.reference.commons-codec-1.10.jar=/home/quix0r/public_html/JARs/commons-codec-1.10-javadoc.jar javadoc.splitindex=true javadoc.use=true javadoc.version=false @@ -84,6 +87,7 @@ run.test.classpath=\ # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): runmain.jvmargs= source.encoding=UTF-8 +source.reference.commons-codec-1.10.jar=/home/quix0r/public_html/JARs/commons-codec-1.10-sources.jar source.root=src src.dir=${source.root}/java test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml index c7be0c8d..fa6b5722 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -18,6 +18,10 @@ ${file.reference.log4j-core-2.3.jar} WEB-INF/lib + + ${file.reference.commons-codec-1.10.jar} + WEB-INF/lib + diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index e32f4556..68cf7220 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.BasePizzaServiceSystem; import org.mxchange.pizzaapplication.category.Category; @@ -482,12 +483,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override public String getPrintableProduktAvailability (final Product product) { // Trace message - this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N // Is it null? if (product == null) { // Should not be null - throw new NullPointerException("product is null"); + throw new NullPointerException("product is null"); //NOI18N } // Get availability @@ -544,7 +545,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P try { // Ask frontend for a list of products return this.productFrontend.getAvailableProducts(); - } catch (final IOException | BadTokenException | SQLException ex) { + } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException ex) { throw new ServletException(ex); } } @@ -559,7 +560,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P try { // Ask frontend for a list of products return this.productFrontend.getAllProducts(); - } catch (final IOException | BadTokenException | SQLException ex) { + } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException ex) { throw new ServletException(ex); } } @@ -574,7 +575,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P try { // Ask frontend for a list of categories return this.categoryFrontend.getCategories(); - } catch (final IOException | BadTokenException | SQLException ex) { + } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException ex) { throw new ServletException(ex); } } @@ -1092,7 +1093,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param title Title of category to check * @return Whether it has been found */ - private boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException { + private boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException { // Delegate to frontend return this.categoryFrontend.isCategoryTitleUsed(title); } @@ -1102,7 +1103,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param title Product title to check * @return Whether the product title has already been used */ - private boolean isProductTitleUsed (final String title) throws IOException, SQLException, BadTokenException { + private boolean isProductTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException { // Delegate to frontend return this.productFrontend.isProductTitleUsed(title); } @@ -1224,21 +1225,26 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // request must not be null if (request == null) { // Is null - throw new NullPointerException("request is null"); + throw new NullPointerException("request is null"); //NOI18N } // Get all fields String title = request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE); String parent = request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_PARENT); - Integer id = null; + + // Debug message + this.getLogger().debug(MessageFormat.format("title={0},parent={1}", title, parent)); //NOI18N + + // Init variables for casting + Integer id = 0; // Check all fields if (title == null) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaCategoryDatabaseConstants.COLUMN_TITLE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaCategoryDatabaseConstants.COLUMN_TITLE)); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaCategoryDatabaseConstants.COLUMN_TITLE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaCategoryDatabaseConstants.COLUMN_TITLE)); //NOI18N } else if ((parent != null) && (!parent.isEmpty())) { // "parent" is set, so check it try { @@ -1248,20 +1254,21 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P throw new IllegalArgumentException(e); } } + try { // Try to check if title is used already if (this.isCategoryTitleUsed(title)) { // Title already used throw new CategoryTitleAlreadyUsedException(request); } - } catch (final IOException | SQLException | BadTokenException ex) { + } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException ex) { throw new ServletException(ex); } try { // The category is not found, so add it to database this.categoryFrontend.addCategory(title, id); - } catch (final SQLException ex) { + } catch (final SQLException | IOException ex) { // Continue to throw it throw new ServletException(ex); } @@ -1283,7 +1290,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // request must not be null if (request == null) { // Is null - throw new NullPointerException("request is null"); + throw new NullPointerException("request is null"); //NOI18N } // Get title, price and category id @@ -1292,38 +1299,41 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P String category = request.getParameter(PizzaProductDatabaseConstants.COLUMN_CATEGORY); String available = request.getParameter(PizzaProductDatabaseConstants.COLUMN_AVAILABLE); + // Debug message + this.getLogger().debug(MessageFormat.format("title={0},price={1},category={2},available={3}", title, price, category, available)); + + // Variables for converting Long id = null; Float p = null; - Boolean a = null; // Check all fields if (title == null) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_TITLE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_TITLE)); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_TITLE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_TITLE)); //NOI18N } else if (price == null) { // "price" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_PRICE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_PRICE)); //NOI18N } else if (price.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_PRICE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_PRICE)); //NOI18N } else if (category == null) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_CATEGORY)); + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_CATEGORY)); //NOI18N } else if (category.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_CATEGORY)); + throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_CATEGORY)); //NOI18N } else if (available == null) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE)); + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE)); //NOI18N } else if (available.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE)); - } else if ((!"true".equals(available)) && (!"false".equals(available))) { + throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE)); //NOI18N + } else if ((!"true".equals(available)) && (!"false".equals(available))) { //NOI18N // Invalid value - throw new IllegalArgumentException(MessageFormat.format("{0} is invalid: {1}", PizzaProductDatabaseConstants.COLUMN_AVAILABLE, available)); + throw new IllegalArgumentException(MessageFormat.format("{0} is invalid: {1}", PizzaProductDatabaseConstants.COLUMN_AVAILABLE, available)); //NOI18N } // Parse numbers @@ -1336,7 +1346,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Parse boolean - a = Boolean.parseBoolean(available); + Boolean a = Boolean.parseBoolean(available); // Test on product title try { @@ -1345,14 +1355,14 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Title already used throw new ProductTitleAlreadyUsedException(request); } - } catch (final IOException | SQLException | BadTokenException ex) { + } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException ex) { throw new ServletException(ex); } try { // The product is not found, so add it to database this.productFrontend.addProduct(title, p, id, a); - } catch (final SQLException ex) { + } catch (final SQLException | IOException ex) { // Continue to throw it throw new ServletException(ex); } @@ -1371,12 +1381,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override public String generateLinkForParent (final Category category) { // Trace message - this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N // category must not be null if (category == null) { // Is null - throw new NullPointerException("category is null"); + throw new NullPointerException("category is null"); //NOI18N } // Get parent id @@ -1385,7 +1395,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is the id set? if (parent > 0) { // Product HTML code for link - throw new UnsupportedOperationException(MessageFormat.format("parent={0} - Unfinished!", parent)); + throw new UnsupportedOperationException(MessageFormat.format("parent={0} - Unfinished!", parent)); //NOI18N } // No parent set diff --git a/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java b/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java index 04b78b71..dbc4fa51 100644 --- a/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java +++ b/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java @@ -17,6 +17,7 @@ package org.mxchange.pizzaapplication.category; import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.Objects; import org.mxchange.jcore.BaseFrameworkSystem; @@ -55,6 +56,12 @@ public class BaseCategory extends BaseFrameworkSystem implements Category { this.setParent(parent); } + /** + * Default constructor + */ + protected BaseCategory () { + } + /** * Compares two categories with each other * @@ -154,4 +161,14 @@ public class BaseCategory extends BaseFrameworkSystem implements Category { public final void setTitle (final String title) { this.title = title; } + + @Override + public void setValueFromColumn (final String columnName, final String value) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } diff --git a/src/java/org/mxchange/pizzaapplication/category/Category.java b/src/java/org/mxchange/pizzaapplication/category/Category.java index 75de6b96..2ef80835 100644 --- a/src/java/org/mxchange/pizzaapplication/category/Category.java +++ b/src/java/org/mxchange/pizzaapplication/category/Category.java @@ -65,6 +65,7 @@ public interface Category extends Storeable, Comparable { /** * Compare method * @param category Category to compare to + * @return Comparison value */ @Override public int compareTo (final Category category); diff --git a/src/java/org/mxchange/pizzaapplication/category/product/ProductCategory.java b/src/java/org/mxchange/pizzaapplication/category/product/ProductCategory.java index dd89d346..d4c2e249 100644 --- a/src/java/org/mxchange/pizzaapplication/category/product/ProductCategory.java +++ b/src/java/org/mxchange/pizzaapplication/category/product/ProductCategory.java @@ -33,4 +33,10 @@ public class ProductCategory extends BaseCategory { // Call parent constructor super(id, title, parent); } + + /** + * Default constructor + */ + public ProductCategory () { + } } diff --git a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java index a3b06d43..276cdf3f 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -254,4 +254,16 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements public void show (final Client client) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + + @Override + public Object getValueFromColumn (String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Deligate to "hidden" object + return this.getContact().getValueFromColumn(columnName); + } + + @Override + public void setValueFromColumn (String columnName, String value) { + // Deligate to "hidden" object + this.getContact().setValueFromColumn(columnName, value); + } } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java index 6302554d..57a158b7 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/category/CategoryFrontend.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.util.Iterator; import org.mxchange.jcore.database.frontend.DatabaseFrontend; import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.pizzaapplication.category.Category; /** @@ -36,8 +37,9 @@ public interface CategoryFrontend extends DatabaseFrontend { * @param title Title of category * @param parent Parent id or null if not selected * @throws java.sql.SQLException If any SQL error occurs + * @throws java.io.IOException If an IO error occurs */ - public void addCategory (final String title, final Integer parent) throws SQLException; + public void addCategory (final String title, final Integer parent) throws SQLException, IOException; /** * An iterator on all categories @@ -46,8 +48,9 @@ public interface CategoryFrontend extends DatabaseFrontend { * @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 + * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getCategories () throws IOException, BadTokenException, SQLException; + public Iterator getCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException; /** * Checks if given category title is already used @@ -57,6 +60,7 @@ public interface CategoryFrontend extends DatabaseFrontend { * @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 + * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException; + public boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException; } 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 e9e76f4c..39278cd0 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java @@ -16,12 +16,12 @@ */ package org.mxchange.pizzaapplication.database.frontend.category; -import org.mxchange.pizzaapplication.category.product.ProductCategory; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; +import java.util.Map; import org.mxchange.jcore.criteria.searchable.SearchCriteria; import org.mxchange.jcore.criteria.searchable.SearchableCritera; import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend; @@ -29,8 +29,10 @@ 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; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.category.Category; +import org.mxchange.pizzaapplication.category.product.ProductCategory; import org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants; /** @@ -62,7 +64,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen * @param parent Parent id or null if not selected */ @Override - public void addCategory (final String title, final Integer parent) throws SQLException { + public void addCategory (final String title, final Integer parent) throws SQLException, IOException { // Trace message this.getLogger().trace(MessageFormat.format("title={0},parent={1} - CALLED!", title, parent)); @@ -140,7 +142,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen @Override @SuppressWarnings ("unchecked") - public Iterator getCategories () throws IOException, BadTokenException, SQLException { + public Iterator getCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N @@ -215,7 +217,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen * @return Whether the title has been used */ @Override - public boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException { + public boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException { // Trace message this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title)); @@ -245,34 +247,48 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen } /** - * Parses given line from database backend into a Storeable instance. Please - * note that not all backends need this. + * Converts the given map into a Storeable instance, depending on which class implements it. All + * keys are being interpreted as class fields/attributes and their respective setters are being searched for. As + * this method may fail to find one or access it, this method throws some exception. * - * @param line Line from database backend - * @return A Storeable instance + * @param map Map instance to convert to Storeable + * @return An instance of a Storeable implementation */ @Override - public Storeable parseLineToStoreable (final String line) throws BadTokenException { + public Storeable toStoreable (final Map map) { // Trace message - this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N - - // Call inner method - Category category = this.parseLine(line); + this.getLogger().trace("map=" + map + " - CALLED!"); + + // Is map null? + if (map == null) { + // Is null + throw new NullPointerException("map is null"); + } else if (map.isEmpty()) { + // Map is empty + throw new IllegalArgumentException("map is empty."); + } // Debug message - this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N + this.getLogger().debug("Has to handle " + map.size() + " entries"); - // Return it - return category; - } + // Get iterator on all entries + Iterator> iterator = map.entrySet().iterator(); - /** - * 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 parseLine (final String line) { - throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N + // Init object instance + Storeable instance = new ProductCategory(); + + // Iterate over all + while (iterator.hasNext()) { + // Get next entry + Map.Entry entry = iterator.next(); + + // Debug message + this.getLogger().debug("entry:" + entry.getKey() + "=" + entry.getValue()); + + // Try to set value + instance.setValueFromColumn(entry.getKey(), entry.getValue()); + } + + throw new UnsupportedOperationException("Not supported yet: map=" + map); } } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java index 321e3097..4eabce6b 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java @@ -21,6 +21,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; +import java.util.Map; import org.mxchange.jcore.criteria.searchable.SearchCriteria; import org.mxchange.jcore.criteria.searchable.SearchableCritera; import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend; @@ -28,9 +29,10 @@ 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; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.database.product.PizzaProductDatabaseConstants; -import org.mxchange.pizzaapplication.product.PizzaProduct; +import org.mxchange.pizzaapplication.product.pizza.PizzaProduct; import org.mxchange.pizzaapplication.product.Product; /** @@ -105,7 +107,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement @Override @SuppressWarnings ("unchecked") - public Iterator getAvailableProducts () throws IOException, BadTokenException, SQLException { + public Iterator getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N @@ -141,7 +143,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement */ @Override @SuppressWarnings ("unchecked") - public Iterator getAllProducts () throws IOException, BadTokenException, SQLException { + public Iterator getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N @@ -221,7 +223,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement * @throws java.sql.SQLException If any SQL errors occur */ @Override - public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException { + public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException { // Trace message this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title)); @@ -250,38 +252,6 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement return isFound; } - /** - * 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 - Product product = this.parseLine(line); - - // Debug message - this.getLogger().trace(MessageFormat.format("product={0} - EXIT!", product)); //NOI18N - - // Return it - return product; - } - - /** - * Parses given line to a Product instance - * - * @param line - * @return A Product instance from given line - */ - private Product parseLine (final String line) { - throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N - } - /** * Adds product to database by given title, price and category id * @param title Product title @@ -291,7 +261,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement * @throws java.sql.SQLException If any SQL errors occur */ @Override - public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException { + public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException, IOException { // Trace message this.getLogger().trace(MessageFormat.format("title={0},price={1},category={2} - CALLED!", title, price, category)); @@ -328,4 +298,17 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement // Trace message this.getLogger().trace("EXIT!"); } + + /** + * Converts the given map into a Storeable instance, depending on which class implements it. All + * keys are being interpreted as class fields/attributes and their respective setters are being searched for. As + * this method may fail to find one or access it, this method throws some exception. + * + * @param map Map instance to convert to Storeable + * @return An instance of a Storeable implementation + */ + @Override + public Storeable toStoreable (final Map map) { + throw new UnsupportedOperationException("Not supported yet: map=" + map); + } } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java index 4455fd54..431201e2 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.util.Iterator; import org.mxchange.jcore.database.frontend.DatabaseFrontend; import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.pizzaapplication.product.Product; /** @@ -37,8 +38,9 @@ public interface ProductFrontend extends DatabaseFrontend { * @param category Product category id * @param available Availability of product (selectable by customer) * @throws java.sql.SQLException If any SQL errors occur + * @throws java.io.IOException If an IO error occurs */ - public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException; + public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException, IOException; /** * An iterator on all products @@ -47,8 +49,9 @@ public interface ProductFrontend extends DatabaseFrontend { * @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 + * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getAllProducts () throws IOException, BadTokenException, SQLException; + public Iterator getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException; /** * An iterator on all products @@ -57,8 +60,9 @@ public interface ProductFrontend extends DatabaseFrontend { * @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 + * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getAvailableProducts () throws IOException, BadTokenException, SQLException; + public Iterator getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException; /** * Checks wether the given product title is already used. @@ -68,6 +72,7 @@ public interface ProductFrontend extends DatabaseFrontend { * @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 + * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException; + public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException; } diff --git a/src/java/org/mxchange/pizzaapplication/product/BaseProduct.java b/src/java/org/mxchange/pizzaapplication/product/BaseProduct.java new file mode 100644 index 00000000..453cf4e7 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/product/BaseProduct.java @@ -0,0 +1,178 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mxchange.pizzaapplication.product; + +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jcore.BaseFrameworkSystem; + +/** + * + * @author quix0r + */ +public class BaseProduct extends BaseFrameworkSystem implements Product { + /** + * Availability of product + */ + private Boolean available; + + /** + * Product category + */ + private Long category; + + /** + * Id number of product + */ + private Long id; + + /** + * Price of product + */ + private float price; + + /** + * Title of product + */ + private String title; + + /** + * Getter for product availability + * + * @return Product availability + */ + @Override + public final Boolean getAvailable () { + return this.available; + } + + /** + * Setter for product availability + * + * @param available Product availability + */ + @Override + public final void setAvailable (final Boolean available) { + this.available = available; + } + + /** + * Getter for product category + * + * @return Product category + */ + @Override + public final Long getCategory () { + return this.category; + } + + /** + * Setter for product category + * + * @param category Product category + */ + @Override + public final void setCategory (final Long category) { + this.category = category; + } + + /** + * Name of product + * @return the name + */ + @Override + public final Long getId () { + return this.id; + } + + /** + * Id number of product + * @param id the id number to set + */ + @Override + public final void setId (final Long id) { + this.id = id; + } + + /** + * Price of product + * @return the price + */ + @Override + public final float getPrice () { + return this.price; + } + + /** + * Price of product + * @param price the price to set + */ + @Override + public final void setPrice (final float price) { + this.price = price; + } + + /** + * Title of product + * @return the title + */ + @Override + public final String getTitle () { + return this.title; + } + + /** + * Title of product + * @param title the title to set + */ + @Override + public final void setTitle (final String title) { + this.title = title; + } + + /** + * Compares two categories with each other + * + * @param product Product comparator + * @return Comparison value + */ + @Override + public int compareTo (final Product product) { + // Trace message + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); + + // category should not be null + if (product == null) { + throw new NullPointerException("product is null"); + } + + // Debug message + this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getId(), product.getId())); + + // Is the id the same? + if (Objects.equals(this.getId(), product.getId())) { + // Same id, means same category + return 0; + } else if (this.getId() > product.getId()) { + // This id is larger than compared to + return -1; + } + + // The other id is larger + return 1; + } + + @Override + public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + throw new UnsupportedOperationException("Not supported yet:columnName=" + columnName); + } + + @Override + public void setValueFromColumn (final String columnName, final String value) { + throw new UnsupportedOperationException("Not supported yet: columnName=" + columnName + ",value=" + value); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java b/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java deleted file mode 100644 index 23f37575..00000000 --- a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.pizzaapplication.product; - -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jcore.BaseFrameworkSystem; - -/** - * Product class for pizza application - * - * @author Roland Haeder - */ -public class PizzaProduct extends BaseFrameworkSystem implements Product { - /** - * Availability of product - */ - private Boolean available; - - /** - * Product category - */ - private Long category; - - /** - * Id number of product - */ - private Long id; - - /** - * Price of product - */ - private float price; - - /** - * Title of product - */ - private String title; - - - /** - * Constructor for products with a name and a price. - * - * @param id Id number of product - * @param title Name of product - * @param price Price - * @deprecated Please use constructor with category and available - */ - @Deprecated - public PizzaProduct (final Long id, final String title, final float price) { - this.setId(id); - this.setTitle(title); - this.setPrice(price); - } - - /** - * Constructor will all required data - * - * @param id Id number of product - * @param title Name of product - * @param price Price - * @param category Category id - * @param available Availability (selectable by customer) - */ - public PizzaProduct (final Long id, final String title, final Float price, final Long category, final Boolean available) { - // Set all here - this.setId(id); - this.setTitle(title); - this.setPrice(price); - this.setCategory(category); - this.setAvailable(available); - } - - /** - * Getter for product availability - * - * @return Product availability - */ - @Override - public final Boolean getAvailable () { - return this.available; - } - - /** - * Setter for product availability - * - * @param available Product availability - */ - @Override - public final void setAvailable (final Boolean available) { - this.available = available; - } - - /** - * Getter for product category - * - * @return Product category - */ - @Override - public final Long getCategory () { - return this.category; - } - - /** - * Setter for product category - * - * @param category Product category - */ - @Override - public final void setCategory (final Long category) { - this.category = category; - } - - /** - * Name of product - * @return the name - */ - @Override - public final Long getId () { - return this.id; - } - - /** - * Id number of product - * @param id the id number to set - */ - @Override - public final void setId (final Long id) { - this.id = id; - } - - /** - * Price of product - * @return the price - */ - @Override - public final float getPrice () { - return this.price; - } - - /** - * Price of product - * @param price the price to set - */ - @Override - public final void setPrice (final float price) { - this.price = price; - } - - /** - * Title of product - * @return the title - */ - @Override - public final String getTitle () { - return this.title; - } - - /** - * Title of product - * @param title the title to set - */ - @Override - public final void setTitle (final String title) { - this.title = title; - } - - /** - * Compares two categories with each other - * - * @param product Product comparator - * @return Comparison value - */ - @Override - public int compareTo (final Product product) { - // Trace message - this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); - - // category should not be null - if (product == null) { - throw new NullPointerException("product is null"); - } - - // Debug message - this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getId(), product.getId())); - - // Is the id the same? - if (Objects.equals(this.getId(), product.getId())) { - // Same id, means same category - return 0; - } else if (this.getId() > product.getId()) { - // This id is larger than compared to - return -1; - } - - // The other id is larger - return 1; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/product/Product.java b/src/java/org/mxchange/pizzaapplication/product/Product.java index 2e17f8c8..8f55eab3 100644 --- a/src/java/org/mxchange/pizzaapplication/product/Product.java +++ b/src/java/org/mxchange/pizzaapplication/product/Product.java @@ -94,6 +94,7 @@ public interface Product extends Storeable, Comparable { /** * Compare method * @param category Category to compare to + * @return Comparison value */ @Override public int compareTo (final Product category); diff --git a/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java b/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java new file mode 100644 index 00000000..c6881a7f --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/product/pizza/PizzaProduct.java @@ -0,0 +1,68 @@ +/* + * 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 . + */ +package org.mxchange.pizzaapplication.product.pizza; + +import org.mxchange.pizzaapplication.product.BaseProduct; +import org.mxchange.pizzaapplication.product.Product; + +/** + * Product class for pizza application + * + * @author Roland Haeder + */ +public class PizzaProduct extends BaseProduct implements Product { + + /** + * Constructor for products with a name and a price. + * + * @param id Id number of product + * @param title Name of product + * @param price Price + * @deprecated Please use constructor with category and available + */ + @Deprecated + public PizzaProduct (final Long id, final String title, final Float price) { + // Trace message + this.getLogger().trace("id=" + id + ",title=" + title + ",price=" + price + " - CALLED!"); + + // Set all + this.setId(id); + this.setTitle(title); + this.setPrice(price); + } + + /** + * Constructor will all required data + * + * @param id Id number of product + * @param title Name of product + * @param price Price + * @param category Category id + * @param available Availability (selectable by customer) + */ + public PizzaProduct (final Long id, final String title, final Float price, final Long category, final Boolean available) { + // Trace message + this.getLogger().trace("id=" + id + ",title=" + title + ",price=" + price + ",category=" + category + ",available=" + available + " - CALLED!"); + + // Set all here + this.setId(id); + this.setTitle(title); + this.setPrice(price); + this.setCategory(category); + this.setAvailable(available); + } +}