mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-26 01:51:20 +01:00
Removed DBException:
- Made DBInitException subclass of DBOpException
This commit is contained in:
parent
6fbd8ced60
commit
0b7b0a5a16
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan;
|
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.DBInitException;
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
@ -116,10 +115,6 @@ public class ShutdownHook extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeDatabase(Database database) {
|
private void closeDatabase(Database database) {
|
||||||
try {
|
database.close();
|
||||||
database.close();
|
|
||||||
} catch (DBException e) {
|
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.api.exceptions.connection;
|
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
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,16 +21,12 @@ package com.djrapitops.plan.api.exceptions.database;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class DBInitException extends DBException {
|
public class DBInitException extends DBOpException {
|
||||||
|
|
||||||
public DBInitException(String message, Throwable cause) {
|
public DBInitException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBInitException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DBInitException(String message) {
|
public DBInitException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.command.commands.manage;
|
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.DBInitException;
|
||||||
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.db.DBType;
|
import com.djrapitops.plan.db.DBType;
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.db.SQLiteDB;
|
import com.djrapitops.plan.db.SQLiteDB;
|
||||||
@ -138,7 +138,7 @@ public class ManageBackupCommand extends CommandNode {
|
|||||||
backupDB = sqliteFactory.usingFileCalled(fileName);
|
backupDB = sqliteFactory.usingFileCalled(fileName);
|
||||||
backupDB.init();
|
backupDB.init();
|
||||||
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)).get();
|
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)).get();
|
||||||
} catch (DBException | ExecutionException e) {
|
} catch (DBOpException | ExecutionException e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
backupDB.close();
|
backupDB.close();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.db;
|
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.api.exceptions.database.DBInitException;
|
||||||
import com.djrapitops.plan.db.access.Query;
|
import com.djrapitops.plan.db.access.Query;
|
||||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||||
@ -32,7 +31,7 @@ public interface Database {
|
|||||||
|
|
||||||
void init() throws DBInitException;
|
void init() throws DBInitException;
|
||||||
|
|
||||||
void close() throws DBException;
|
void close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute an SQL Query statement to get a result.
|
* Execute an SQL Query statement to get a result.
|
||||||
|
@ -72,7 +72,7 @@ public class H2DB extends SQLDB {
|
|||||||
try {
|
try {
|
||||||
connection = getNewConnection(databaseFile);
|
connection = getNewConnection(databaseFile);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DBInitException(e);
|
throw new DBInitException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Figure out if execute("SET REFERENTIAL_INTEGRITY FALSE"); is required
|
// TODO Figure out if execute("SET REFERENTIAL_INTEGRITY FALSE"); is required
|
||||||
|
@ -71,7 +71,7 @@ public class SQLiteDB extends SQLDB {
|
|||||||
try {
|
try {
|
||||||
connection = getNewConnection(databaseFile);
|
connection = getNewConnection(databaseFile);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DBInitException(e);
|
throw new DBInitException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
startConnectionPingTask();
|
startConnectionPingTask();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package com.djrapitops.plan.system.database;
|
package com.djrapitops.plan.system.database;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
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.api.exceptions.database.DBInitException;
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.db.H2DB;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plugin.benchmarking.Timings;
|
import com.djrapitops.plugin.benchmarking.Timings;
|
||||||
import com.djrapitops.plugin.logging.L;
|
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
@ -86,12 +84,8 @@ public abstract class DBSystem implements SubSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
try {
|
if (db != null) {
|
||||||
if (db != null) {
|
db.close();
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
} catch (DBException e) {
|
|
||||||
errorHandler.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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.close();
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package com.djrapitops.plan.system.info.request;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.ParseException;
|
import com.djrapitops.plan.api.exceptions.ParseException;
|
||||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
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.info.InfoSystem;
|
||||||
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
@ -107,8 +107,8 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables impleme
|
|||||||
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
Throwable cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
if (cause instanceof DBException) {
|
if (cause instanceof DBOpException) {
|
||||||
throw new TransferDatabaseException((DBException) cause);
|
throw new TransferDatabaseException((DBOpException) cause);
|
||||||
} else if (cause instanceof IllegalStateException && "Player profile was null!".equals(cause.getMessage())) {
|
} else if (cause instanceof IllegalStateException && "Player profile was null!".equals(cause.getMessage())) {
|
||||||
throw new NotFoundException("Player has not played on this server.");
|
throw new NotFoundException("Player has not played on this server.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,7 +80,7 @@ public class SpongeMySQLDB extends MySQLDB {
|
|||||||
"jdbc:mysql://" + username + ":" + password + "@" + url
|
"jdbc:mysql://" + username + ":" + password + "@" + url
|
||||||
);
|
);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DBInitException(e);
|
throw new DBInitException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user