Removed DBException:

- Made DBInitException subclass of DBOpException
This commit is contained in:
Rsl1122 2019-02-18 18:15:50 +02:00
parent 6fbd8ced60
commit 0b7b0a5a16
11 changed files with 15 additions and 68 deletions

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.Session;
@ -116,10 +115,6 @@ public class ShutdownHook extends Thread {
}
private void closeDatabase(Database database) {
try {
database.close();
} catch (DBException e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
database.close();
}
}

View File

@ -17,7 +17,7 @@
package com.djrapitops.plan.api.exceptions.connection;
/**
* Thrown when DBException occurs during InfoRequest#placeIntoDatabase.
* Thrown when {@link com.djrapitops.plan.api.exceptions.database.DBOpException} occurs during {@link com.djrapitops.plan.system.info.request.InfoRequest#placeIntoDatabase}.
*
* @author Rsl1122
*/

View File

@ -1,37 +0,0 @@
/*
* 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.api.exceptions.database;
/**
* Thrown when something goes wrong with the Database, generic exception.
*
* @author Rsl1122
*/
public class DBException extends Exception {
public DBException(String message, Throwable cause) {
super(message, cause);
}
public DBException(Throwable cause) {
super(cause);
}
public DBException(String message) {
super(message);
}
}

View File

@ -21,16 +21,12 @@ package com.djrapitops.plan.api.exceptions.database;
*
* @author Rsl1122
*/
public class DBInitException extends DBException {
public class DBInitException extends DBOpException {
public DBInitException(String message, Throwable cause) {
super(message, cause);
}
public DBInitException(Throwable cause) {
super(cause);
}
public DBInitException(String message) {
super(message);
}

View File

@ -16,8 +16,8 @@
*/
package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.SQLiteDB;
@ -138,7 +138,7 @@ public class ManageBackupCommand extends CommandNode {
backupDB = sqliteFactory.usingFileCalled(fileName);
backupDB.init();
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)).get();
} catch (DBException | ExecutionException e) {
} catch (DBOpException | ExecutionException e) {
errorHandler.log(L.ERROR, this.getClass(), e);
} catch (InterruptedException e) {
backupDB.close();

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.access.Query;
import com.djrapitops.plan.db.access.transactions.Transaction;
@ -32,7 +31,7 @@ public interface Database {
void init() throws DBInitException;
void close() throws DBException;
void close();
/**
* Execute an SQL Query statement to get a result.

View File

@ -72,7 +72,7 @@ public class H2DB extends SQLDB {
try {
connection = getNewConnection(databaseFile);
} catch (SQLException e) {
throw new DBInitException(e);
throw new DBInitException(e.getMessage(), e);
}
// TODO Figure out if execute("SET REFERENTIAL_INTEGRITY FALSE"); is required

View File

@ -71,7 +71,7 @@ public class SQLiteDB extends SQLDB {
try {
connection = getNewConnection(databaseFile);
} catch (SQLException e) {
throw new DBInitException(e);
throw new DBInitException(e.getMessage(), e);
}
startConnectionPingTask();
}

View File

@ -17,7 +17,6 @@
package com.djrapitops.plan.system.database;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.H2DB;
@ -26,7 +25,6 @@ import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plugin.benchmarking.Timings;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
@ -86,12 +84,8 @@ public abstract class DBSystem implements SubSystem {
@Override
public void disable() {
try {
if (db != null) {
db.close();
}
} catch (DBException e) {
errorHandler.log(L.WARN, this.getClass(), e);
if (db != null) {
db.close();
}
}
@ -112,7 +106,7 @@ public abstract class DBSystem implements SubSystem {
}
}
public void setActiveDatabase(Database db) throws DBException {
public void setActiveDatabase(Database db) {
this.db.close();
this.db = db;
}

View File

@ -18,7 +18,7 @@ package com.djrapitops.plan.system.info.request;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
@ -107,8 +107,8 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables impleme
} catch (ParseException e) {
Throwable cause = e.getCause();
if (cause instanceof DBException) {
throw new TransferDatabaseException((DBException) cause);
if (cause instanceof DBOpException) {
throw new TransferDatabaseException((DBOpException) cause);
} else if (cause instanceof IllegalStateException && "Player profile was null!".equals(cause.getMessage())) {
throw new NotFoundException("Player has not played on this server.");
} else {

View File

@ -80,7 +80,7 @@ public class SpongeMySQLDB extends MySQLDB {
"jdbc:mysql://" + username + ":" + password + "@" + url
);
} catch (SQLException e) {
throw new DBInitException(e);
throw new DBInitException(e.getMessage(), e);
}
}