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.backend;
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
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;
32 * A generic interface for database frontends
34 * @author Roland Haeder
36 public interface DatabaseBackend extends FrameworkInterface {
39 * Tries a connection to the database
41 * @throws java.sql.SQLException If the connection attempt fails
42 * @throws javax.naming.NamingException May be thrown by a backend implementation
44 public void connectToDatabase () throws SQLException, NamingException;
47 * Inserts given dataset instance and returns a Result instance on success.
48 * The callee should not modify any content of the dataset instance.
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
55 public Result<? extends Storeable> doInsertDataSet (final Map<String, Object> dataset) throws SQLException, IOException;
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
62 * The callee should not modify any content of the criteria instance.
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?
74 public Result<? extends Storeable> doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
77 * Shuts down this backend
79 * @throws java.sql.SQLException If any SQL error occurs
80 * @throws java.io.IOException If any IO error occurs
82 public void doShutdown () throws SQLException, IOException;
85 * Some getter for total rows
88 * @throws java.io.IOException If an IO error occurs
89 * @throws java.sql.SQLException If any SQL error occurs
91 public Long getTotalRows () throws IOException, SQLException;