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