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.addressbook.database.backend;
19 import java.sql.Driver;
20 import java.sql.DriverManager;
21 import java.text.MessageFormat;
22 import java.util.Enumeration;
23 import org.mxchange.addressbook.BaseFrameworkSystem;
24 import org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException;
27 * Generall database backend
29 * @author Roland Haeder
31 public class BaseDatabaseBackend extends BaseFrameworkSystem {
34 * No instances from this class
36 protected BaseDatabaseBackend () {
40 * Validates driver name and throws an exception if the driver is not valid
42 * @param driverName Driver name (e.g. "mysql")
43 * @throws org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException If the given driver name cannot be solved into a driver instance
45 protected void validateDriver (final String driverName) throws UnsupportedDatabaseDriverException {
47 this.getLogger().trace(MessageFormat.format("driverName={0} - CALLED!", driverName)); //NOI18N
49 // Try to find the driver in driver list
50 Enumeration<Driver> drivers = DriverManager.getDrivers();
52 // Default is not found
53 boolean isFound = false;
56 while (drivers.hasMoreElements()) {
58 Driver driver = drivers.nextElement();
61 this.getLogger().debug(MessageFormat.format("Driver {0} is installed.", driver)); //NOI18N
64 String className = driver.getClass().getName();
67 if (className.contains(driverName)) {
69 this.getLogger().debug("Found driver!"); //NOI18N
80 throw new UnsupportedDatabaseDriverException(driverName);
84 this.getLogger().trace("EXIT!"); //NOI18N