2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.database.frontend.category;
19 import java.io.IOException;
20 import java.sql.SQLException;
21 import java.text.MessageFormat;
22 import java.util.Iterator;
23 import org.mxchange.jcore.criteria.searchable.SearchCriteria;
24 import org.mxchange.jcore.criteria.searchable.SearchableCritera;
25 import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
26 import org.mxchange.jcore.database.result.Result;
27 import org.mxchange.jcore.database.storage.Storeable;
28 import org.mxchange.jcore.exceptions.BadTokenException;
29 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
30 import org.mxchange.pizzaapplication.category.Category;
33 * Stores and retrieves Contact instances
35 * @author Roland Haeder
37 public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implements CategoryFrontend {
41 * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured backend is not supported
42 * @throws java.sql.SQLException If any SQL error occurs
44 public PizzaCategoryDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
46 this.getLogger().trace("CALLED!"); //NOI18N
49 this.setTableName("category"); //NOI18N
56 * Shuts down the database layer
57 * @throws java.sql.SQLException If an SQL error occurs
58 * @throws java.io.IOException If any IO error occurs
61 public void doShutdown () throws SQLException, IOException {
63 this.getLogger().trace("CALLED!"); //NOI18N
66 this.getBackend().doShutdown();
69 this.getLogger().trace("EXIT!"); //NOI18N
73 * An iterator on all products
75 * @return Iterator on all products
76 * @throws java.io.IOException If any IO error occurs
77 * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
80 @SuppressWarnings ("unchecked")
81 public Iterator<Category> getCategories () throws IOException, BadTokenException {
83 this.getLogger().trace("CALLED!"); //NOI18N
85 // Instance search criteria
86 SearchableCritera critera = new SearchCriteria();
89 Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(critera);
92 this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
95 Iterator<?> iterator = result.iterator();
98 this.getLogger().trace(MessageFormat.format("iterator={0} - EXIT!", iterator)); //NOI18N
100 // Get iterator and return it
101 return (Iterator<Category>) iterator;
105 * Parses given line from database backend into a Storeable instance. Please
106 * note that not all backends need this.
108 * @param line Line from database backend
109 * @return A Storeable instance
112 public Storeable parseLineToStoreable (final String line) throws BadTokenException {
114 this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
117 Category category = this.parseLineToCategory(line);
120 this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N
127 * Parses given line to a Category instance
129 * @param line Raw, decoded line from a file-based backend
130 * @return A Category instance from given line
132 private Category parseLineToCategory (final String line) {
133 throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N