]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/database/backend/DatabaseBackend.java
Added logger
[jcore.git] / src / org / mxchange / jcore / database / backend / DatabaseBackend.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.backend;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
22 import java.util.Map;
23 import org.mxchange.jcore.FrameworkInterface;
24 import org.mxchange.jcore.criteria.searchable.SearchableCriteria;
25 import org.mxchange.jcore.database.result.Result;
26 import org.mxchange.jcore.database.storage.Storeable;
27 import org.mxchange.jcore.exceptions.BadTokenException;
28 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
29
30 /**
31  * A generic interface for database frontends
32  *
33  * @author Roland Haeder
34  */
35 public interface DatabaseBackend extends FrameworkInterface {
36
37         /**
38          * Tries a connection to the database
39          * 
40          * @throws java.sql.SQLException If the connection attempt fails
41          */
42         public void connectToDatabase () throws SQLException;
43
44         /**
45          * Inserts given dataset instance and returns a Result instance on success
46          *
47          * @param dataset A dataset instance
48          * @return An instance of Result
49          * @throws java.sql.SQLException If any SQL error occurs
50          * @throws java.io.IOException If an IO error occurs
51          */
52         public Result<? extends Storeable> doInsertDataSet (final Map<String, Object> dataset) throws SQLException, IOException;
53
54         /**
55          * Run a "SELECT" statement with given criteria and always return a Result
56          * instance. The result instance then provides methods to iterate over all
57          * found entries.
58          *
59          * @param critera Search critera
60          * @return A result instance
61          * @throws java.io.IOException If any IO error occurs
62          * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
63          * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the file is badly damaged
64          * @throws java.sql.SQLException If any SQL error occurs
65          * @throws java.lang.NoSuchMethodException If a method was not found
66          * @throws java.lang.IllegalAccessException If the method cannot be accessed
67          * @throws java.lang.reflect.InvocationTargetException Any other problems?
68          */
69         public Result<? extends Storeable> doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
70
71         /**
72          * Shuts down this backend
73          *
74          * @throws java.sql.SQLException If any SQL error occurs
75          * @throws java.io.IOException If any IO error occurs
76          */
77         public void doShutdown () throws SQLException, IOException;
78
79         /**
80          * Some getter for total rows
81          *
82          * @return Total rows
83          * @throws java.io.IOException If an IO error occurs
84          * @throws java.sql.SQLException If any SQL error occurs
85          */
86         public Long getTotalRows () throws IOException, SQLException;
87 }