]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java
59e59fbf5289055be60a53061e53d41424998af1
[jcore.git] / src / org / mxchange / jcore / database / frontend / DatabaseFrontend.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcore.database.frontend;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.Map;
24 import org.mxchange.jcore.FrameworkInterface;
25 import org.mxchange.jcore.database.result.Result;
26 import org.mxchange.jcore.database.storage.Storeable;
27
28 /**
29  * A generic interface for database frontends
30  *
31  * @author Roland Haeder
32  */
33 public interface DatabaseFrontend extends FrameworkInterface {
34         /**
35          * Depending on column, an empty value may be converted to null
36          *
37          * @param key Key to check
38          * @param value Value to check
39          * @return Possible previous value or null
40          */
41         public Object emptyStringToNull (final String key, final Object value);
42
43         /**
44          * Gets a Result back from given ResultSet instance
45          *
46          * @param resultSet ResultSet instance from SQL driver
47          * @return A typorized Result instance
48          * @throws java.sql.SQLException If an SQL error occurs
49          */
50         public Result<? extends Storeable> getResultFromSet (final ResultSet resultSet) throws SQLException;
51
52         /**
53          * Name of used database table, handled over to backend
54          *
55          * @return the tableName
56          */
57         public String getTableName ();
58
59         /**
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
63          */
64         public void doShutdown () throws SQLException, IOException;
65
66         /**
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.
70          *
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?
77          */
78         public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
79
80         /**
81          * Some getter for name of id column
82          *
83          * @return Name of id column
84          */
85         public String getIdName ();
86 }