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

View File

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

View File

@ -17,7 +17,10 @@
package com.djrapitops.plan.system.database.databases.sql.operation; package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.db.SQLDB; 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 @Deprecated
public class SQLOps { public class SQLOps {
@ -28,7 +31,6 @@ public class SQLOps {
protected final UserInfoTable userInfoTable; protected final UserInfoTable userInfoTable;
protected final SessionsTable sessionsTable; protected final SessionsTable sessionsTable;
protected final TPSTable tpsTable; protected final TPSTable tpsTable;
protected final ServerTable serverTable;
public SQLOps(SQLDB db) { public SQLOps(SQLDB db) {
this.db = db; this.db = db;
@ -37,6 +39,5 @@ public class SQLOps {
userInfoTable = db.getUserInfoTable(); userInfoTable = db.getUserInfoTable();
sessionsTable = db.getSessionsTable(); sessionsTable = db.getSessionsTable();
tpsTable = db.getTpsTable(); 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.queries.objects.ServerQueries;
import com.djrapitops.plan.db.access.transactions.StoreServerInformationTransaction; import com.djrapitops.plan.db.access.transactions.StoreServerInformationTransaction;
import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction; 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 com.djrapitops.plan.system.info.server.Server;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -60,8 +59,6 @@ public class SQLiteTest extends CommonDBTest {
@Test @Test
public void testServerTableBungeeSave() throws DBInitException { public void testServerTableBungeeSave() throws DBInitException {
ServerTable serverTable = db.getServerTable();
Optional<Server> bungeeInfo = db.query(ServerQueries.fetchProxyServerInformation()); Optional<Server> bungeeInfo = db.query(ServerQueries.fetchProxyServerInformation());
assertFalse(bungeeInfo.isPresent()); assertFalse(bungeeInfo.isPresent());