Implemented a couple missing Check, Fetch & Save Operations for SQL

This commit is contained in:
Rsl1122 2018-01-19 17:24:28 +02:00
parent 60257a3004
commit ba661ca2e0
9 changed files with 117 additions and 77 deletions

View File

@ -41,7 +41,7 @@ public interface FetchOperations {
Optional<Server> getBungeeInformation() throws DBException;
Optional<Integer> getServerID(UUID serverUUID);
Optional<Integer> getServerID(UUID serverUUID) throws DBException;
// Raw Data

View File

@ -5,9 +5,9 @@ import com.djrapitops.plan.api.exceptions.database.FatalDBException;
import java.sql.SQLException;
public class ErrorUtil {
public class SQLErrorUtil {
private ErrorUtil() {
private SQLErrorUtil() {
}
public static DBException getExceptionFor(SQLException e) {

View File

@ -4,19 +4,19 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.BackupOperations;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
public class SQLBackupOps implements BackupOperations {
private final SQLDB db;
public class SQLBackupOps extends SQLOps implements BackupOperations {
public SQLBackupOps(SQLDB db) {
this.db = db;
super(db);
}
@Override
public void backup(Database toDatabase) {
// TODO
}
@Override
public void restore(Database fromDatabase) {
// TODO
}
}

View File

@ -2,44 +2,57 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.operation.CheckOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import com.djrapitops.plan.system.info.server.ServerInfo;
import java.sql.SQLException;
import java.util.UUID;
public class SQLCheckOps implements CheckOperations {
private final SQLDB db;
public class SQLCheckOps extends SQLOps implements CheckOperations {
public SQLCheckOps(SQLDB db) {
this.db = db;
super(db);
}
@Override
public boolean isPlayerRegistered(UUID player) throws DBException {
try {
return db.getUsersTable().isRegistered(player);
return usersTable.isRegistered(player);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public boolean isPlayerRegistered(UUID player, UUID server) throws DBException {
try {
return db.getUserInfoTable().isRegistered(player, server);
return userInfoTable.isRegistered(player, server);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public boolean doesWebUserExists(String username) throws DBException {
try {
return db.getSecurityTable().userExists(username);
return securityTable.userExists(username);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public boolean isPlayerRegisteredOnThisServer(UUID player) throws DBException {
return isPlayerRegistered(player, ServerInfo.getServerUUID());
}
@Override
public boolean isServerInDatabase(UUID serverUUID) throws DBException {
try {
return serverTable.getServerID(serverUUID).isPresent();
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -2,8 +2,8 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.operation.CountOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import java.sql.SQLException;
import java.util.UUID;
@ -19,7 +19,7 @@ public class SQLCountOps extends SQLOps implements CountOperations {
try {
return userInfoTable.getServerUserCount(server);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -28,7 +28,7 @@ public class SQLCountOps extends SQLOps implements CountOperations {
try {
return usersTable.getPlayerCount();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -6,8 +6,9 @@ import com.djrapitops.plan.data.ServerProfile;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.*;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.TimeAmount;
@ -45,7 +46,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
return profile;
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -83,7 +84,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
}
return players;
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -118,7 +119,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
return profile;
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -142,7 +143,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getSavedUUIDs();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -151,7 +152,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return userInfoTable.getSavedUUIDs(server);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -160,7 +161,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return serverTable.getServerNames();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -169,7 +170,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return serverTable.getServerUUID(serverName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -178,27 +179,25 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getUuidOf(playerName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public WebUser getWebUser(String username) throws DBException {
try {
return securityTable.getWebUser(username);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public List<TPS> getTPSData(UUID serverUUID) throws DBException {
try {
return tpsTable.getTPSData(serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -207,7 +206,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return tpsTable.getNetworkOnlineData();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -216,7 +215,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getRegisterDates();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -225,7 +224,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return tpsTable.getAllTimePeak(serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -234,7 +233,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return tpsTable.getPeakPlayerCount(serverUUID, afterDate);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -243,7 +242,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return sessionsTable.getAllSessions(false);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -252,7 +251,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return sessionsTable.getAllSessions(true);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -261,7 +260,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return worldTable.getWorldNames(serverUuid);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -270,7 +269,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return nicknamesTable.getNicknames(uuid, serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -279,7 +278,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return actionsTable.getActions(uuid);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -288,7 +287,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getUsers();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -297,7 +296,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return sessionsTable.getLastSeenForAllPlayers();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -306,7 +305,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return geoInfoTable.getAllGeoInfo();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -315,7 +314,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getPlayerNames();
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -324,7 +323,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return usersTable.getPlayerName(playerUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -333,7 +332,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return serverTable.getServerName(serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -342,7 +341,25 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
try {
return nicknamesTable.getNicknames(uuid);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public Optional<Server> getBungeeInformation() throws DBException {
try {
return serverTable.getBungeeInfo();
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public Optional<Integer> getServerID(UUID serverUUID) throws DBException {
try {
return serverTable.getServerID(serverUUID);
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -3,8 +3,8 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.FatalDBException;
import com.djrapitops.plan.system.database.databases.operation.RemoveOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
import com.djrapitops.plan.system.database.databases.sql.tables.UserIDTable;
import com.djrapitops.plugin.api.Benchmark;
@ -41,7 +41,7 @@ public class SQLRemoveOps extends SQLOps implements RemoveOperations {
securityTable.removeUser(webUser);
} catch (SQLException e) {
throw ErrorUtil.getFatalExceptionFor(e);
throw SQLErrorUtil.getFatalExceptionFor(e);
} finally {
Benchmark.stop("Database", "Remove Account");
}
@ -64,7 +64,7 @@ public class SQLRemoveOps extends SQLOps implements RemoveOperations {
table.removeAllData();
}
} catch (SQLException e) {
throw ErrorUtil.getFatalExceptionFor(e);
throw SQLErrorUtil.getFatalExceptionFor(e);
}
}
@ -73,7 +73,7 @@ public class SQLRemoveOps extends SQLOps implements RemoveOperations {
try {
securityTable.removeUser(userName);
} catch (SQLException e) {
throw ErrorUtil.getFatalExceptionFor(e);
throw SQLErrorUtil.getFatalExceptionFor(e);
}
}
}

View File

@ -7,8 +7,9 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.container.*;
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import com.djrapitops.plan.system.info.server.Server;
import java.sql.SQLException;
import java.util.List;
@ -31,7 +32,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
tpsTable.insertAllTPS(ofServers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -40,7 +41,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
commandUseTable.insertCommandUsage(ofServers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -49,7 +50,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
usersTable.insertUsers(ofServers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -58,7 +59,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
sessionsTable.insertSessions(ofServers, containsExtraData);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -67,7 +68,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
usersTable.updateKicked(ofUsers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -76,7 +77,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
userInfoTable.insertUserInfo(ofServers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -85,7 +86,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
nicknamesTable.insertNicknames(ofServers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -94,7 +95,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
geoInfoTable.insertAllGeoInfo(ofUsers);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -103,7 +104,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
userInfoTable.updateBanStatus(uuid, banned);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -112,7 +113,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
userInfoTable.updateOpStatus(uuid, op);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -121,7 +122,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
usersTable.registerUser(uuid, registered, name);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -130,7 +131,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
actionsTable.insertAction(uuid, action);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -139,7 +140,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
geoInfoTable.saveGeoInfo(uuid, geoInfo);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -148,7 +149,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
usersTable.kicked(uuid);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -157,7 +158,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
usersTable.updateName(uuid, playerName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -166,7 +167,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
nicknamesTable.saveUserName(uuid, displayName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -175,7 +176,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
userInfoTable.registerUserInfo(uuid, registered);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -184,7 +185,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
commandUseTable.commandUsed(commandName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -193,7 +194,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
tpsTable.insertTPS(tps);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@ -202,7 +203,16 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
try {
sessionsTable.saveSession(uuid, session);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public void serverInfoForThisServer(Server server) throws DBException {
try {
serverTable.saveCurrentServerInfo(server);
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -2,8 +2,8 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.operation.SearchOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLErrorUtil;
import java.sql.SQLException;
import java.util.List;
@ -19,7 +19,7 @@ public class SQLSearchOps extends SQLOps implements SearchOperations {
try {
return usersTable.getMatchingNames(search);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
throw SQLErrorUtil.getExceptionFor(e);
}
}
}