ServerTable now a static information class:

- Made constructor private
- Removed getter in SQLDB
This commit is contained in:
Rsl1122 2019-02-15 09:44:36 +02:00
parent 817d157065
commit 57bc5b532e
4 changed files with 21 additions and 28 deletions

View File

@ -27,7 +27,10 @@ import com.djrapitops.plan.db.access.transactions.init.CleanTransaction;
import com.djrapitops.plan.db.access.transactions.init.CreateIndexTransaction;
import com.djrapitops.plan.db.access.transactions.init.CreateTablesTransaction;
import com.djrapitops.plan.db.patches.*;
import com.djrapitops.plan.db.sql.tables.*;
import com.djrapitops.plan.db.sql.tables.SessionsTable;
import com.djrapitops.plan.db.sql.tables.TPSTable;
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
import com.djrapitops.plan.db.sql.tables.UsersTable;
import com.djrapitops.plan.db.tasks.PatchTask;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
@ -78,7 +81,6 @@ public abstract class SQLDB extends AbstractDatabase {
private final UserInfoTable userInfoTable;
private final SessionsTable sessionsTable;
private final TPSTable tpsTable;
private final ServerTable serverTable;
private final SQLFetchOps fetchOps;
private final SQLSearchOps searchOps;
@ -104,8 +106,6 @@ public abstract class SQLDB extends AbstractDatabase {
this.timings = timings;
this.errorHandler = errorHandler;
serverTable = new ServerTable(this);
tpsTable = new TPSTable(this);
usersTable = new UsersTable(this);
@ -349,11 +349,6 @@ public abstract class SQLDB extends AbstractDatabase {
return tpsTable;
}
@Deprecated
public ServerTable getServerTable() {
return serverTable;
}
@Deprecated
public UserInfoTable getUserInfoTable() {
return userInfoTable;

View File

@ -17,19 +17,21 @@
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.sql.parsing.*;
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
import com.djrapitops.plan.db.sql.parsing.Insert;
import com.djrapitops.plan.db.sql.parsing.Sql;
import com.djrapitops.plan.db.sql.parsing.Update;
import com.djrapitops.plan.system.info.server.Server;
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
/**
* Table for managing multiple server's data in the database.
* <p>
* Table Name: plan_servers
* Table information about 'plan_servers'.
*
* @author Rsl1122
* @see Server
*/
public class ServerTable extends Table {
public class ServerTable {
public static final String TABLE_NAME = "plan_servers";
@ -54,17 +56,15 @@ public class ServerTable extends Table {
.toString();
public static final String STATEMENT_SELECT_SERVER_ID =
"(SELECT " + TABLE_NAME + "." + SERVER_ID + " FROM " + TABLE_NAME +
" WHERE " + TABLE_NAME + "." + SERVER_UUID + "=?" +
"(" + SELECT + TABLE_NAME + "." + SERVER_ID +
FROM + TABLE_NAME +
WHERE + TABLE_NAME + "." + SERVER_UUID + "=?" +
" LIMIT 1)";
public ServerTable(SQLDB db) {
super(TABLE_NAME, db);
statementSelectServerID = "(" + Select.from(tableName, tableName + "." + SERVER_ID).where(tableName + "." + SERVER_UUID + "=?").toString() + " LIMIT 1)";
private ServerTable() {
/* Static information class */
}
public final String statementSelectServerID;
public static String createTableSQL(DBType dbType) {
return CreateTableParser.create(TABLE_NAME, dbType)
.column(SERVER_ID, Sql.INT).primaryKey()

View File

@ -17,7 +17,10 @@
package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.sql.tables.*;
import com.djrapitops.plan.db.sql.tables.SessionsTable;
import com.djrapitops.plan.db.sql.tables.TPSTable;
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
import com.djrapitops.plan.db.sql.tables.UsersTable;
@Deprecated
public class SQLOps {
@ -28,7 +31,6 @@ public class SQLOps {
protected final UserInfoTable userInfoTable;
protected final SessionsTable sessionsTable;
protected final TPSTable tpsTable;
protected final ServerTable serverTable;
public SQLOps(SQLDB db) {
this.db = db;
@ -37,6 +39,5 @@ public class SQLOps {
userInfoTable = db.getUserInfoTable();
sessionsTable = db.getSessionsTable();
tpsTable = db.getTpsTable();
serverTable = db.getServerTable();
}
}

View File

@ -22,7 +22,6 @@ import com.djrapitops.plan.db.access.queries.ServerAggregateQueries;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.db.access.transactions.StoreServerInformationTransaction;
import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction;
import com.djrapitops.plan.db.sql.tables.ServerTable;
import com.djrapitops.plan.system.info.server.Server;
import org.junit.BeforeClass;
import org.junit.Test;
@ -60,8 +59,6 @@ public class SQLiteTest extends CommonDBTest {
@Test
public void testServerTableBungeeSave() throws DBInitException {
ServerTable serverTable = db.getServerTable();
Optional<Server> bungeeInfo = db.query(ServerQueries.fetchProxyServerInformation());
assertFalse(bungeeInfo.isPresent());