From f75ab956c6bc9c0e0aa278a107d3de964b82b08e Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 18 Jan 2019 18:03:37 +0200 Subject: [PATCH] Extracted Database interface --- .../djrapitops/plan/db/AbstractDatabase.java | 35 ++++++++++++++ .../java/com/djrapitops/plan/db/Database.java | 46 ++++++++++--------- .../java/com/djrapitops/plan/db/SQLDB.java | 2 +- 3 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/db/AbstractDatabase.java diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/AbstractDatabase.java b/Plan/common/src/main/java/com/djrapitops/plan/db/AbstractDatabase.java new file mode 100644 index 000000000..a4dcb98c7 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/AbstractDatabase.java @@ -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 . + */ +package com.djrapitops.plan.db; + +/** + * Abstract class representing a Database. + *

+ * 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; + } + +} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/Database.java b/Plan/common/src/main/java/com/djrapitops/plan/db/Database.java index e6993c14d..4b5452681 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/Database.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/Database.java @@ -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. - *

- * 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); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java index 58e6f358f..4adcc5e2e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java @@ -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 serverUUIDSupplier;