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.jcore.database.frontend;
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
24 import org.mxchange.jcore.FrameworkInterface;
25 import org.mxchange.jcore.database.result.Result;
26 import org.mxchange.jcore.database.storage.Storeable;
29 * A generic interface for database frontends
31 * @author Roland Haeder
33 public interface DatabaseFrontend extends FrameworkInterface {
35 * Depending on column, an empty value may be converted to null
37 * @param key Key to check
38 * @param value Value to check
39 * @return Possible previous value or null
41 public Object emptyStringToNull (final String key, final Object value);
44 * Gets a Result back from given ResultSet instance
46 * @param resultSet ResultSet instance from SQL driver
47 * @return A typorized Result instance
48 * @throws java.sql.SQLException If an SQL error occurs
50 public Result<? extends Storeable> getResultFromSet (final ResultSet resultSet) throws SQLException;
53 * Name of used database table, handled over to backend
55 * @return the tableName
57 public String getTableName ();
60 * Shuts down the database layer
61 * @throws java.sql.SQLException If any SQL error occurs
62 * @throws java.io.IOException If any IO error occurs
64 public void doShutdown () throws SQLException, IOException;
67 * Converts the given map into a Storeable instance, depending on which class implements it. All
68 * keys are being interpreted as class fields/attributes and their respective setters are being searched for. As
69 * this method may fail to find one or access it, this method throws some exception.
71 * @param map Map instance to convert to Storeable
72 * @return An instance of a Storeable implementation
73 * @throws IllegalArgumentException Some implementations may throw this
74 * @throws java.lang.NoSuchMethodException If the invoked method was not found
75 * @throws java.lang.IllegalAccessException If the method cannot be accessed
76 * @throws java.lang.reflect.InvocationTargetException Any other problems?
78 public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
81 * Some getter for name of id column
83 * @return Name of id column
85 public String getIdName ();