Extracted Database interface

This commit is contained in:
Rsl1122 2019-01-18 18:03:37 +02:00
parent 0f37da5663
commit f75ab956c6
3 changed files with 60 additions and 23 deletions

View File

@ -0,0 +1,35 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.db;
/**
* Abstract class representing a Database.
* <p>
* All Operations methods should be only called from an asynchronous thread.
*
* @author Rsl1122
*/
public abstract class AbstractDatabase implements Database {
protected volatile boolean open = false;
@Override
public boolean isOpen() {
return open;
}
}

View File

@ -21,31 +21,38 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.system.database.databases.operation.*;
/**
* Abstract class representing a Database.
* <p>
* All Operations methods should be only called from an asynchronous thread.
* Interface for interacting with a Plan SQL database.
*
* @author Rsl1122
*/
public abstract class Database {
public interface Database {
protected volatile boolean open = false;
void init() throws DBInitException;
public abstract void init() throws DBInitException;
void close() throws DBException;
public abstract BackupOperations backup();
boolean isOpen();
public abstract CheckOperations check();
@Deprecated
BackupOperations backup();
public abstract FetchOperations fetch();
@Deprecated
CheckOperations check();
public abstract RemoveOperations remove();
@Deprecated
FetchOperations fetch();
public abstract SearchOperations search();
@Deprecated
RemoveOperations remove();
public abstract CountOperations count();
@Deprecated
SearchOperations search();
public abstract SaveOperations save();
@Deprecated
CountOperations count();
@Deprecated
SaveOperations save();
/**
* Used to get the {@code DBType} of the Database
@ -53,14 +60,9 @@ public abstract class Database {
* @return the {@code DBType}
* @see DBType
*/
public abstract DBType getType();
public abstract void close() throws DBException;
public boolean isOpen() {
return open;
}
public abstract void scheduleClean(long delay);
@Deprecated
DBType getType();
@Deprecated
void scheduleClean(long delay);
}

View File

@ -58,7 +58,7 @@ import java.util.stream.Collectors;
*
* @author Rsl1122
*/
public abstract class SQLDB extends Database {
public abstract class SQLDB extends AbstractDatabase {
private final Supplier<UUID> serverUUIDSupplier;