001/*
002 * #%L
003 * Netarchivesuite - archive
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish Library, 
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023
024package dk.netarkivet.archive.arcrepositoryadmin;
025
026import java.io.File;
027import java.sql.Connection;
028import java.sql.SQLException;
029
030import dk.netarkivet.archive.ArchiveSettings;
031import dk.netarkivet.common.exceptions.PermissionDenied;
032import dk.netarkivet.common.utils.SettingsFactory;
033
034/**
035 * Abstract collection of DB methods that are not standard SQL. This class is a singleton class whose actual
036 * implementation is provided by a subclass as determined by the DB_SPECIFICS_CLASS setting.
037 */
038public abstract class DBSpecifics extends SettingsFactory<DBSpecifics> {
039
040    /** The instance of the DBSpecifics class. */
041    private static DBSpecifics instance;
042
043    /**
044     * Get the singleton instance of the DBSpecifics implementation class.
045     *
046     * @return An instance of DBSpecifics with implementations for a given DB.
047     */
048    public static synchronized DBSpecifics getInstance() {
049        if (instance == null) {
050            instance = getInstance(ArchiveSettings.CLASS_ARCREPOSITORY_ADMIN_DATABASE);
051        }
052        return instance;
053    }
054
055    /**
056     * Shutdown the database system, if running in embedded mode. Otherwise, this is ignored.
057     * <p>
058     * Will log a warning on errors, but otherwise ignore them.
059     */
060    public abstract void shutdownDatabase();
061
062    /**
063     * Backup the database. For server-based databases, where the administrator is expected to perform the backups, this
064     * method should do nothing. This method gets called within one hour of the hour-of-day indicated by the
065     * DB_BACKUP_INIT_HOUR settings.
066     *
067     * @param backupDir Directory to which the database should be backed up
068     * @param c The connection to the database.
069     * @throws SQLException On SQL trouble backing up database
070     * @throws PermissionDenied if the directory cannot be created.
071     */
072    public abstract void backupDatabase(Connection c, File backupDir) throws SQLException, PermissionDenied;
073
074    /**
075     * Get the name of the JDBC driver class that handles interfacing to this server.
076     *
077     * @return The name of a JDBC driver class
078     */
079    public abstract String getDriverClassName();
080}