mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Removed CommandUseTable id related methods - not used
This commit is contained in:
parent
41275a1f84
commit
03335ec145
@ -19,15 +19,11 @@ package com.djrapitops.plan.db.sql.tables;
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Table that is in charge of storing command data.
|
||||
@ -53,12 +49,8 @@ public class CommandUseTable extends Table {
|
||||
|
||||
public CommandUseTable(SQLDB db) {
|
||||
super(TABLE_NAME, db);
|
||||
serverTable = db.getServerTable();
|
||||
|
||||
}
|
||||
|
||||
private final ServerTable serverTable;
|
||||
|
||||
public static String createTableSQL(DBType dbType) {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(COMMAND_ID, Sql.INT).primaryKey()
|
||||
@ -74,9 +66,9 @@ public class CommandUseTable extends Table {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = "UPDATE " + tableName + " SET "
|
||||
String sql = "UPDATE " + TABLE_NAME + " SET "
|
||||
+ TIMES_USED + "=" + TIMES_USED + "+ 1" +
|
||||
" WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID +
|
||||
" WHERE " + SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
" AND " + COMMAND + "=?";
|
||||
|
||||
boolean updated = execute(new ExecStatement(sql) {
|
||||
@ -91,25 +83,6 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<String> getCommandByID(int id) {
|
||||
String sql = Select.from(tableName, COMMAND).where(COMMAND_ID + "=?").toString();
|
||||
|
||||
return query(new QueryStatement<Optional<String>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return Optional.of(set.getString(COMMAND));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void insertCommand(String command) {
|
||||
execute(new ExecStatement(INSERT_STATEMENT) {
|
||||
@Override
|
||||
@ -120,23 +93,4 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<Integer> getCommandID(String command) {
|
||||
String sql = Select.from(tableName, COMMAND_ID).where(COMMAND + "=?").toString();
|
||||
|
||||
return query(new QueryStatement<Optional<Integer>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return Optional.of(set.getInt(COMMAND_ID));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -192,38 +192,6 @@ public abstract class CommonDBTest {
|
||||
assertEquals(expected, commandUse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandUseTableIDSystem() {
|
||||
CommandUseTable commandUseTable = db.getCommandUseTable();
|
||||
commandUseTable.commandUsed("plan");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
commandUseTable.commandUsed("tp");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
commandUseTable.commandUsed("pla");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 21; i++) {
|
||||
commandUseTable.commandUsed("help");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
commandUseTable.commandUsed("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
}
|
||||
|
||||
Optional<Integer> id = commandUseTable.getCommandID("plan");
|
||||
|
||||
assertTrue(id.isPresent());
|
||||
|
||||
Optional<String> commandByID = commandUseTable.getCommandByID(id.get());
|
||||
|
||||
assertTrue(commandByID.isPresent());
|
||||
assertEquals("plan", commandByID.get());
|
||||
assertFalse(commandUseTable.getCommandID("roiergbnougbierubieugbeigubeigubgierbgeugeg").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTPSSaving() throws Exception {
|
||||
TPSTable tpsTable = db.getTpsTable();
|
||||
|
Loading…
Reference in New Issue
Block a user