commit
c9421d9528
|
@ -6,7 +6,7 @@ pipeline {
|
|||
steps {
|
||||
dir("Plan") {
|
||||
script {
|
||||
sh './gradlew shadowJar --parallel'
|
||||
sh './gradlew clean shadowJar --parallel'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pipeline {
|
|||
dir("Plan") {
|
||||
script {
|
||||
try {
|
||||
sh './gradlew clean test --no-daemon'
|
||||
sh './gradlew test --parallel'
|
||||
} finally {
|
||||
junit '**/build/test-results/test/*.xml'
|
||||
}
|
||||
|
@ -45,4 +45,13 @@ pipeline {
|
|||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
dir("Plan") {
|
||||
script {
|
||||
sh './gradlew clean --parallel'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,5 +33,6 @@ public class NotReadyException extends IllegalStateException {
|
|||
* The Exception is not logged (Fails silently) so no message is available.
|
||||
*/
|
||||
public NotReadyException() {
|
||||
// Constructor is present for javadoc comment.
|
||||
}
|
||||
}
|
|
@ -155,6 +155,7 @@ public final class ExtensionExtractor {
|
|||
for (Class option : parameterOptions) {
|
||||
if (option.equals(methodParameter)) {
|
||||
validParameter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ plugins {
|
|||
apply plugin: 'nebula-aggregate-javadocs'
|
||||
|
||||
allprojects {
|
||||
wrapper.gradleVersion = "5.0"
|
||||
wrapper.gradleVersion = "5.5.1"
|
||||
|
||||
group "com.djrapitops"
|
||||
version "4.9.1"
|
||||
version "4.9.2"
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
|
@ -56,25 +56,25 @@ subprojects {
|
|||
ext.daggerVersion = "2.24"
|
||||
ext.daggerCompilerVersion = "2.24"
|
||||
|
||||
ext.abstractPluginFrameworkVersion = "3.4.1"
|
||||
ext.abstractPluginFrameworkVersion = "3.4.2"
|
||||
ext.planPluginBridgeVersion = "4.9.0-R0.3"
|
||||
|
||||
ext.bukkitVersion = "1.12.2-R0.1-SNAPSHOT"
|
||||
ext.spigotVersion = "1.12.2-R0.1-SNAPSHOT"
|
||||
ext.paperVersion = "1.12.2-R0.1-SNAPSHOT"
|
||||
ext.bukkitVersion = "1.13.2-R0.1-SNAPSHOT"
|
||||
ext.spigotVersion = "1.13.2-R0.1-SNAPSHOT"
|
||||
ext.paperVersion = "1.13.2-R0.1-SNAPSHOT"
|
||||
ext.spongeVersion = "7.1.0"
|
||||
ext.bungeeVersion = "1.12-SNAPSHOT"
|
||||
ext.bungeeVersion = "1.13-SNAPSHOT"
|
||||
ext.velocityVersion = "1.0-SNAPSHOT"
|
||||
ext.redisBungeeVersion = "0.3.8-SNAPSHOT"
|
||||
|
||||
ext.httpClientVersion = "4.5.9"
|
||||
ext.commonsTextVersion = "1.7"
|
||||
ext.htmlCompressorVersion = "1.5.2"
|
||||
ext.caffeineVersion = "2.7.0"
|
||||
ext.caffeineVersion = "2.8.0"
|
||||
ext.h2Version = "1.4.199"
|
||||
ext.mysqlVersion = "8.0.17"
|
||||
ext.hikariVersion = "3.3.1"
|
||||
ext.slf4jVersion = "1.7.26"
|
||||
ext.slf4jVersion = "1.7.27"
|
||||
ext.geoIpVersion = "2.12.0"
|
||||
ext.guavaVersion = "28.0-jre"
|
||||
ext.bstatsVersion = "1.4"
|
||||
|
@ -127,7 +127,7 @@ subprojects {
|
|||
testCompile "org.xerial:sqlite-jdbc:3.28.0" // SQLite
|
||||
testCompile "mysql:mysql-connector-java:$mysqlVersion" // MySQL
|
||||
}
|
||||
|
||||
|
||||
configurations {
|
||||
testArtifacts.extendsFrom testRuntime
|
||||
}
|
||||
|
@ -143,11 +143,20 @@ subprojects {
|
|||
checkstyle {
|
||||
configFile rootProject.file('config/checkstyle/checkstyle.xml')
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled true
|
||||
xml.destination file("${buildDir}/reports/jacoco/report.xml")
|
||||
csv.enabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sonarqube {
|
||||
properties {
|
||||
property "sonar.projectName", "Player Analytics"
|
||||
property "sonar.projectKey", "com.djrapitops:Plan"
|
||||
property "sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco"
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
import com.djrapitops.plan.command.commands.RegisterCommandFilter;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
|
@ -75,7 +74,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||
PlanCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("plan", command);
|
||||
new RegisterCommandFilter().registerFilter();
|
||||
if (system != null) {
|
||||
system.getProcessing().submitNonCritical(() -> system.getListenerSystem().callEnableEvent(this));
|
||||
}
|
||||
|
|
|
@ -1,99 +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.command.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.apache.logging.log4j.core.filter.AbstractFilter;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Filters out WebUser registration command logs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RegisterCommandFilter extends AbstractFilter {
|
||||
|
||||
private final Set<String> censoredCommands = ImmutableSet.of("/plan web register", "/plan webuser register", "/plan register");
|
||||
|
||||
public void registerFilter() {
|
||||
Logger logger = (Logger) LogManager.getRootLogger();
|
||||
logger.addFilter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(LogEvent event) {
|
||||
if (event == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
return validateMessage(event.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
|
||||
return validateMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
|
||||
return validateMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
|
||||
if (msg == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
return validateMessage(msg.toString());
|
||||
}
|
||||
|
||||
private Result validateMessage(Message message) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
return validateMessage(message.getFormattedMessage());
|
||||
}
|
||||
|
||||
private Result validateMessage(String message) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
return commandShouldBeCensored(message)
|
||||
? Result.DENY
|
||||
: Result.NEUTRAL;
|
||||
}
|
||||
|
||||
private boolean commandShouldBeCensored(String message) {
|
||||
return message != null
|
||||
&& (message.toLowerCase().contains("issued server command:")
|
||||
&& shouldBeCensored(message));
|
||||
}
|
||||
|
||||
private boolean shouldBeCensored(String message) {
|
||||
return message != null && censoredCommands.stream().anyMatch(message::contains);
|
||||
}
|
||||
}
|
|
@ -70,11 +70,6 @@ public abstract class BukkitImporter implements Importer {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public List<String> getNames() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -102,10 +102,10 @@ public class DeathEventListener implements Listener {
|
|||
Material itemInHand;
|
||||
try {
|
||||
itemInHand = killer.getInventory().getItemInMainHand().getType();
|
||||
} catch (NoSuchMethodError e) {
|
||||
} catch (NoSuchMethodError oldVersion) {
|
||||
try {
|
||||
itemInHand = killer.getInventory().getItemInHand().getType(); // Support for non dual wielding versions.
|
||||
} catch (Exception | NoSuchMethodError | NoSuchFieldError e2) {
|
||||
} catch (Exception | NoSuchMethodError | NoSuchFieldError unknownError) {
|
||||
itemInHand = Material.AIR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package com.djrapitops.plan.api.exceptions;
|
|||
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Exception that is thrown when a call to a DataExtension method throws an exception.
|
||||
*
|
||||
|
@ -26,7 +28,8 @@ import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
|||
public class DataExtensionMethodCallException extends IllegalStateException {
|
||||
|
||||
private final String pluginName;
|
||||
private final MethodWrapper method;
|
||||
// Non serializable field due to Method not being serializable.
|
||||
private transient final MethodWrapper method;
|
||||
|
||||
public DataExtensionMethodCallException(Throwable cause, String pluginName, MethodWrapper method) {
|
||||
super(cause);
|
||||
|
@ -38,7 +41,8 @@ public class DataExtensionMethodCallException extends IllegalStateException {
|
|||
return pluginName;
|
||||
}
|
||||
|
||||
public MethodWrapper getMethod() {
|
||||
return method;
|
||||
public Optional<MethodWrapper> getMethod() {
|
||||
// method is transient and might be lost if flushed to disk.
|
||||
return Optional.ofNullable(method);
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@ import com.djrapitops.plugin.command.CommandType;
|
|||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -59,17 +58,17 @@ public class ReloadCommand extends CommandNode {
|
|||
|
||||
@Override
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
runnableFactory.create("Reload task", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.reloadPlugin(true);
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED));
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
plugin.reloadPlugin(true);
|
||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED));
|
||||
} finally {
|
||||
Thread thread = Thread.currentThread();
|
||||
thread.interrupt();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}, "Plan Reload Thread").start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,17 +72,17 @@ public class ActivityIndex {
|
|||
double max = 4.0;
|
||||
|
||||
long playtimeWeek = weekOne.toActivePlaytime();
|
||||
double weekPlay = (playtimeWeek * 1.0 / activePlayThreshold);
|
||||
double weekPlay = playtimeWeek * 1.0 / activePlayThreshold;
|
||||
if (weekPlay > max) {
|
||||
weekPlay = max;
|
||||
}
|
||||
long playtimeWeek2 = weekTwo.toActivePlaytime();
|
||||
double week2Play = (playtimeWeek2 * 1.0 / activePlayThreshold);
|
||||
double week2Play = playtimeWeek2 * 1.0 / activePlayThreshold;
|
||||
if (week2Play > max) {
|
||||
week2Play = max;
|
||||
}
|
||||
long playtimeWeek3 = weekThree.toActivePlaytime();
|
||||
double week3Play = (playtimeWeek3 * 1.0 / activePlayThreshold);
|
||||
double week3Play = playtimeWeek3 * 1.0 / activePlayThreshold;
|
||||
if (week3Play > max) {
|
||||
week3Play = max;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
/**
|
||||
* Static method class for single item store queries.
|
||||
*
|
||||
|
@ -211,7 +213,7 @@ public class DataStoreQueries {
|
|||
*/
|
||||
public static Executable updatePlayerName(UUID playerUUID, String playerName) {
|
||||
String sql = "UPDATE " + UsersTable.TABLE_NAME + " SET " + UsersTable.USER_NAME + "=?" +
|
||||
" WHERE " + UsersTable.USER_UUID + "=?";
|
||||
WHERE + UsersTable.USER_UUID + "=?";
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Static method class for queries that use large amount of memory.
|
||||
*
|
||||
|
@ -46,14 +48,14 @@ public class LargeFetchQueries {
|
|||
* @return Multi map: Server UUID - (Command name - Usage count)
|
||||
*/
|
||||
public static Query<Map<UUID, Map<String, Integer>>> fetchAllCommandUsageData() {
|
||||
String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_ID;
|
||||
String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_UUID + " as s_uuid";
|
||||
String sql = "SELECT " +
|
||||
CommandUseTable.COMMAND + ", " +
|
||||
CommandUseTable.TIMES_USED + ", " +
|
||||
String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
|
||||
String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
|
||||
String sql = SELECT +
|
||||
CommandUseTable.COMMAND + ',' +
|
||||
CommandUseTable.TIMES_USED + ',' +
|
||||
serverUUIDColumn +
|
||||
" FROM " + CommandUseTable.TABLE_NAME +
|
||||
" INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + CommandUseTable.SERVER_ID;
|
||||
FROM + CommandUseTable.TABLE_NAME +
|
||||
INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + CommandUseTable.SERVER_ID;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, Map<String, Integer>>>(sql, 10000) {
|
||||
@Override
|
||||
|
@ -81,20 +83,20 @@ public class LargeFetchQueries {
|
|||
* @return Map: Server UUID - List of TPS data
|
||||
*/
|
||||
public static Query<Map<UUID, List<TPS>>> fetchAllTPSData() {
|
||||
String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_ID;
|
||||
String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_UUID + " as s_uuid";
|
||||
String sql = "SELECT " +
|
||||
TPSTable.DATE + ", " +
|
||||
TPSTable.TPS + ", " +
|
||||
TPSTable.PLAYERS_ONLINE + ", " +
|
||||
TPSTable.CPU_USAGE + ", " +
|
||||
TPSTable.RAM_USAGE + ", " +
|
||||
TPSTable.ENTITIES + ", " +
|
||||
TPSTable.CHUNKS + ", " +
|
||||
TPSTable.FREE_DISK + ", " +
|
||||
String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
|
||||
String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
|
||||
String sql = SELECT +
|
||||
TPSTable.DATE + ',' +
|
||||
TPSTable.TPS + ',' +
|
||||
TPSTable.PLAYERS_ONLINE + ',' +
|
||||
TPSTable.CPU_USAGE + ',' +
|
||||
TPSTable.RAM_USAGE + ',' +
|
||||
TPSTable.ENTITIES + ',' +
|
||||
TPSTable.CHUNKS + ',' +
|
||||
TPSTable.FREE_DISK + ',' +
|
||||
serverUUIDColumn +
|
||||
" FROM " + TPSTable.TABLE_NAME +
|
||||
" INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
|
||||
FROM + TPSTable.TABLE_NAME +
|
||||
INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, List<TPS>>>(sql, 50000) {
|
||||
@Override
|
||||
|
@ -130,7 +132,7 @@ public class LargeFetchQueries {
|
|||
* @return Map: Server UUID - List of world names
|
||||
*/
|
||||
public static Query<Map<UUID, Collection<String>>> fetchAllWorldNames() {
|
||||
String sql = "SELECT * FROM " + WorldTable.TABLE_NAME;
|
||||
String sql = SELECT + '*' + FROM + WorldTable.TABLE_NAME;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, Collection<String>>>(sql, 1000) {
|
||||
@Override
|
||||
|
|
|
@ -51,7 +51,7 @@ public class PerServerAggregateQueries {
|
|||
* @return Map: Server UUID - Last seen epoch ms.
|
||||
*/
|
||||
public static Query<Map<UUID, Long>> lastSeenOnServers(UUID playerUUID) {
|
||||
String sql = "SELECT MAX(" + SessionsTable.SESSION_END + ") as last_seen, " +
|
||||
String sql = SELECT + "MAX(" + SessionsTable.SESSION_END + ") as last_seen, " +
|
||||
SessionsTable.SERVER_UUID +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.USER_UUID + "=?" +
|
||||
|
@ -82,26 +82,10 @@ public class PerServerAggregateQueries {
|
|||
* @return Map: Server UUID - Player kill count
|
||||
*/
|
||||
public static Query<Map<UUID, Integer>> playerKillCountOnServers(UUID playerUUID) {
|
||||
String sql = "SELECT COUNT(1) as kill_count, " + KillsTable.SERVER_UUID + FROM + KillsTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as kill_count, " + KillsTable.SERVER_UUID + FROM + KillsTable.TABLE_NAME +
|
||||
WHERE + KillsTable.KILLER_UUID + "=?" +
|
||||
GROUP_BY + KillsTable.SERVER_UUID;
|
||||
return new QueryStatement<Map<UUID, Integer>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Integer> killCountMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(SessionsTable.SERVER_UUID));
|
||||
int lastSeen = set.getInt("kill_count");
|
||||
killCountMap.put(serverUUID, lastSeen);
|
||||
}
|
||||
return killCountMap;
|
||||
}
|
||||
};
|
||||
return getQueryForCountOf(playerUUID, sql, "kill_count");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,27 +95,11 @@ public class PerServerAggregateQueries {
|
|||
* @return Map: Server UUID - Mob kill count
|
||||
*/
|
||||
public static Query<Map<UUID, Integer>> mobKillCountOnServers(UUID playerUUID) {
|
||||
String sql = "SELECT SUM(" + SessionsTable.MOB_KILLS + ") as kill_count, " +
|
||||
String sql = SELECT + "SUM(" + SessionsTable.MOB_KILLS + ") as kill_count, " +
|
||||
SessionsTable.SERVER_UUID + FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.USER_UUID + "=?" +
|
||||
GROUP_BY + SessionsTable.SERVER_UUID;
|
||||
return new QueryStatement<Map<UUID, Integer>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Integer> killCountMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(SessionsTable.SERVER_UUID));
|
||||
int lastSeen = set.getInt("kill_count");
|
||||
killCountMap.put(serverUUID, lastSeen);
|
||||
}
|
||||
return killCountMap;
|
||||
}
|
||||
};
|
||||
return getQueryForCountOf(playerUUID, sql, "kill_count");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,33 +109,22 @@ public class PerServerAggregateQueries {
|
|||
* @return Map: Server UUID - Mob kill count
|
||||
*/
|
||||
public static Query<Map<UUID, Integer>> playerDeathCountOnServers(UUID playerUUID) {
|
||||
String sql = "SELECT COUNT(1) as death_count, " + KillsTable.SERVER_UUID + FROM + KillsTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as death_count, " + KillsTable.SERVER_UUID + FROM + KillsTable.TABLE_NAME +
|
||||
WHERE + KillsTable.VICTIM_UUID + "=?" +
|
||||
GROUP_BY + KillsTable.SERVER_UUID;
|
||||
return new QueryStatement<Map<UUID, Integer>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Integer> killCountMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(SessionsTable.SERVER_UUID));
|
||||
int lastSeen = set.getInt("death_count");
|
||||
killCountMap.put(serverUUID, lastSeen);
|
||||
}
|
||||
return killCountMap;
|
||||
}
|
||||
};
|
||||
return getQueryForCountOf(playerUUID, sql, "death_count");
|
||||
}
|
||||
|
||||
public static Query<Map<UUID, Integer>> totalDeathCountOnServers(UUID playerUUID) {
|
||||
String sql = "SELECT SUM(" + SessionsTable.DEATHS + ") as death_count, " +
|
||||
String sql = SELECT + "SUM(" + SessionsTable.DEATHS + ") as death_count, " +
|
||||
SessionsTable.SERVER_UUID + FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.USER_UUID + "=?" +
|
||||
GROUP_BY + SessionsTable.SERVER_UUID;
|
||||
return getQueryForCountOf(playerUUID, sql, "death_count");
|
||||
}
|
||||
|
||||
|
||||
private static QueryStatement<Map<UUID, Integer>> getQueryForCountOf(UUID playerUUID, String sql, String column) {
|
||||
return new QueryStatement<Map<UUID, Integer>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -179,12 +136,11 @@ public class PerServerAggregateQueries {
|
|||
Map<UUID, Integer> killCountMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(SessionsTable.SERVER_UUID));
|
||||
int lastSeen = set.getInt("death_count");
|
||||
killCountMap.put(serverUUID, lastSeen);
|
||||
int count = set.getInt(column);
|
||||
killCountMap.put(serverUUID, count);
|
||||
}
|
||||
return killCountMap;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -48,7 +48,7 @@ public class PlayerFetchQueries {
|
|||
* @return Optional, Name if found.
|
||||
*/
|
||||
public static Query<Optional<String>> playerUserName(UUID playerUUID) {
|
||||
String sql = "SELECT " + UsersTable.USER_NAME +
|
||||
String sql = SELECT + UsersTable.USER_NAME +
|
||||
FROM + UsersTable.TABLE_NAME +
|
||||
WHERE + UsersTable.USER_UUID + "=?";
|
||||
return new QueryStatement<Optional<String>>(sql) {
|
||||
|
@ -74,7 +74,8 @@ public class PlayerFetchQueries {
|
|||
* @return True if the player's BaseUser is found
|
||||
*/
|
||||
public static Query<Boolean> isPlayerRegistered(UUID playerUUID) {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + UsersTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + UsersTable.TABLE_NAME +
|
||||
WHERE + UsersTable.USER_UUID + "=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
|
@ -92,7 +93,8 @@ public class PlayerFetchQueries {
|
|||
* @return True if the player's UserInfo is found
|
||||
*/
|
||||
public static Query<Boolean> isPlayerRegisteredOnServer(UUID playerUUID, UUID serverUUID) {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + UserInfoTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + UserInfoTable.TABLE_NAME +
|
||||
WHERE + UserInfoTable.USER_UUID + "=?" +
|
||||
AND + UserInfoTable.SERVER_UUID + "=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
|
@ -103,5 +105,4 @@ public class PlayerFetchQueries {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -47,7 +47,7 @@ public class ServerAggregateQueries {
|
|||
* @return Count of base users, all users in a network after Plan installation.
|
||||
*/
|
||||
public static Query<Integer> baseUserCount() {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + UsersTable.TABLE_NAME;
|
||||
String sql = SELECT + "COUNT(1) as c FROM " + UsersTable.TABLE_NAME;
|
||||
return new QueryAllStatement<Integer>(sql) {
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
|
@ -63,7 +63,7 @@ public class ServerAggregateQueries {
|
|||
* @return Count of users registered to that server after Plan installation.
|
||||
*/
|
||||
public static Query<Integer> serverUserCount(UUID serverUUID) {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + UserInfoTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as c FROM " + UserInfoTable.TABLE_NAME +
|
||||
WHERE + UserInfoTable.SERVER_UUID + "=?";
|
||||
return new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
|
@ -87,7 +87,7 @@ public class ServerAggregateQueries {
|
|||
* @return Map: Server UUID - Count of users registered to that server
|
||||
*/
|
||||
public static Query<Map<UUID, Integer>> serverUserCounts() {
|
||||
String sql = "SELECT COUNT(1) as c, " + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME +
|
||||
String sql = SELECT + "COUNT(1) as c, " + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME +
|
||||
GROUP_BY + UserInfoTable.SERVER_UUID;
|
||||
return new QueryAllStatement<Map<UUID, Integer>>(sql, 100) {
|
||||
@Override
|
||||
|
@ -110,7 +110,7 @@ public class ServerAggregateQueries {
|
|||
* @return Map: Lowercase used command - Count of use times.
|
||||
*/
|
||||
public static Query<Map<String, Integer>> commandUsageCounts(UUID serverUUID) {
|
||||
String sql = SELECT + CommandUseTable.COMMAND + ", " + CommandUseTable.TIMES_USED + FROM + CommandUseTable.TABLE_NAME +
|
||||
String sql = SELECT + CommandUseTable.COMMAND + ',' + CommandUseTable.TIMES_USED + FROM + CommandUseTable.TABLE_NAME +
|
||||
WHERE + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID;
|
||||
|
||||
return new QueryStatement<Map<String, Integer>>(sql, 5000) {
|
||||
|
@ -134,17 +134,17 @@ public class ServerAggregateQueries {
|
|||
|
||||
public static Query<Map<String, Integer>> networkGeolocationCounts() {
|
||||
String subQuery1 = SELECT +
|
||||
GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.GEOLOCATION + ',' +
|
||||
GeoInfoTable.LAST_USED +
|
||||
FROM + GeoInfoTable.TABLE_NAME;
|
||||
String subQuery2 = SELECT +
|
||||
GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
"MAX(" + GeoInfoTable.LAST_USED + ") as m" +
|
||||
FROM + GeoInfoTable.TABLE_NAME +
|
||||
GROUP_BY + GeoInfoTable.USER_UUID;
|
||||
String sql = SELECT + GeoInfoTable.GEOLOCATION + ", COUNT(1) as c FROM (" +
|
||||
"(" + subQuery1 + ") AS q1" +
|
||||
'(' + subQuery1 + ") AS q1" +
|
||||
" INNER JOIN (" + subQuery2 + ") AS q2 ON q1.uuid = q2.uuid)" +
|
||||
WHERE + GeoInfoTable.LAST_USED + "=m" +
|
||||
GROUP_BY + GeoInfoTable.GEOLOCATION;
|
||||
|
|
|
@ -32,6 +32,8 @@ import java.util.HashSet;
|
|||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link BaseUser} objects.
|
||||
*
|
||||
|
@ -56,20 +58,24 @@ public class BaseUserQueries {
|
|||
return new QueryAllStatement<Collection<BaseUser>>(sql, 20000) {
|
||||
@Override
|
||||
public Collection<BaseUser> processResults(ResultSet set) throws SQLException {
|
||||
Collection<BaseUser> users = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
|
||||
String name = set.getString(UsersTable.USER_NAME);
|
||||
long registered = set.getLong(UsersTable.REGISTERED);
|
||||
int kicked = set.getInt(UsersTable.TIMES_KICKED);
|
||||
|
||||
users.add(new BaseUser(playerUUID, name, registered, kicked));
|
||||
}
|
||||
return users;
|
||||
return extractBaseUsers(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Collection<BaseUser> extractBaseUsers(ResultSet set) throws SQLException {
|
||||
Collection<BaseUser> users = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
|
||||
String name = set.getString(UsersTable.USER_NAME);
|
||||
long registered = set.getLong(UsersTable.REGISTERED);
|
||||
int kicked = set.getInt(UsersTable.TIMES_KICKED);
|
||||
|
||||
users.add(new BaseUser(playerUUID, name, registered, kicked));
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query database for common user information of a player.
|
||||
* <p>
|
||||
|
@ -113,15 +119,15 @@ public class BaseUserQueries {
|
|||
* @return Collection: BaseUsers
|
||||
*/
|
||||
public static Query<Collection<BaseUser>> fetchServerBaseUsers(UUID serverUUID) {
|
||||
String sql = "SELECT " +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + ", " +
|
||||
UsersTable.USER_NAME + ", " +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.REGISTERED + ", " +
|
||||
String sql = SELECT +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + ',' +
|
||||
UsersTable.USER_NAME + ',' +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.REGISTERED + ',' +
|
||||
UsersTable.TIMES_KICKED +
|
||||
" FROM " + UsersTable.TABLE_NAME +
|
||||
" INNER JOIN " + UserInfoTable.TABLE_NAME + " on " +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + "." + UserInfoTable.USER_UUID +
|
||||
" WHERE " + UserInfoTable.SERVER_UUID + "=?";
|
||||
FROM + UsersTable.TABLE_NAME +
|
||||
INNER_JOIN + UserInfoTable.TABLE_NAME + " on " +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID +
|
||||
WHERE + UserInfoTable.SERVER_UUID + "=?";
|
||||
return new QueryStatement<Collection<BaseUser>>(sql, 1000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -130,16 +136,7 @@ public class BaseUserQueries {
|
|||
|
||||
@Override
|
||||
public Collection<BaseUser> processResults(ResultSet set) throws SQLException {
|
||||
Collection<BaseUser> users = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
|
||||
String name = set.getString(UsersTable.USER_NAME);
|
||||
long registered = set.getLong(UsersTable.REGISTERED);
|
||||
int kicked = set.getInt(UsersTable.TIMES_KICKED);
|
||||
|
||||
users.add(new BaseUser(playerUUID, name, registered, kicked));
|
||||
}
|
||||
return users;
|
||||
return extractBaseUsers(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link com.djrapitops.plan.data.container.GeoInfo} objects.
|
||||
*
|
||||
|
@ -45,34 +47,38 @@ public class GeoInfoQueries {
|
|||
* @return Map: Player UUID - List of GeoInfo
|
||||
*/
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInformation() {
|
||||
String sql = "SELECT " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
String sql = SELECT +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.GEOLOCATION + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.USER_UUID +
|
||||
" FROM " + GeoInfoTable.TABLE_NAME;
|
||||
FROM + GeoInfoTable.TABLE_NAME;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, List<GeoInfo>>>(sql, 50000) {
|
||||
@Override
|
||||
public Map<UUID, List<GeoInfo>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<GeoInfo>> geoInformation = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(GeoInfoTable.USER_UUID));
|
||||
|
||||
List<GeoInfo> userGeoInfo = geoInformation.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
|
||||
geoInformation.put(uuid, userGeoInfo);
|
||||
}
|
||||
return geoInformation;
|
||||
return extractGeoInformation(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Map<UUID, List<GeoInfo>> extractGeoInformation(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<GeoInfo>> geoInformation = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(GeoInfoTable.USER_UUID));
|
||||
|
||||
List<GeoInfo> userGeoInfo = geoInformation.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
|
||||
geoInformation.put(uuid, userGeoInfo);
|
||||
}
|
||||
return geoInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Player's GeoInfo by player's UUID.
|
||||
*
|
||||
|
@ -80,8 +86,8 @@ public class GeoInfoQueries {
|
|||
* @return List of {@link GeoInfo}, empty if none are found.
|
||||
*/
|
||||
public static Query<List<GeoInfo>> fetchPlayerGeoInformation(UUID playerUUID) {
|
||||
String sql = "SELECT DISTINCT * FROM " + GeoInfoTable.TABLE_NAME +
|
||||
" WHERE " + GeoInfoTable.USER_UUID + "=?";
|
||||
String sql = SELECT + DISTINCT + '*' + FROM + GeoInfoTable.TABLE_NAME +
|
||||
WHERE + GeoInfoTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<List<GeoInfo>>(sql, 100) {
|
||||
@Override
|
||||
|
@ -104,14 +110,14 @@ public class GeoInfoQueries {
|
|||
}
|
||||
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchServerGeoInformation(UUID serverUUID) {
|
||||
String sql = "SELECT " + GeoInfoTable.TABLE_NAME + "." + GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
String sql = SELECT + GeoInfoTable.TABLE_NAME + '.' + GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.GEOLOCATION + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.IP +
|
||||
" FROM " + GeoInfoTable.TABLE_NAME +
|
||||
" INNER JOIN " + UserInfoTable.TABLE_NAME + " on " +
|
||||
GeoInfoTable.TABLE_NAME + "." + GeoInfoTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + "." + UserInfoTable.USER_UUID +
|
||||
" WHERE " + UserInfoTable.SERVER_UUID + "=?";
|
||||
FROM + GeoInfoTable.TABLE_NAME +
|
||||
INNER_JOIN + UserInfoTable.TABLE_NAME + " on " +
|
||||
GeoInfoTable.TABLE_NAME + '.' + GeoInfoTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID +
|
||||
WHERE + UserInfoTable.SERVER_UUID + "=?";
|
||||
return new QueryStatement<Map<UUID, List<GeoInfo>>>(sql, 10000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -120,20 +126,7 @@ public class GeoInfoQueries {
|
|||
|
||||
@Override
|
||||
public Map<UUID, List<GeoInfo>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<GeoInfo>> geoInformation = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(GeoInfoTable.USER_UUID));
|
||||
|
||||
List<GeoInfo> userGeoInfo = geoInformation.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
|
||||
geoInformation.put(uuid, userGeoInfo);
|
||||
}
|
||||
return geoInformation;
|
||||
return extractGeoInformation(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Optional;
|
|||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
import static com.djrapitops.plan.db.sql.tables.SettingsTable.*;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +37,9 @@ import static com.djrapitops.plan.db.sql.tables.SettingsTable.*;
|
|||
*/
|
||||
public class NewerConfigQuery extends QueryStatement<Optional<Config>> {
|
||||
|
||||
private static final String SELECT_STATEMENT = "SELECT " + CONFIG_CONTENT + " FROM " + TABLE_NAME +
|
||||
" WHERE " + UPDATED + ">? AND " +
|
||||
SERVER_UUID + "=? LIMIT 1";
|
||||
private static final String SELECT_STATEMENT = SELECT + CONFIG_CONTENT + FROM + TABLE_NAME +
|
||||
WHERE + UPDATED + ">?" +
|
||||
AND + SERVER_UUID + "=? LIMIT 1";
|
||||
|
||||
private final UUID serverUUID;
|
||||
private final long updatedAfter;
|
||||
|
|
|
@ -47,9 +47,9 @@ public class NicknameQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
|
||||
String sql = SELECT +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.LAST_USED + ", " +
|
||||
NicknamesTable.USER_UUID + ", " +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED + ',' +
|
||||
NicknamesTable.USER_UUID + ',' +
|
||||
NicknamesTable.SERVER_UUID +
|
||||
FROM + NicknamesTable.TABLE_NAME;
|
||||
|
||||
|
@ -79,16 +79,16 @@ public class NicknameQueries {
|
|||
}
|
||||
|
||||
public static Query<Optional<Nickname>> fetchLastSeenNicknameOfPlayer(UUID playerUUID, UUID serverUUID) {
|
||||
String subQuery = "SELECT MAX(" + NicknamesTable.LAST_USED + ") FROM " + NicknamesTable.TABLE_NAME +
|
||||
String subQuery = SELECT + "MAX(" + NicknamesTable.LAST_USED + ") FROM " + NicknamesTable.TABLE_NAME +
|
||||
WHERE + NicknamesTable.USER_UUID + "=?" +
|
||||
AND + NicknamesTable.SERVER_UUID + "=?" +
|
||||
GROUP_BY + NicknamesTable.USER_UUID;
|
||||
String sql = SELECT +
|
||||
NicknamesTable.LAST_USED + ", " + NicknamesTable.NICKNAME +
|
||||
NicknamesTable.LAST_USED + ',' + NicknamesTable.NICKNAME +
|
||||
FROM + NicknamesTable.TABLE_NAME +
|
||||
WHERE + NicknamesTable.USER_UUID + "=?" +
|
||||
AND + NicknamesTable.SERVER_UUID + "=?" +
|
||||
AND + NicknamesTable.LAST_USED + "=(" + subQuery + ")";
|
||||
AND + NicknamesTable.LAST_USED + "=(" + subQuery + ')';
|
||||
return new QueryStatement<Optional<Nickname>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -114,8 +114,8 @@ public class NicknameQueries {
|
|||
|
||||
public static Query<List<Nickname>> fetchNicknameDataOfPlayer(UUID playerUUID) {
|
||||
String sql = SELECT +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.LAST_USED + ", " +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED + ',' +
|
||||
NicknamesTable.SERVER_UUID +
|
||||
FROM + NicknamesTable.TABLE_NAME +
|
||||
WHERE + NicknamesTable.USER_UUID + "=?";
|
||||
|
@ -147,9 +147,9 @@ public class NicknameQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, List<Nickname>>> fetchAllNicknameDataByPlayerUUIDs() {
|
||||
String sql = SELECT +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.LAST_USED + ", " +
|
||||
NicknamesTable.USER_UUID + ", " +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED + ',' +
|
||||
NicknamesTable.USER_UUID + ',' +
|
||||
NicknamesTable.SERVER_UUID +
|
||||
FROM + NicknamesTable.TABLE_NAME;
|
||||
return new QueryAllStatement<Map<UUID, List<Nickname>>>(sql, 5000) {
|
||||
|
@ -177,9 +177,9 @@ public class NicknameQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, List<Nickname>>> fetchNicknameDataOfServer(UUID serverUUID) {
|
||||
String sql = SELECT +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.LAST_USED + ", " +
|
||||
NicknamesTable.USER_UUID + ", " +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED + ',' +
|
||||
NicknamesTable.USER_UUID + ',' +
|
||||
NicknamesTable.SERVER_UUID +
|
||||
FROM + NicknamesTable.TABLE_NAME +
|
||||
WHERE + NicknamesTable.SERVER_UUID + "=?";
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link WebUser} objects.
|
||||
*
|
||||
|
@ -45,40 +47,44 @@ public class PingQueries {
|
|||
* @return Map: Player UUID - List of ping data.
|
||||
*/
|
||||
public static Query<Map<UUID, List<Ping>>> fetchAllPingData() {
|
||||
String sql = "SELECT " +
|
||||
PingTable.DATE + ", " +
|
||||
PingTable.MAX_PING + ", " +
|
||||
PingTable.MIN_PING + ", " +
|
||||
PingTable.AVG_PING + ", " +
|
||||
PingTable.USER_UUID + ", " +
|
||||
String sql = SELECT +
|
||||
PingTable.DATE + ',' +
|
||||
PingTable.MAX_PING + ',' +
|
||||
PingTable.MIN_PING + ',' +
|
||||
PingTable.AVG_PING + ',' +
|
||||
PingTable.USER_UUID + ',' +
|
||||
PingTable.SERVER_UUID +
|
||||
" FROM " + PingTable.TABLE_NAME;
|
||||
FROM + PingTable.TABLE_NAME;
|
||||
return new QueryAllStatement<Map<UUID, List<Ping>>>(sql, 100000) {
|
||||
@Override
|
||||
public Map<UUID, List<Ping>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<Ping>> userPings = new HashMap<>();
|
||||
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
|
||||
UUID serverUUID = UUID.fromString(set.getString(PingTable.SERVER_UUID));
|
||||
long date = set.getLong(PingTable.DATE);
|
||||
double avgPing = set.getDouble(PingTable.AVG_PING);
|
||||
int minPing = set.getInt(PingTable.MIN_PING);
|
||||
int maxPing = set.getInt(PingTable.MAX_PING);
|
||||
|
||||
List<Ping> pings = userPings.getOrDefault(uuid, new ArrayList<>());
|
||||
pings.add(new Ping(date, serverUUID,
|
||||
minPing,
|
||||
maxPing,
|
||||
avgPing));
|
||||
userPings.put(uuid, pings);
|
||||
}
|
||||
|
||||
return userPings;
|
||||
return extractUserPings(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Map<UUID, List<Ping>> extractUserPings(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<Ping>> userPings = new HashMap<>();
|
||||
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
|
||||
UUID serverUUID = UUID.fromString(set.getString(PingTable.SERVER_UUID));
|
||||
long date = set.getLong(PingTable.DATE);
|
||||
double avgPing = set.getDouble(PingTable.AVG_PING);
|
||||
int minPing = set.getInt(PingTable.MIN_PING);
|
||||
int maxPing = set.getInt(PingTable.MAX_PING);
|
||||
|
||||
List<Ping> pings = userPings.getOrDefault(uuid, new ArrayList<>());
|
||||
pings.add(new Ping(date, serverUUID,
|
||||
minPing,
|
||||
maxPing,
|
||||
avgPing));
|
||||
userPings.put(uuid, pings);
|
||||
}
|
||||
|
||||
return userPings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query database for Ping data of a specific player.
|
||||
*
|
||||
|
@ -86,8 +92,8 @@ public class PingQueries {
|
|||
* @return List of Ping entries for this player.
|
||||
*/
|
||||
public static Query<List<Ping>> fetchPingDataOfPlayer(UUID playerUUID) {
|
||||
String sql = "SELECT * FROM " + PingTable.TABLE_NAME +
|
||||
" WHERE " + PingTable.USER_UUID + "=?";
|
||||
String sql = SELECT + '*' + FROM + PingTable.TABLE_NAME +
|
||||
WHERE + PingTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<List<Ping>>(sql, 10000) {
|
||||
@Override
|
||||
|
@ -116,15 +122,15 @@ public class PingQueries {
|
|||
}
|
||||
|
||||
public static Query<Map<UUID, List<Ping>>> fetchPingDataOfServer(UUID serverUUID) {
|
||||
String sql = "SELECT " +
|
||||
PingTable.DATE + ", " +
|
||||
PingTable.MAX_PING + ", " +
|
||||
PingTable.MIN_PING + ", " +
|
||||
PingTable.AVG_PING + ", " +
|
||||
PingTable.USER_UUID + ", " +
|
||||
String sql = SELECT +
|
||||
PingTable.DATE + ',' +
|
||||
PingTable.MAX_PING + ',' +
|
||||
PingTable.MIN_PING + ',' +
|
||||
PingTable.AVG_PING + ',' +
|
||||
PingTable.USER_UUID + ',' +
|
||||
PingTable.SERVER_UUID +
|
||||
" FROM " + PingTable.TABLE_NAME +
|
||||
" WHERE " + PingTable.SERVER_UUID + "=?";
|
||||
FROM + PingTable.TABLE_NAME +
|
||||
WHERE + PingTable.SERVER_UUID + "=?";
|
||||
return new QueryStatement<Map<UUID, List<Ping>>>(sql, 100000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -133,25 +139,7 @@ public class PingQueries {
|
|||
|
||||
@Override
|
||||
public Map<UUID, List<Ping>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<Ping>> userPings = new HashMap<>();
|
||||
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
|
||||
UUID serverUUID = UUID.fromString(set.getString(PingTable.SERVER_UUID));
|
||||
long date = set.getLong(PingTable.DATE);
|
||||
double avgPing = set.getDouble(PingTable.AVG_PING);
|
||||
int minPing = set.getInt(PingTable.MIN_PING);
|
||||
int maxPing = set.getInt(PingTable.MAX_PING);
|
||||
|
||||
List<Ping> pings = userPings.getOrDefault(uuid, new ArrayList<>());
|
||||
pings.add(new Ping(date, serverUUID,
|
||||
minPing,
|
||||
maxPing,
|
||||
avgPing));
|
||||
userPings.put(uuid, pings);
|
||||
}
|
||||
|
||||
return userPings;
|
||||
return extractUserPings(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link com.djrapitops.plan.system.info.server.Server} objects.
|
||||
*
|
||||
|
@ -46,7 +48,7 @@ public class ServerQueries {
|
|||
* @return Map: Server UUID - Plan Server Information
|
||||
*/
|
||||
public static Query<Map<UUID, Server>> fetchPlanServerInformation() {
|
||||
String sql = "SELECT * FROM " + ServerTable.TABLE_NAME + " WHERE " + ServerTable.INSTALLED + "=?";
|
||||
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?";
|
||||
|
||||
return new QueryStatement<Map<UUID, Server>>(sql, 100) {
|
||||
@Override
|
||||
|
@ -80,11 +82,11 @@ public class ServerQueries {
|
|||
}
|
||||
|
||||
public static Query<Optional<Server>> fetchServerMatchingIdentifier(String identifier) {
|
||||
String sql = "SELECT * FROM " + ServerTable.TABLE_NAME +
|
||||
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME +
|
||||
" WHERE (LOWER(" + ServerTable.SERVER_UUID + ") LIKE LOWER(?)" +
|
||||
" OR LOWER(" + ServerTable.NAME + ") LIKE LOWER(?)" +
|
||||
" OR " + ServerTable.SERVER_ID + "=?)" +
|
||||
" AND " + ServerTable.INSTALLED + "=?" +
|
||||
OR + "LOWER(" + ServerTable.NAME + ") LIKE LOWER(?)" +
|
||||
OR + ServerTable.SERVER_ID + "=?)" +
|
||||
AND + ServerTable.INSTALLED + "=?" +
|
||||
" LIMIT 1";
|
||||
return new QueryStatement<Optional<Server>>(sql) {
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.sql.SQLException;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link com.djrapitops.plan.data.container.Session} objects.
|
||||
|
@ -48,31 +48,31 @@ public class SessionQueries {
|
|||
/* Static method class */
|
||||
}
|
||||
|
||||
private static final String SELECT_SESSIONS_STATEMENT = "SELECT " +
|
||||
SessionsTable.TABLE_NAME + "." + SessionsTable.ID + ", " +
|
||||
SessionsTable.TABLE_NAME + "." + SessionsTable.USER_UUID + ", " +
|
||||
SessionsTable.TABLE_NAME + "." + SessionsTable.SERVER_UUID + ", " +
|
||||
SessionsTable.SESSION_START + ", " +
|
||||
SessionsTable.SESSION_END + ", " +
|
||||
SessionsTable.MOB_KILLS + ", " +
|
||||
SessionsTable.DEATHS + ", " +
|
||||
SessionsTable.AFK_TIME + ", " +
|
||||
WorldTimesTable.SURVIVAL + ", " +
|
||||
WorldTimesTable.CREATIVE + ", " +
|
||||
WorldTimesTable.ADVENTURE + ", " +
|
||||
WorldTimesTable.SPECTATOR + ", " +
|
||||
WorldTable.NAME + ", " +
|
||||
KillsTable.VICTIM_UUID + ", " +
|
||||
private static final String SELECT_SESSIONS_STATEMENT = SELECT +
|
||||
SessionsTable.TABLE_NAME + '.' + SessionsTable.ID + ',' +
|
||||
SessionsTable.TABLE_NAME + '.' + SessionsTable.USER_UUID + ',' +
|
||||
SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID + ',' +
|
||||
SessionsTable.SESSION_START + ',' +
|
||||
SessionsTable.SESSION_END + ',' +
|
||||
SessionsTable.MOB_KILLS + ',' +
|
||||
SessionsTable.DEATHS + ',' +
|
||||
SessionsTable.AFK_TIME + ',' +
|
||||
WorldTimesTable.SURVIVAL + ',' +
|
||||
WorldTimesTable.CREATIVE + ',' +
|
||||
WorldTimesTable.ADVENTURE + ',' +
|
||||
WorldTimesTable.SPECTATOR + ',' +
|
||||
WorldTable.NAME + ',' +
|
||||
KillsTable.VICTIM_UUID + ',' +
|
||||
UsersTable.USER_NAME + " as victim_name, " +
|
||||
KillsTable.DATE + ", " +
|
||||
KillsTable.DATE + ',' +
|
||||
KillsTable.WEAPON +
|
||||
" FROM " + SessionsTable.TABLE_NAME +
|
||||
" LEFT JOIN " + KillsTable.TABLE_NAME + " ON " + SessionsTable.TABLE_NAME + "." + SessionsTable.ID + "=" + KillsTable.TABLE_NAME + "." + KillsTable.SESSION_ID +
|
||||
" LEFT JOIN " + UsersTable.TABLE_NAME + " on " + UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + "=" + KillsTable.VICTIM_UUID +
|
||||
" INNER JOIN " + WorldTimesTable.TABLE_NAME + " ON " + SessionsTable.TABLE_NAME + "." + SessionsTable.ID + "=" + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SESSION_ID +
|
||||
" INNER JOIN " + WorldTable.TABLE_NAME + " ON " + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.WORLD_ID + "=" + WorldTable.TABLE_NAME + "." + WorldTable.ID;
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
LEFT_JOIN + KillsTable.TABLE_NAME + " ON " + SessionsTable.TABLE_NAME + '.' + SessionsTable.ID + "=" + KillsTable.TABLE_NAME + '.' + KillsTable.SESSION_ID +
|
||||
LEFT_JOIN + UsersTable.TABLE_NAME + " on " + UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + "=" + KillsTable.VICTIM_UUID +
|
||||
INNER_JOIN + WorldTimesTable.TABLE_NAME + " ON " + SessionsTable.TABLE_NAME + '.' + SessionsTable.ID + "=" + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SESSION_ID +
|
||||
INNER_JOIN + WorldTable.TABLE_NAME + " ON " + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.WORLD_ID + "=" + WorldTable.TABLE_NAME + '.' + WorldTable.ID;
|
||||
|
||||
private static final String ORDER_BY_SESSION_START_DESC = " ORDER BY " + SessionsTable.SESSION_START + " DESC";
|
||||
private static final String ORDER_BY_SESSION_START_DESC = ORDER_BY + SessionsTable.SESSION_START + " DESC";
|
||||
|
||||
/**
|
||||
* Query the database for Session data without kill, death or world data.
|
||||
|
@ -80,16 +80,16 @@ public class SessionQueries {
|
|||
* @return Multimap: Server UUID - (Player UUID - List of sessions)
|
||||
*/
|
||||
public static Query<Map<UUID, Map<UUID, List<Session>>>> fetchAllSessionsWithoutKillOrWorldData() {
|
||||
String sql = "SELECT " +
|
||||
SessionsTable.ID + ", " +
|
||||
SessionsTable.USER_UUID + ", " +
|
||||
SessionsTable.SERVER_UUID + ", " +
|
||||
SessionsTable.SESSION_START + ", " +
|
||||
SessionsTable.SESSION_END + ", " +
|
||||
SessionsTable.DEATHS + ", " +
|
||||
SessionsTable.MOB_KILLS + ", " +
|
||||
String sql = SELECT +
|
||||
SessionsTable.ID + ',' +
|
||||
SessionsTable.USER_UUID + ',' +
|
||||
SessionsTable.SERVER_UUID + ',' +
|
||||
SessionsTable.SESSION_START + ',' +
|
||||
SessionsTable.SESSION_END + ',' +
|
||||
SessionsTable.DEATHS + ',' +
|
||||
SessionsTable.MOB_KILLS + ',' +
|
||||
SessionsTable.AFK_TIME +
|
||||
" FROM " + SessionsTable.TABLE_NAME;
|
||||
FROM + SessionsTable.TABLE_NAME;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) {
|
||||
@Override
|
||||
|
@ -145,7 +145,7 @@ public class SessionQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, List<Session>>> fetchSessionsOfServer(UUID serverUUID) {
|
||||
String sql = SELECT_SESSIONS_STATEMENT +
|
||||
WHERE + SessionsTable.TABLE_NAME + "." + SessionsTable.SERVER_UUID + "=?" +
|
||||
WHERE + SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID + "=?" +
|
||||
ORDER_BY_SESSION_START_DESC;
|
||||
return new QueryStatement<Map<UUID, List<Session>>>(sql, 50000) {
|
||||
@Override
|
||||
|
@ -169,7 +169,7 @@ public class SessionQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, List<Session>>> fetchSessionsOfPlayer(UUID playerUUID) {
|
||||
String sql = SELECT_SESSIONS_STATEMENT +
|
||||
WHERE + SessionsTable.TABLE_NAME + "." + SessionsTable.USER_UUID + "=?" +
|
||||
WHERE + SessionsTable.TABLE_NAME + '.' + SessionsTable.USER_UUID + "=?" +
|
||||
ORDER_BY_SESSION_START_DESC;
|
||||
return new QueryStatement<Map<UUID, List<Session>>>(sql, 50000) {
|
||||
@Override
|
||||
|
|
|
@ -87,14 +87,14 @@ public class TPSQueries {
|
|||
}
|
||||
|
||||
TextStringBuilder sql = new TextStringBuilder(SELECT);
|
||||
sql.append(SERVER_ID).append(", ")
|
||||
.append(DATE).append(", ")
|
||||
sql.append(SERVER_ID).append(',')
|
||||
.append(DATE).append(',')
|
||||
.append(PLAYERS_ONLINE)
|
||||
.append(FROM).append(TABLE_NAME)
|
||||
.append(WHERE).append(DATE).append(">").append(System.currentTimeMillis() - TimeAmount.WEEK.toMillis(2L))
|
||||
.append(AND).append("(");
|
||||
sql.appendWithSeparators(servers.stream().map(server -> SERVER_ID + "=" + server.getId()).iterator(), " OR ");
|
||||
sql.append(")");
|
||||
.append(AND).append('(');
|
||||
sql.appendWithSeparators(servers.stream().map(server -> SERVER_ID + "=" + server.getId()).iterator(), OR);
|
||||
sql.append(')');
|
||||
|
||||
return new QueryAllStatement<Map<Integer, List<TPS>>>(sql.toString(), 10000) {
|
||||
@Override
|
||||
|
@ -120,10 +120,10 @@ public class TPSQueries {
|
|||
}
|
||||
|
||||
public static Query<Optional<DateObj<Integer>>> fetchPeakPlayerCount(UUID serverUUID, long afterDate) {
|
||||
String subQuery = "(" + SELECT + "MAX(" + PLAYERS_ONLINE + ")" + FROM + TABLE_NAME + WHERE + SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
String subQuery = '(' + SELECT + "MAX(" + PLAYERS_ONLINE + ')' + FROM + TABLE_NAME + WHERE + SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
AND + DATE + ">= ?)";
|
||||
String sql = SELECT +
|
||||
DATE + ", " + PLAYERS_ONLINE +
|
||||
DATE + ',' + PLAYERS_ONLINE +
|
||||
FROM + TABLE_NAME +
|
||||
WHERE + SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
AND + DATE + ">= ?" +
|
||||
|
|
|
@ -71,10 +71,10 @@ public class UserIdentifierQueries {
|
|||
*/
|
||||
public static Query<Set<UUID>> fetchPlayerUUIDsOfServer(UUID serverUUID) {
|
||||
String sql = SELECT +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + ", " +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + ',' +
|
||||
FROM + UsersTable.TABLE_NAME +
|
||||
INNER_JOIN + UserInfoTable.TABLE_NAME + " on " +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + "." + UserInfoTable.USER_UUID +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID +
|
||||
WHERE + UserInfoTable.SERVER_UUID + "=?";
|
||||
return new QueryStatement<Set<UUID>>(sql, 1000) {
|
||||
@Override
|
||||
|
@ -107,8 +107,8 @@ public class UserIdentifierQueries {
|
|||
public Map<UUID, String> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, String> names = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString((UsersTable.USER_UUID)));
|
||||
String name = set.getString((UsersTable.USER_NAME));
|
||||
UUID uuid = UUID.fromString(set.getString(UsersTable.USER_UUID));
|
||||
String name = set.getString(UsersTable.USER_NAME);
|
||||
|
||||
names.put(uuid, name);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public class UserIdentifierQueries {
|
|||
SELECT + DISTINCT + UsersTable.USER_NAME +
|
||||
FROM + UsersTable.TABLE_NAME +
|
||||
INNER_JOIN + NicknamesTable.TABLE_NAME + " on " +
|
||||
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + "=" + NicknamesTable.TABLE_NAME + "." + NicknamesTable.USER_UUID +
|
||||
UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + "=" + NicknamesTable.TABLE_NAME + '.' + NicknamesTable.USER_UUID +
|
||||
WHERE + "LOWER(" + NicknamesTable.NICKNAME + ") LIKE LOWER(?)";
|
||||
|
||||
return new QueryStatement<List<String>>(sql, 5000) {
|
||||
|
|
|
@ -49,10 +49,10 @@ public class UserInfoQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, List<UserInfo>>> fetchAllUserInformation() {
|
||||
String sql = SELECT +
|
||||
UserInfoTable.REGISTERED + ", " +
|
||||
UserInfoTable.BANNED + ", " +
|
||||
UserInfoTable.OP + ", " +
|
||||
UserInfoTable.USER_UUID + ", " +
|
||||
UserInfoTable.REGISTERED + ',' +
|
||||
UserInfoTable.BANNED + ',' +
|
||||
UserInfoTable.OP + ',' +
|
||||
UserInfoTable.USER_UUID + ',' +
|
||||
UserInfoTable.SERVER_UUID +
|
||||
FROM + UserInfoTable.TABLE_NAME;
|
||||
|
||||
|
@ -86,12 +86,12 @@ public class UserInfoQueries {
|
|||
*/
|
||||
public static Query<List<UserInfo>> fetchUserInformationOfUser(UUID playerUUID) {
|
||||
String sql = SELECT +
|
||||
UserInfoTable.TABLE_NAME + "." + UserInfoTable.REGISTERED + ", " +
|
||||
UserInfoTable.BANNED + ", " +
|
||||
UserInfoTable.OP + ", " +
|
||||
UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' +
|
||||
UserInfoTable.BANNED + ',' +
|
||||
UserInfoTable.OP + ',' +
|
||||
UserInfoTable.SERVER_UUID +
|
||||
FROM + UserInfoTable.TABLE_NAME +
|
||||
WHERE + UserInfoTable.TABLE_NAME + "." + UserInfoTable.USER_UUID + "=?";
|
||||
WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<List<UserInfo>>(sql) {
|
||||
@Override
|
||||
|
@ -122,10 +122,10 @@ public class UserInfoQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, UserInfo>> fetchUserInformationOfServer(UUID serverUUID) {
|
||||
String sql = SELECT +
|
||||
UserInfoTable.REGISTERED + ", " +
|
||||
UserInfoTable.BANNED + ", " +
|
||||
UserInfoTable.OP + ", " +
|
||||
UserInfoTable.USER_UUID + ", " +
|
||||
UserInfoTable.REGISTERED + ',' +
|
||||
UserInfoTable.BANNED + ',' +
|
||||
UserInfoTable.OP + ',' +
|
||||
UserInfoTable.USER_UUID + ',' +
|
||||
UserInfoTable.SERVER_UUID +
|
||||
FROM + UserInfoTable.TABLE_NAME +
|
||||
WHERE + UserInfoTable.SERVER_UUID + "=?";
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for {@link com.djrapitops.plan.data.WebUser} objects.
|
||||
*
|
||||
|
@ -46,7 +48,7 @@ public class WebUserQueries {
|
|||
* @return List of Plan WebUsers.
|
||||
*/
|
||||
public static Query<List<WebUser>> fetchAllPlanWebUsers() {
|
||||
String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME + " ORDER BY " + SecurityTable.PERMISSION_LEVEL + " ASC";
|
||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + ORDER_BY + SecurityTable.PERMISSION_LEVEL + " ASC";
|
||||
|
||||
return new QueryAllStatement<List<WebUser>>(sql, 5000) {
|
||||
@Override
|
||||
|
@ -65,8 +67,8 @@ public class WebUserQueries {
|
|||
}
|
||||
|
||||
public static Query<Optional<WebUser>> fetchWebUser(String called) {
|
||||
String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME +
|
||||
" WHERE " + SecurityTable.USERNAME + "=? LIMIT 1";
|
||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME +
|
||||
WHERE + SecurityTable.USERNAME + "=? LIMIT 1";
|
||||
return new QueryStatement<Optional<WebUser>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
|
|
@ -40,9 +40,9 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
|||
public class WorldTimesQueries {
|
||||
|
||||
private static String worldColumn = "world";
|
||||
private static final String SELECT_WORLD_TIMES_JOIN_WORLD_NAME = WorldTable.TABLE_NAME + "." + WorldTable.NAME + " as " + worldColumn +
|
||||
private static final String SELECT_WORLD_TIMES_JOIN_WORLD_NAME = WorldTable.TABLE_NAME + '.' + WorldTable.NAME + " as " + worldColumn +
|
||||
FROM + WorldTimesTable.TABLE_NAME +
|
||||
INNER_JOIN + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + "." + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID;
|
||||
INNER_JOIN + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + '.' + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID;
|
||||
private static final String SELECT_WORLD_TIMES_STATEMENT_START = SELECT +
|
||||
"SUM(" + WorldTimesTable.SURVIVAL + ") as survival, " +
|
||||
"SUM(" + WorldTimesTable.CREATIVE + ") as creative, " +
|
||||
|
@ -62,7 +62,7 @@ public class WorldTimesQueries {
|
|||
public static Query<WorldTimes> fetchServerTotalWorldTimes(UUID serverUUID) {
|
||||
String sql = SELECT_WORLD_TIMES_STATEMENT_START +
|
||||
SELECT_WORLD_TIMES_JOIN_WORLD_NAME +
|
||||
WHERE + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + "=?" +
|
||||
WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + "=?" +
|
||||
GROUP_BY + worldColumn;
|
||||
|
||||
return new QueryStatement<WorldTimes>(sql, 1000) {
|
||||
|
@ -131,10 +131,10 @@ public class WorldTimesQueries {
|
|||
*/
|
||||
public static Query<Map<UUID, WorldTimes>> fetchPlayerWorldTimesOnServers(UUID playerUUID) {
|
||||
String sql = SELECT_WORLD_TIMES_STATEMENT_START +
|
||||
WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + ", " +
|
||||
WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + ',' +
|
||||
SELECT_WORLD_TIMES_JOIN_WORLD_NAME +
|
||||
WHERE + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.USER_UUID + "=?" +
|
||||
GROUP_BY + worldColumn + ", " + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID;
|
||||
WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.USER_UUID + "=?" +
|
||||
GROUP_BY + worldColumn + ',' + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID;
|
||||
|
||||
return new QueryStatement<Map<UUID, WorldTimes>>(sql, 1000) {
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,8 @@ import com.djrapitops.plan.db.access.Query;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.SELECT;
|
||||
|
||||
/**
|
||||
* Static method class for H2 Schema related queries.
|
||||
*
|
||||
|
@ -34,7 +36,7 @@ public class H2SchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesTableExist(String tableName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?";
|
||||
String sql = SELECT + "COUNT(1) as c FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -44,7 +46,7 @@ public class H2SchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesColumnExist(String tableName, String columnName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM INFORMATION_SCHEMA.COLUMNS" +
|
||||
String sql = SELECT + "COUNT(1) as c FROM INFORMATION_SCHEMA.COLUMNS" +
|
||||
" WHERE TABLE_NAME=? AND COLUMN_NAME=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
|
|
|
@ -26,6 +26,8 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Static method class for MySQL Schema related queries.
|
||||
*
|
||||
|
@ -38,7 +40,7 @@ public class MySQLSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesTableExist(String tableName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM information_schema.TABLES WHERE table_name=? AND TABLE_SCHEMA=DATABASE()";
|
||||
String sql = SELECT + "COUNT(1) as c FROM information_schema.TABLES WHERE table_name=? AND TABLE_SCHEMA=DATABASE()";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -48,9 +50,10 @@ public class MySQLSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<List<ForeignKeyConstraint>> foreignKeyConstraintsOf(String referencedTable) {
|
||||
String keySQL = "SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE" +
|
||||
" WHERE REFERENCED_TABLE_SCHEMA = DATABASE()" +
|
||||
" AND REFERENCED_TABLE_NAME = ?";
|
||||
String keySQL = SELECT + "TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME" +
|
||||
FROM + "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" +
|
||||
WHERE + "REFERENCED_TABLE_SCHEMA = DATABASE()" +
|
||||
AND + "REFERENCED_TABLE_NAME = ?";
|
||||
return new QueryStatement<List<ForeignKeyConstraint>>(keySQL) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -81,8 +84,9 @@ public class MySQLSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesIndexExist(String indexName, String tableName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM INFORMATION_SCHEMA.STATISTICS " +
|
||||
"WHERE table_schema=DATABASE() AND table_name=? AND index_name=?";
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + "INFORMATION_SCHEMA.STATISTICS" +
|
||||
WHERE + "table_schema=DATABASE()" + AND + "table_name=?" + AND + "index_name=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -93,8 +97,9 @@ public class MySQLSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesColumnExist(String tableName, String columnName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM information_schema.COLUMNS" +
|
||||
" WHERE TABLE_NAME=? AND COLUMN_NAME=? AND TABLE_SCHEMA=DATABASE()";
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + "information_schema.COLUMNS" +
|
||||
WHERE + "TABLE_NAME=? AND COLUMN_NAME=? AND TABLE_SCHEMA=DATABASE()";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -152,9 +157,9 @@ public class MySQLSchemaQueries {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "FK '" + constraintName + "' " +
|
||||
table + "." + column +
|
||||
table + '.' + column +
|
||||
" references " +
|
||||
referencedTable + "." + referencedColumn;
|
||||
referencedTable + '.' + referencedColumn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Static method class for SQLite Schema related queries.
|
||||
*
|
||||
|
@ -36,7 +38,8 @@ public class SQLiteSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesTableExist(String tableName) {
|
||||
String sql = "SELECT COUNT(1) as c FROM sqlite_master WHERE tbl_name=?";
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + "sqlite_master" + WHERE + "tbl_name=?";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -46,7 +49,7 @@ public class SQLiteSchemaQueries {
|
|||
}
|
||||
|
||||
public static Query<Boolean> doesColumnExist(String tableName, String columnName) {
|
||||
return new QueryAllStatement<Boolean>("PRAGMA table_info(" + tableName + ")") {
|
||||
return new QueryAllStatement<Boolean>("PRAGMA table_info(" + tableName + ')') {
|
||||
@Override
|
||||
public Boolean processResults(ResultSet set) throws SQLException {
|
||||
while (set.next()) {
|
||||
|
|
|
@ -37,7 +37,7 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.SELECT;
|
|||
public class SessionIDServerIDRelationQuery extends QueryAllStatement<Map<Integer, Integer>> {
|
||||
|
||||
public SessionIDServerIDRelationQuery() {
|
||||
super(SELECT + SessionsTable.ID + ", " +
|
||||
super(SELECT + SessionsTable.ID + ',' +
|
||||
"(SELECT plan_servers.id FROM plan_servers WHERE plan_servers.uuid=" + SessionsTable.SERVER_UUID + ") as server_id" +
|
||||
FROM + SessionsTable.TABLE_NAME, 50000);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.sql.SQLException;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Transaction to store a server's configuration file in the database.
|
||||
*
|
||||
|
@ -64,8 +66,9 @@ public class StoreConfigTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Query<Boolean> isConfigStored() {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + SettingsTable.TABLE_NAME +
|
||||
" WHERE " + SettingsTable.SERVER_UUID + "=? LIMIT 1";
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + SettingsTable.TABLE_NAME +
|
||||
WHERE + SettingsTable.SERVER_UUID + "=? LIMIT 1";
|
||||
return new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.access.transactions.commands;
|
|||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.db.sql.tables.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.DELETE_FROM;
|
||||
|
||||
/**
|
||||
* Transaction that removes everything from the database.
|
||||
*
|
||||
|
@ -56,6 +58,6 @@ public class RemoveEverythingTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private void clearTable(String tableName) {
|
||||
execute("DELETE FROM " + tableName);
|
||||
execute(DELETE_FROM + tableName);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Transaction for removing a player's data from the database.
|
||||
*
|
||||
|
@ -62,7 +64,7 @@ public class RemovePlayerTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private void deleteFromTable(String tableName) {
|
||||
execute(new ExecStatement("DELETE FROM " + tableName + " WHERE uuid=?") {
|
||||
execute(new ExecStatement(DELETE_FROM + tableName + WHERE + "uuid=?") {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
|
@ -71,9 +73,9 @@ public class RemovePlayerTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private void deleteFromKillsTable() {
|
||||
String sql = "DELETE FROM " + KillsTable.TABLE_NAME +
|
||||
" WHERE " + KillsTable.KILLER_UUID + "=?" +
|
||||
" OR " + KillsTable.VICTIM_UUID + "=?";
|
||||
String sql = DELETE_FROM + KillsTable.TABLE_NAME +
|
||||
WHERE + KillsTable.KILLER_UUID + "=?" +
|
||||
OR + KillsTable.VICTIM_UUID + "=?";
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
|
|
@ -23,6 +23,9 @@ import com.djrapitops.plan.db.sql.tables.SecurityTable;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.DELETE_FROM;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
/**
|
||||
* Transaction to remove a Plan {@link com.djrapitops.plan.data.WebUser} from the database.
|
||||
*
|
||||
|
@ -38,7 +41,7 @@ public class RemoveWebUserTransaction extends Transaction {
|
|||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
String sql = "DELETE FROM " + SecurityTable.TABLE_NAME + " WHERE " + SecurityTable.USERNAME + "=?";
|
||||
String sql = DELETE_FROM + SecurityTable.TABLE_NAME + WHERE + SecurityTable.USERNAME + "=?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.djrapitops.plan.db.access.queries.DataStoreQueries;
|
|||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
|
@ -32,8 +31,6 @@ import java.util.function.UnaryOperator;
|
|||
*/
|
||||
public class GeoInfoStoreTransaction extends Transaction {
|
||||
|
||||
private static boolean hasFailed = false;
|
||||
|
||||
private final UUID playerUUID;
|
||||
private InetAddress ip;
|
||||
private long time;
|
||||
|
@ -58,29 +55,14 @@ public class GeoInfoStoreTransaction extends Transaction {
|
|||
this.geoInfo = geoInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldBeExecuted() {
|
||||
return !hasFailed;
|
||||
}
|
||||
|
||||
public static void setAsFailed() {
|
||||
hasFailed = true;
|
||||
}
|
||||
|
||||
private GeoInfo createGeoInfo() throws NoSuchAlgorithmException {
|
||||
private GeoInfo createGeoInfo() {
|
||||
String country = geolocationFunction.apply(ip.getHostAddress());
|
||||
return new GeoInfo(ip, country, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
try {
|
||||
if (geoInfo == null) geoInfo = createGeoInfo();
|
||||
|
||||
execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo));
|
||||
} catch (NoSuchAlgorithmException noSHA256Available) {
|
||||
// SHA256 not available.
|
||||
setAsFailed();
|
||||
}
|
||||
if (geoInfo == null) geoInfo = createGeoInfo();
|
||||
execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo));
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Transaction to store world name after an event.
|
||||
*
|
||||
|
@ -46,9 +48,10 @@ public class WorldNameStoreTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private boolean doesWorldNameNotExist() {
|
||||
String sql = "SELECT COUNT(1) as c FROM " + WorldTable.TABLE_NAME +
|
||||
" WHERE " + WorldTable.NAME + "=?" +
|
||||
" AND " + WorldTable.SERVER_UUID + "=?";
|
||||
String sql = SELECT + "COUNT(1) as c" +
|
||||
FROM + WorldTable.TABLE_NAME +
|
||||
WHERE + WorldTable.NAME + "=?" +
|
||||
AND + WorldTable.SERVER_UUID + "=?";
|
||||
return !query(new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class CreateIndexTransaction extends Transaction {
|
|||
|
||||
sql.append(" (");
|
||||
sql.appendWithSeparators(indexedColumns, ",");
|
||||
sql.append(")");
|
||||
sql.append(')');
|
||||
|
||||
execute(sql.toString());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class RemoveDuplicateUserInfoTransaction extends Transaction {
|
|||
private static final String COLUMN_ID = UserInfoTable.TABLE_NAME + '.' + UserInfoTable.ID;
|
||||
private static final String STATEMENT_SELECT_DUPLICATE_IDS =
|
||||
SELECT + "MIN(" + COLUMN_ID + ") as id" + FROM + UserInfoTable.TABLE_NAME +
|
||||
GROUP_BY + UserInfoTable.USER_UUID + ", " + UserInfoTable.SERVER_UUID;
|
||||
GROUP_BY + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID;
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.sql.SQLException;
|
|||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Transaction for cleaning up old data from the database.
|
||||
*
|
||||
|
@ -59,9 +61,9 @@ public class RemoveOldSampledDataTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable cleanTPSTable(int allTimePlayerPeak) {
|
||||
String sql = "DELETE FROM " + TPSTable.TABLE_NAME +
|
||||
" WHERE (" + TPSTable.DATE + "<?)" +
|
||||
" AND (" + TPSTable.PLAYERS_ONLINE + "!=?)";
|
||||
String sql = DELETE_FROM + TPSTable.TABLE_NAME +
|
||||
WHERE + '(' + TPSTable.DATE + "<?)" +
|
||||
AND + '(' + TPSTable.PLAYERS_ONLINE + "!=?)";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -73,9 +75,9 @@ public class RemoveOldSampledDataTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable cleanPingTable() {
|
||||
String sql = "DELETE FROM " + PingTable.TABLE_NAME +
|
||||
" WHERE (" + PingTable.DATE + "<?)" +
|
||||
" OR (" + PingTable.MIN_PING + "<0)";
|
||||
String sql = DELETE_FROM + PingTable.TABLE_NAME +
|
||||
WHERE + '(' + PingTable.DATE + "<?)" +
|
||||
OR + '(' + PingTable.MIN_PING + "<0)";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,8 @@ import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
|||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Patch that resets AFK time of sessions with afk time of length of the session to 0.
|
||||
* <p>
|
||||
|
@ -40,11 +42,12 @@ public class BadAFKThresholdValuePatch extends Patch {
|
|||
|
||||
private boolean containsSessionsWithFullAFK() {
|
||||
// where |afk - session_length| < 5
|
||||
String sql = "SELECT COUNT(1) as found FROM " + SessionsTable.TABLE_NAME +
|
||||
" WHERE ABS(" +
|
||||
String sql = SELECT + "COUNT(1) as found" + FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + "ABS(" +
|
||||
SessionsTable.AFK_TIME +
|
||||
" - (" + SessionsTable.SESSION_END + "-" + SessionsTable.SESSION_START +
|
||||
")) < 5 AND " + SessionsTable.AFK_TIME + "!=0";
|
||||
")) < 5" +
|
||||
AND + SessionsTable.AFK_TIME + "!=0";
|
||||
return query(new HasMoreThanZeroQueryStatement(sql, "found") {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) {
|
||||
|
@ -56,10 +59,12 @@ public class BadAFKThresholdValuePatch extends Patch {
|
|||
@Override
|
||||
protected void applyPatch() {
|
||||
// where |afk - session_length| < 5
|
||||
String sql = "UPDATE " + SessionsTable.TABLE_NAME + " SET " + SessionsTable.AFK_TIME + "=0 WHERE ABS(" +
|
||||
String sql = "UPDATE " + SessionsTable.TABLE_NAME + " SET " + SessionsTable.AFK_TIME + "=0" +
|
||||
WHERE + "ABS(" +
|
||||
SessionsTable.AFK_TIME +
|
||||
" - (" + SessionsTable.SESSION_END + "-" + SessionsTable.SESSION_START +
|
||||
")) < 5 AND " + SessionsTable.AFK_TIME + "!=0";
|
||||
")) < 5" +
|
||||
AND + SessionsTable.AFK_TIME + "!=0";
|
||||
execute(sql);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ package com.djrapitops.plan.db.patches;
|
|||
|
||||
import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class GeoInfoOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -42,16 +44,16 @@ public class GeoInfoOptimizationPatch extends Patch {
|
|||
execute(GeoInfoTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.USER_UUID + ',' +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.IP + ',' +
|
||||
GeoInfoTable.LAST_USED + ',' +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -31,6 +31,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
public class IPAnonPatch extends Patch {
|
||||
|
||||
private String tableName;
|
||||
|
@ -47,8 +49,8 @@ public class IPAnonPatch extends Patch {
|
|||
}
|
||||
|
||||
private Boolean containsUnAnonymizedIPs() {
|
||||
String sql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + GeoInfoTable.IP + " NOT LIKE ? LIMIT 1";
|
||||
String sql = SELECT + '*' + FROM + tableName +
|
||||
WHERE + GeoInfoTable.IP + " NOT LIKE ? LIMIT 1";
|
||||
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@Override
|
||||
|
@ -72,8 +74,8 @@ public class IPAnonPatch extends Patch {
|
|||
|
||||
private void anonymizeIPs(Map<UUID, List<GeoInfo>> allGeoInfo) {
|
||||
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET " +
|
||||
GeoInfoTable.IP + "=? " +
|
||||
"WHERE " + GeoInfoTable.IP + "=?";
|
||||
GeoInfoTable.IP + "=?" +
|
||||
WHERE + GeoInfoTable.IP + "=?";
|
||||
|
||||
execute(new ExecBatchStatement(sql) {
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.KillsTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class KillsOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -56,20 +58,20 @@ public class KillsOptimizationPatch extends Patch {
|
|||
execute(KillsTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
KillsTable.VICTIM_UUID + ", " +
|
||||
KillsTable.KILLER_UUID + ", " +
|
||||
KillsTable.SERVER_UUID + ", " +
|
||||
KillsTable.DATE + ", " +
|
||||
KillsTable.WEAPON + ", " +
|
||||
KillsTable.VICTIM_UUID + ',' +
|
||||
KillsTable.KILLER_UUID + ',' +
|
||||
KillsTable.SERVER_UUID + ',' +
|
||||
KillsTable.DATE + ',' +
|
||||
KillsTable.WEAPON + ',' +
|
||||
KillsTable.SESSION_ID +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".victim_id LIMIT 1), " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".killer_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
KillsTable.DATE + ", " +
|
||||
KillsTable.WEAPON + ", " +
|
||||
KillsTable.DATE + ',' +
|
||||
KillsTable.WEAPON + ',' +
|
||||
KillsTable.SESSION_ID +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
package com.djrapitops.plan.db.patches;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecBatchStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.access.queries.schema.SessionIDServerIDRelationQuery;
|
||||
import com.djrapitops.plan.db.sql.tables.KillsTable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -35,22 +33,7 @@ public class KillsServerIDPatch extends Patch {
|
|||
|
||||
// KillsOptimizationPatch makes this patch incompatible with newer patch versions.
|
||||
return hasColumn(tableName, KillsTable.SERVER_UUID)
|
||||
|| (hasColumn(tableName, columnName) && allValuesHaveServerID(tableName, columnName));
|
||||
}
|
||||
|
||||
private Boolean allValuesHaveServerID(String tableName, String columnName) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE " + columnName + "=? LIMIT 1";
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean processResults(ResultSet set) throws SQLException {
|
||||
return !set.next();
|
||||
}
|
||||
});
|
||||
|| (hasColumn(tableName, columnName) && allValuesHaveValueZero(tableName, columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,6 +28,9 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
public class NicknameLastSeenPatch extends Patch {
|
||||
|
||||
@Override
|
||||
|
@ -108,9 +111,9 @@ public class NicknameLastSeenPatch extends Patch {
|
|||
|
||||
private void updateLastUsed(Map<UUID, Integer> serverIDsByUUID, Map<Integer, Set<Nickname>> nicknames) {
|
||||
String updateSQL = "UPDATE " + NicknamesTable.TABLE_NAME + " SET " + NicknamesTable.LAST_USED + "=?" +
|
||||
" WHERE " + NicknamesTable.NICKNAME + "=?" +
|
||||
" AND user_id=?" +
|
||||
" AND server_id=?";
|
||||
WHERE + NicknamesTable.NICKNAME + "=?" +
|
||||
AND + "user_id=?" +
|
||||
AND + "server_id=?";
|
||||
|
||||
execute(new ExecBatchStatement(updateSQL) {
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.NicknamesTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class NicknamesOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -45,16 +47,16 @@ public class NicknamesOptimizationPatch extends Patch {
|
|||
execute(NicknamesTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
NicknamesTable.USER_UUID + ", " +
|
||||
NicknamesTable.SERVER_UUID + ", " +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.USER_UUID + ',' +
|
||||
NicknamesTable.SERVER_UUID + ',' +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
NicknamesTable.NICKNAME + ", " +
|
||||
NicknamesTable.NICKNAME + ',' +
|
||||
NicknamesTable.LAST_USED +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -18,14 +18,20 @@ package com.djrapitops.plan.db.patches;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.access.queries.schema.H2SchemaQueries;
|
||||
import com.djrapitops.plan.db.access.queries.schema.MySQLSchemaQueries;
|
||||
import com.djrapitops.plan.db.access.queries.schema.SQLiteSchemaQueries;
|
||||
import com.djrapitops.plan.db.access.transactions.init.OperationCriticalTransaction;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
public abstract class Patch extends OperationCriticalTransaction {
|
||||
|
||||
private static final String ALTER_TABLE = "ALTER TABLE ";
|
||||
|
@ -127,4 +133,19 @@ public abstract class Patch extends OperationCriticalTransaction {
|
|||
|
||||
Verify.isTrue(constraints.isEmpty(), () -> new DBOpException("Table '" + table + "' has constraints '" + constraints + "'"));
|
||||
}
|
||||
|
||||
protected boolean allValuesHaveValueZero(String tableName, String column) {
|
||||
String sql = SELECT + '*' + FROM + tableName + WHERE + column + "=? LIMIT 1";
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean processResults(ResultSet set) throws SQLException {
|
||||
return !set.next();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.PingTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class PingOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -45,22 +47,22 @@ public class PingOptimizationPatch extends Patch {
|
|||
execute(PingTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
PingTable.USER_UUID + ", " +
|
||||
PingTable.SERVER_UUID + ", " +
|
||||
PingTable.ID + ", " +
|
||||
PingTable.MIN_PING + ", " +
|
||||
PingTable.MAX_PING + ", " +
|
||||
PingTable.AVG_PING + ", " +
|
||||
PingTable.USER_UUID + ',' +
|
||||
PingTable.SERVER_UUID + ',' +
|
||||
PingTable.ID + ',' +
|
||||
PingTable.MIN_PING + ',' +
|
||||
PingTable.MAX_PING + ',' +
|
||||
PingTable.AVG_PING + ',' +
|
||||
PingTable.DATE +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
PingTable.ID + ", " +
|
||||
PingTable.MIN_PING + ", " +
|
||||
PingTable.MAX_PING + ", " +
|
||||
PingTable.AVG_PING + ", " +
|
||||
PingTable.ID + ',' +
|
||||
PingTable.MIN_PING + ',' +
|
||||
PingTable.MAX_PING + ',' +
|
||||
PingTable.AVG_PING + ',' +
|
||||
PingTable.DATE +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class SessionsOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -49,24 +51,24 @@ public class SessionsOptimizationPatch extends Patch {
|
|||
execute(SessionsTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
SessionsTable.USER_UUID + ", " +
|
||||
SessionsTable.SERVER_UUID + ", " +
|
||||
SessionsTable.ID + ", " +
|
||||
SessionsTable.SESSION_START + ", " +
|
||||
SessionsTable.SESSION_END + ", " +
|
||||
SessionsTable.MOB_KILLS + ", " +
|
||||
SessionsTable.DEATHS + ", " +
|
||||
SessionsTable.USER_UUID + ',' +
|
||||
SessionsTable.SERVER_UUID + ',' +
|
||||
SessionsTable.ID + ',' +
|
||||
SessionsTable.SESSION_START + ',' +
|
||||
SessionsTable.SESSION_END + ',' +
|
||||
SessionsTable.MOB_KILLS + ',' +
|
||||
SessionsTable.DEATHS + ',' +
|
||||
SessionsTable.AFK_TIME +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
SessionsTable.ID + ", " +
|
||||
SessionsTable.SESSION_START + ", " +
|
||||
SessionsTable.SESSION_END + ", " +
|
||||
SessionsTable.MOB_KILLS + ", " +
|
||||
SessionsTable.DEATHS + ", " +
|
||||
SessionsTable.ID + ',' +
|
||||
SessionsTable.SESSION_START + ',' +
|
||||
SessionsTable.SESSION_END + ',' +
|
||||
SessionsTable.MOB_KILLS + ',' +
|
||||
SessionsTable.DEATHS + ',' +
|
||||
SessionsTable.AFK_TIME +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class UserInfoOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -45,18 +47,18 @@ public class UserInfoOptimizationPatch extends Patch {
|
|||
execute(UserInfoTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
UserInfoTable.USER_UUID + ", " +
|
||||
UserInfoTable.SERVER_UUID + ", " +
|
||||
UserInfoTable.REGISTERED + ", " +
|
||||
UserInfoTable.BANNED + ", " +
|
||||
UserInfoTable.USER_UUID + ',' +
|
||||
UserInfoTable.SERVER_UUID + ',' +
|
||||
UserInfoTable.REGISTERED + ',' +
|
||||
UserInfoTable.BANNED + ',' +
|
||||
UserInfoTable.OP +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
UserInfoTable.REGISTERED + ", " +
|
||||
UserInfoTable.BANNED + ", " +
|
||||
UserInfoTable.REGISTERED + ',' +
|
||||
UserInfoTable.BANNED + ',' +
|
||||
UserInfoTable.OP +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.WorldTimesTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class WorldTimesOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -46,24 +48,24 @@ public class WorldTimesOptimizationPatch extends Patch {
|
|||
execute(WorldTimesTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
WorldTimesTable.USER_UUID + ", " +
|
||||
WorldTimesTable.SERVER_UUID + ", " +
|
||||
WorldTimesTable.ADVENTURE + ", " +
|
||||
WorldTimesTable.CREATIVE + ", " +
|
||||
WorldTimesTable.SURVIVAL + ", " +
|
||||
WorldTimesTable.SPECTATOR + ", " +
|
||||
WorldTimesTable.SESSION_ID + ", " +
|
||||
WorldTimesTable.USER_UUID + ',' +
|
||||
WorldTimesTable.SERVER_UUID + ',' +
|
||||
WorldTimesTable.ADVENTURE + ',' +
|
||||
WorldTimesTable.CREATIVE + ',' +
|
||||
WorldTimesTable.SURVIVAL + ',' +
|
||||
WorldTimesTable.SPECTATOR + ',' +
|
||||
WorldTimesTable.SESSION_ID + ',' +
|
||||
WorldTimesTable.WORLD_ID +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
WorldTimesTable.ADVENTURE + ", " +
|
||||
WorldTimesTable.CREATIVE + ", " +
|
||||
WorldTimesTable.SURVIVAL + ", " +
|
||||
WorldTimesTable.SPECTATOR + ", " +
|
||||
WorldTimesTable.SESSION_ID + ", " +
|
||||
WorldTimesTable.ADVENTURE + ',' +
|
||||
WorldTimesTable.CREATIVE + ',' +
|
||||
WorldTimesTable.SURVIVAL + ',' +
|
||||
WorldTimesTable.SPECTATOR + ',' +
|
||||
WorldTimesTable.SESSION_ID + ',' +
|
||||
WorldTimesTable.WORLD_ID +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -17,15 +17,15 @@
|
|||
package com.djrapitops.plan.db.patches;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecBatchStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.access.queries.schema.SessionIDServerIDRelationQuery;
|
||||
import com.djrapitops.plan.db.sql.tables.WorldTimesTable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
public class WorldTimesSeverIDPatch extends Patch {
|
||||
|
||||
@Override
|
||||
|
@ -36,22 +36,7 @@ public class WorldTimesSeverIDPatch extends Patch {
|
|||
// WorldTimesOptimizationPatch makes this patch incompatible with newer patch versions.
|
||||
return hasColumn(tableName, "server_uuid")
|
||||
|| hasColumn(tableName, columnName)
|
||||
&& allValuesHaveServerID(tableName, columnName);
|
||||
}
|
||||
|
||||
private Boolean allValuesHaveServerID(String tableName, String columnName) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE " + columnName + "=? LIMIT 1";
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean processResults(ResultSet set) throws SQLException {
|
||||
return !set.next();
|
||||
}
|
||||
});
|
||||
&& allValuesHaveValueZero(tableName, columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +45,7 @@ public class WorldTimesSeverIDPatch extends Patch {
|
|||
|
||||
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " +
|
||||
"server_id=?" +
|
||||
" WHERE " + WorldTimesTable.SESSION_ID + "=?";
|
||||
WHERE + WorldTimesTable.SESSION_ID + "=?";
|
||||
|
||||
execute(new ExecBatchStatement(sql) {
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.db.patches;
|
|||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.sql.tables.WorldTable;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
|
||||
public class WorldsOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
|
@ -47,14 +49,14 @@ public class WorldsOptimizationPatch extends Patch {
|
|||
execute(WorldTable.createTableSQL(dbType));
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
WorldTable.ID + ", " +
|
||||
WorldTable.SERVER_UUID + ", " +
|
||||
WorldTable.ID + ',' +
|
||||
WorldTable.SERVER_UUID + ',' +
|
||||
WorldTable.NAME +
|
||||
") SELECT " +
|
||||
WorldTable.ID + ", " +
|
||||
WorldTable.ID + ',' +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
WorldTable.NAME +
|
||||
" FROM " + tempTableName
|
||||
FROM + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
|
|
|
@ -44,22 +44,7 @@ public class WorldsServerIDPatch extends Patch {
|
|||
// WorldsOptimizationPatch makes this patch incompatible with newer patch versions.
|
||||
return hasColumn(tableName, "server_uuid")
|
||||
|| hasColumn(tableName, columnName)
|
||||
&& allValuesHaveServerID(tableName, columnName);
|
||||
}
|
||||
|
||||
private Boolean allValuesHaveServerID(String tableName, String columnName) {
|
||||
String sql = "SELECT *" + FROM + tableName + WHERE + columnName + "=? LIMIT 1";
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean processResults(ResultSet set) throws SQLException {
|
||||
return !set.next();
|
||||
}
|
||||
});
|
||||
&& allValuesHaveValueZero(tableName, columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -74,20 +59,20 @@ public class WorldsServerIDPatch extends Patch {
|
|||
execute(LargeStoreQueries.storeAllWorldNames(worldsPerServer));
|
||||
|
||||
updateWorldTimesTableWorldIDs();
|
||||
executeSwallowingExceptions("DELETE FROM " + WorldTable.TABLE_NAME + " WHERE server_id=0");
|
||||
executeSwallowingExceptions(DELETE_FROM + WorldTable.TABLE_NAME + WHERE + "server_id=0");
|
||||
}
|
||||
|
||||
private Set<String> getWorldNamesOld(UUID serverUUID) {
|
||||
String worldIDColumn = WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.WORLD_ID;
|
||||
String worldSessionIDColumn = WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SESSION_ID;
|
||||
String sessionIDColumn = SessionsTable.TABLE_NAME + "." + SessionsTable.ID;
|
||||
String sessionServerUUIDColumn = SessionsTable.TABLE_NAME + "." + SessionsTable.SERVER_UUID;
|
||||
String worldIDColumn = WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.WORLD_ID;
|
||||
String worldSessionIDColumn = WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SESSION_ID;
|
||||
String sessionIDColumn = SessionsTable.TABLE_NAME + '.' + SessionsTable.ID;
|
||||
String sessionServerUUIDColumn = SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID;
|
||||
|
||||
String sql = "SELECT DISTINCT " +
|
||||
String sql = SELECT + DISTINCT +
|
||||
WorldTable.NAME + FROM +
|
||||
WorldTable.TABLE_NAME +
|
||||
" INNER JOIN " + WorldTimesTable.TABLE_NAME + " on " + worldIDColumn + "=" + WorldTable.TABLE_NAME + "." + WorldTable.ID +
|
||||
" INNER JOIN " + SessionsTable.TABLE_NAME + " on " + worldSessionIDColumn + "=" + sessionIDColumn +
|
||||
INNER_JOIN + WorldTimesTable.TABLE_NAME + " on " + worldIDColumn + "=" + WorldTable.TABLE_NAME + '.' + WorldTable.ID +
|
||||
INNER_JOIN + SessionsTable.TABLE_NAME + " on " + worldSessionIDColumn + "=" + sessionIDColumn +
|
||||
WHERE + sessionServerUUIDColumn + "=?";
|
||||
|
||||
return query(new QueryStatement<Set<String>>(sql, 1000) {
|
||||
|
@ -141,7 +126,7 @@ public class WorldsServerIDPatch extends Patch {
|
|||
}
|
||||
|
||||
public List<WorldObj> getWorldObjects() {
|
||||
String sql = "SELECT * FROM " + WorldTable.TABLE_NAME;
|
||||
String sql = SELECT + '*' + FROM + WorldTable.TABLE_NAME;
|
||||
return query(new QueryAllStatement<List<WorldObj>>(sql, 100) {
|
||||
@Override
|
||||
public List<WorldObj> processResults(ResultSet set) throws SQLException {
|
||||
|
|
|
@ -48,7 +48,7 @@ public class CreateTableParser {
|
|||
private void finalizeColumn() {
|
||||
if (columnBuilder != null) {
|
||||
if (columnCount > 0) {
|
||||
columns.append(", ");
|
||||
columns.append(',');
|
||||
}
|
||||
columns.append(columnBuilder.toString());
|
||||
columnCount++;
|
||||
|
@ -97,15 +97,15 @@ public class CreateTableParser {
|
|||
public CreateTableParser foreignKey(String column, String referencedTable, String referencedColumn) {
|
||||
finalizeColumn();
|
||||
if (constraintCount > 0) {
|
||||
keyConstraints.append(", ");
|
||||
keyConstraints.append(',');
|
||||
}
|
||||
keyConstraints.append("FOREIGN KEY(")
|
||||
.append(column)
|
||||
.append(") REFERENCES ")
|
||||
.append(referencedTable)
|
||||
.append("(")
|
||||
.append('(')
|
||||
.append(referencedColumn)
|
||||
.append(")");
|
||||
.append(')');
|
||||
constraintCount++;
|
||||
return this;
|
||||
}
|
||||
|
@ -113,9 +113,9 @@ public class CreateTableParser {
|
|||
private void primaryKey(String column) {
|
||||
finalizeColumn();
|
||||
if (constraintCount > 0) {
|
||||
keyConstraints.append(", ");
|
||||
keyConstraints.append(',');
|
||||
}
|
||||
keyConstraints.append("PRIMARY KEY (").append(column).append(")");
|
||||
keyConstraints.append("PRIMARY KEY (").append(column).append(')');
|
||||
constraintCount++;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class CreateTableParser {
|
|||
|
||||
Verify.isTrue(columnCount > 0, () -> new IllegalStateException("No columns specified for statement '" + columns.toString() + "..'"));
|
||||
if (constraintCount > 0) {
|
||||
return columns.toString() + ", " + keyConstraints.toString() + ')';
|
||||
return columns.toString() + ',' + keyConstraints.toString() + ')';
|
||||
} else {
|
||||
return columns.toString() + ')';
|
||||
}
|
||||
|
|
|
@ -25,22 +25,22 @@ public class Insert extends SqlParser {
|
|||
|
||||
public static String values(String table, String... columns) {
|
||||
Insert parser = new Insert(table);
|
||||
parser.append("(");
|
||||
parser.append('(');
|
||||
int size = columns.length;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (size > 1 && i > 0) {
|
||||
parser.append(", ");
|
||||
parser.append(',');
|
||||
}
|
||||
parser.append(columns[i]);
|
||||
}
|
||||
parser.append(") VALUES (");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (size > 1 && i > 0) {
|
||||
parser.append(", ");
|
||||
parser.append(',');
|
||||
}
|
||||
parser.append("?");
|
||||
}
|
||||
parser.append(")");
|
||||
parser.append(')');
|
||||
return parser.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package com.djrapitops.plan.db.sql.parsing;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.FROM;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.SELECT;
|
||||
|
||||
public class Select extends WhereParser {
|
||||
|
||||
public Select(String start) {
|
||||
|
@ -23,20 +26,20 @@ public class Select extends WhereParser {
|
|||
}
|
||||
|
||||
public static Select from(String table, String... columns) {
|
||||
Select parser = new Select("SELECT ");
|
||||
Select parser = new Select(SELECT);
|
||||
int size = columns.length;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (size > 1 && i > 0) {
|
||||
parser.append(", ");
|
||||
parser.append(',');
|
||||
}
|
||||
parser.append(columns[i]);
|
||||
}
|
||||
|
||||
parser.append(" FROM ").append(table);
|
||||
parser.append(FROM).append(table);
|
||||
return parser;
|
||||
}
|
||||
|
||||
public static Select all(String table) {
|
||||
return new Select("SELECT * FROM " + table);
|
||||
return new Select(SELECT + '*' + FROM + table);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package com.djrapitops.plan.db.sql.parsing;
|
||||
|
||||
/**
|
||||
* Duplicate String reducing utility class for SQL language Strings.
|
||||
*/
|
||||
public class Sql {
|
||||
public static final String INT = "integer";
|
||||
public static final String DOUBLE = "double";
|
||||
|
@ -25,6 +28,7 @@ public class Sql {
|
|||
public static final String SELECT = "SELECT ";
|
||||
public static final String DISTINCT = "DISTINCT ";
|
||||
public static final String FROM = " FROM ";
|
||||
public static final String DELETE_FROM = "DELETE" + FROM;
|
||||
public static final String WHERE = " WHERE ";
|
||||
public static final String GROUP_BY = " GROUP BY ";
|
||||
public static final String ORDER_BY = " ORDER BY ";
|
||||
|
@ -36,10 +40,10 @@ public class Sql {
|
|||
public static final String IS_NOT_NULL = " IS NOT NULL";
|
||||
|
||||
private Sql() {
|
||||
throw new IllegalStateException("Variable Class");
|
||||
/* Variable class */
|
||||
}
|
||||
|
||||
public static String varchar(int length) {
|
||||
return "varchar(" + length + ")";
|
||||
return "varchar(" + length + ')';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,11 @@ public class SqlParser {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SqlParser append(char c) {
|
||||
s.append(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return s.toString();
|
||||
|
|
|
@ -32,7 +32,7 @@ public class Update extends WhereParser {
|
|||
int size = values.length;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (size > 1 && i > 0) {
|
||||
parser.append(", ");
|
||||
parser.append(',');
|
||||
}
|
||||
parser.append(values[i] + "=?");
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package com.djrapitops.plan.db.sql.parsing;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
|
@ -32,12 +34,12 @@ public abstract class WhereParser extends SqlParser {
|
|||
}
|
||||
|
||||
public WhereParser where(String... conditions) {
|
||||
append(" WHERE ");
|
||||
append(WHERE);
|
||||
for (String condition : conditions) {
|
||||
if (this.conditions > 0) {
|
||||
append(" AND ");
|
||||
append(AND);
|
||||
}
|
||||
append("(").append(condition).append(")");
|
||||
append('(').append(condition).append(')');
|
||||
this.conditions++;
|
||||
}
|
||||
|
||||
|
@ -45,15 +47,15 @@ public abstract class WhereParser extends SqlParser {
|
|||
}
|
||||
|
||||
public WhereParser and(String condition) {
|
||||
append(" AND ");
|
||||
append("(").append(condition).append(")");
|
||||
append(AND);
|
||||
append('(').append(condition).append(')');
|
||||
this.conditions++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WhereParser or(String condition) {
|
||||
append(" OR ");
|
||||
append("(").append(condition).append(")");
|
||||
append(OR);
|
||||
append('(').append(condition).append(')');
|
||||
this.conditions++;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ import com.djrapitops.plan.db.DBType;
|
|||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
/**
|
||||
* Table information about 'plan_commandusages'.
|
||||
*
|
||||
|
@ -38,15 +41,15 @@ public class CommandUseTable {
|
|||
public static final String TIMES_USED = "times_used";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ COMMAND + ", "
|
||||
+ TIMES_USED + ", "
|
||||
+ COMMAND + ','
|
||||
+ TIMES_USED + ','
|
||||
+ SERVER_ID
|
||||
+ ") VALUES (?, ?, " + ServerTable.STATEMENT_SELECT_SERVER_ID + ")";
|
||||
+ ") VALUES (?, ?, " + ServerTable.STATEMENT_SELECT_SERVER_ID + ')';
|
||||
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + CommandUseTable.TABLE_NAME + " SET "
|
||||
+ CommandUseTable.TIMES_USED + "=" + CommandUseTable.TIMES_USED + "+ 1" +
|
||||
" WHERE " + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
" AND " + CommandUseTable.COMMAND + "=?";
|
||||
WHERE + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
|
||||
AND + CommandUseTable.COMMAND + "=?";
|
||||
|
||||
private CommandUseTable() {
|
||||
/* Static information class */
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ExtensionIconTable {
|
|||
public static final String FAMILY = "family";
|
||||
public static final String COLOR = "color";
|
||||
|
||||
public static final String STATEMENT_SELECT_ICON_ID = "(" + SELECT + ID +
|
||||
public static final String STATEMENT_SELECT_ICON_ID = '(' + SELECT + ID +
|
||||
FROM + TABLE_NAME +
|
||||
WHERE + ICON_NAME + "=?" +
|
||||
AND + FAMILY + "=?" +
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ExtensionPluginTable {
|
|||
public static final String SERVER_UUID = "server_uuid";
|
||||
public static final String ICON_ID = "icon_id";
|
||||
|
||||
public static final String STATEMENT_SELECT_PLUGIN_ID = "(" + SELECT + ID +
|
||||
public static final String STATEMENT_SELECT_PLUGIN_ID = '(' + SELECT + ID +
|
||||
FROM + TABLE_NAME +
|
||||
WHERE + PLUGIN_NAME + "=?" +
|
||||
AND + SERVER_UUID + "=?)";
|
||||
|
|
|
@ -52,9 +52,9 @@ public class ExtensionProviderTable {
|
|||
public static final String FORMAT_TYPE = "format_type"; // Can be null, related to @NumberProvider
|
||||
public static final String IS_PLAYER_NAME = "player_name"; // default false, related to @StringProvider
|
||||
|
||||
public static final String STATEMENT_SELECT_PROVIDER_ID = "(" + SELECT + ID + FROM + TABLE_NAME +
|
||||
public static final String STATEMENT_SELECT_PROVIDER_ID = '(' + SELECT + ID + FROM + TABLE_NAME +
|
||||
WHERE + PROVIDER_NAME + "=?" +
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ')';
|
||||
|
||||
public static void set3PluginValuesToStatement(PreparedStatement statement, int parameterIndex, String providerName, String pluginName, UUID serverUUID) throws SQLException {
|
||||
statement.setString(parameterIndex, providerName);
|
||||
|
|
|
@ -43,10 +43,10 @@ public class ExtensionTabTable {
|
|||
public static final String PLUGIN_ID = "plugin_id";
|
||||
public static final String ICON_ID = "icon_id";
|
||||
|
||||
public static final String STATEMENT_SELECT_TAB_ID = "(" + SELECT + ID +
|
||||
public static final String STATEMENT_SELECT_TAB_ID = '(' + SELECT + ID +
|
||||
FROM + TABLE_NAME +
|
||||
WHERE + TAB_NAME + "=?" +
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ')';
|
||||
|
||||
public static void set3TabValuesToStatement(PreparedStatement statement, int parameterIndex, String tabName, String pluginName, UUID serverUUID) throws SQLException {
|
||||
statement.setString(parameterIndex, tabName);
|
||||
|
|
|
@ -57,9 +57,9 @@ public class ExtensionTableProviderTable {
|
|||
public static final String ICON_4_ID = "icon_4_id";
|
||||
public static final String ICON_5_ID = "icon_5_id";
|
||||
|
||||
public static final String STATEMENT_SELECT_TABLE_ID = "(" + SELECT + ID + FROM + TABLE_NAME +
|
||||
public static final String STATEMENT_SELECT_TABLE_ID = '(' + SELECT + ID + FROM + TABLE_NAME +
|
||||
WHERE + PROVIDER_NAME + "=?" +
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
|
||||
AND + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ')';
|
||||
|
||||
private ExtensionTableProviderTable() {
|
||||
/* Static information class */
|
||||
|
|
|
@ -21,6 +21,9 @@ import com.djrapitops.plan.db.patches.*;
|
|||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
/**
|
||||
* Table information about 'plan_ips'.
|
||||
* <p>
|
||||
|
@ -44,16 +47,16 @@ public class GeoInfoTable {
|
|||
public static final String LAST_USED = "last_used";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ USER_UUID + ", "
|
||||
+ IP + ", "
|
||||
+ GEOLOCATION + ", "
|
||||
+ USER_UUID + ','
|
||||
+ IP + ','
|
||||
+ GEOLOCATION + ','
|
||||
+ LAST_USED
|
||||
+ ") VALUES (?, ?, ?, ?)";
|
||||
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET "
|
||||
+ LAST_USED + "=?" +
|
||||
" WHERE " + USER_UUID + "=?" +
|
||||
" AND " + GEOLOCATION + "=?";
|
||||
WHERE + USER_UUID + "=?" +
|
||||
AND + GEOLOCATION + "=?";
|
||||
|
||||
private GeoInfoTable() {
|
||||
/* Static information class */
|
||||
|
|
|
@ -53,11 +53,11 @@ public class KillsTable {
|
|||
public static final String DATE = "date";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ SESSION_ID + ", "
|
||||
+ KILLER_UUID + ", "
|
||||
+ VICTIM_UUID + ", "
|
||||
+ SERVER_UUID + ", "
|
||||
+ DATE + ", "
|
||||
+ SESSION_ID + ','
|
||||
+ KILLER_UUID + ','
|
||||
+ VICTIM_UUID + ','
|
||||
+ SERVER_UUID + ','
|
||||
+ DATE + ','
|
||||
+ WEAPON
|
||||
+ ") VALUES (" + SessionsTable.SELECT_SESSION_ID_STATEMENT + ", ?, ?, ?, ?, ?)";
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ import com.djrapitops.plan.db.patches.Version10Patch;
|
|||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
|
||||
/**
|
||||
* Table information about 'plan_nicknames'.
|
||||
* <p>
|
||||
|
@ -44,16 +47,16 @@ public class NicknamesTable {
|
|||
public static final String LAST_USED = "last_used";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
USER_UUID + ", " +
|
||||
SERVER_UUID + ", " +
|
||||
NICKNAME + ", " +
|
||||
USER_UUID + ',' +
|
||||
SERVER_UUID + ',' +
|
||||
NICKNAME + ',' +
|
||||
LAST_USED +
|
||||
") VALUES (?, ?, ?, ?)";
|
||||
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET " + LAST_USED + "=?" +
|
||||
" WHERE " + NICKNAME + "=?" +
|
||||
" AND " + USER_UUID + "=?" +
|
||||
" AND " + SERVER_UUID + "=?";
|
||||
WHERE + NICKNAME + "=?" +
|
||||
AND + USER_UUID + "=?" +
|
||||
AND + SERVER_UUID + "=?";
|
||||
|
||||
private NicknamesTable() {
|
||||
/* Static information class */
|
||||
|
|
|
@ -42,11 +42,11 @@ public class PingTable {
|
|||
public static final String MIN_PING = "min_ping";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
USER_UUID + ", " +
|
||||
SERVER_UUID + ", " +
|
||||
DATE + ", " +
|
||||
MIN_PING + ", " +
|
||||
MAX_PING + ", " +
|
||||
USER_UUID + ',' +
|
||||
SERVER_UUID + ',' +
|
||||
DATE + ',' +
|
||||
MIN_PING + ',' +
|
||||
MAX_PING + ',' +
|
||||
AVG_PING +
|
||||
") VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
|
|
|
@ -56,9 +56,9 @@ public class ServerTable {
|
|||
.toString();
|
||||
|
||||
public static final String STATEMENT_SELECT_SERVER_ID =
|
||||
"(" + SELECT + TABLE_NAME + "." + SERVER_ID +
|
||||
'(' + SELECT + TABLE_NAME + '.' + SERVER_ID +
|
||||
FROM + TABLE_NAME +
|
||||
WHERE + TABLE_NAME + "." + SERVER_UUID + "=?" +
|
||||
WHERE + TABLE_NAME + '.' + SERVER_UUID + "=?" +
|
||||
" LIMIT 1)";
|
||||
|
||||
private ServerTable() {
|
||||
|
|
|
@ -49,18 +49,18 @@ public class SessionsTable {
|
|||
public static final String AFK_TIME = "afk_time";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ USER_UUID + ", "
|
||||
+ SESSION_START + ", "
|
||||
+ SESSION_END + ", "
|
||||
+ DEATHS + ", "
|
||||
+ MOB_KILLS + ", "
|
||||
+ AFK_TIME + ", "
|
||||
+ USER_UUID + ','
|
||||
+ SESSION_START + ','
|
||||
+ SESSION_END + ','
|
||||
+ DEATHS + ','
|
||||
+ MOB_KILLS + ','
|
||||
+ AFK_TIME + ','
|
||||
+ SERVER_UUID
|
||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
public static final String SELECT_SESSION_ID_STATEMENT = "(SELECT " + TABLE_NAME + "." + ID + FROM + TABLE_NAME +
|
||||
WHERE + TABLE_NAME + "." + USER_UUID + "=?" +
|
||||
AND + TABLE_NAME + "." + SERVER_UUID + "=?" +
|
||||
public static final String SELECT_SESSION_ID_STATEMENT = "(SELECT " + TABLE_NAME + '.' + ID + FROM + TABLE_NAME +
|
||||
WHERE + TABLE_NAME + '.' + USER_UUID + "=?" +
|
||||
AND + TABLE_NAME + '.' + SERVER_UUID + "=?" +
|
||||
AND + SESSION_START + "=?" +
|
||||
AND + SESSION_END + "=? LIMIT 1)";
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ public class SettingsTable {
|
|||
public static final String CONFIG_CONTENT = "content";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
SERVER_UUID + ", " +
|
||||
UPDATED + ", " +
|
||||
SERVER_UUID + ',' +
|
||||
UPDATED + ',' +
|
||||
CONFIG_CONTENT + ") VALUES (?,?,?)";
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET " +
|
||||
CONFIG_CONTENT + "=?," +
|
||||
|
|
|
@ -40,17 +40,17 @@ public class TPSTable {
|
|||
public static final String FREE_DISK = "free_disk_space";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ SERVER_ID + ", "
|
||||
+ DATE + ", "
|
||||
+ TPS + ", "
|
||||
+ PLAYERS_ONLINE + ", "
|
||||
+ CPU_USAGE + ", "
|
||||
+ RAM_USAGE + ", "
|
||||
+ ENTITIES + ", "
|
||||
+ CHUNKS + ", "
|
||||
+ SERVER_ID + ','
|
||||
+ DATE + ','
|
||||
+ TPS + ','
|
||||
+ PLAYERS_ONLINE + ','
|
||||
+ CPU_USAGE + ','
|
||||
+ RAM_USAGE + ','
|
||||
+ ENTITIES + ','
|
||||
+ CHUNKS + ','
|
||||
+ FREE_DISK
|
||||
+ ") VALUES ("
|
||||
+ ServerTable.STATEMENT_SELECT_SERVER_ID + ", "
|
||||
+ ServerTable.STATEMENT_SELECT_SERVER_ID + ','
|
||||
+ "?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private TPSTable() {
|
||||
|
|
|
@ -43,10 +43,10 @@ public class UserInfoTable {
|
|||
public static final String BANNED = "banned";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
USER_UUID + ", " +
|
||||
REGISTERED + ", " +
|
||||
SERVER_UUID + ", " +
|
||||
BANNED + ", " +
|
||||
USER_UUID + ',' +
|
||||
REGISTERED + ',' +
|
||||
SERVER_UUID + ',' +
|
||||
BANNED + ',' +
|
||||
OP +
|
||||
") VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ import com.djrapitops.plan.db.patches.WorldsServerIDPatch;
|
|||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Table information about 'plan_worlds'.
|
||||
* <p>
|
||||
|
@ -42,13 +44,14 @@ public class WorldTable {
|
|||
public static final String NAME = "world_name";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ NAME + ", "
|
||||
+ NAME + ','
|
||||
+ SERVER_UUID
|
||||
+ ") VALUES (?, ?)";
|
||||
|
||||
public static final String SELECT_WORLD_ID_STATEMENT = "(SELECT " + TABLE_NAME + "." + ID + " FROM " + TABLE_NAME +
|
||||
" WHERE (" + NAME + "=?)" +
|
||||
" AND (" + TABLE_NAME + "." + SERVER_UUID + "=?)" +
|
||||
public static final String SELECT_WORLD_ID_STATEMENT = '(' +
|
||||
SELECT + TABLE_NAME + '.' + ID + FROM + TABLE_NAME +
|
||||
WHERE + '(' + NAME + "=?)" +
|
||||
AND + '(' + TABLE_NAME + '.' + SERVER_UUID + "=?)" +
|
||||
" LIMIT 1)";
|
||||
|
||||
private WorldTable() {
|
||||
|
|
|
@ -58,17 +58,17 @@ public class WorldTimesTable {
|
|||
public static final String SPECTATOR = "spectator_time";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + WorldTimesTable.TABLE_NAME + " (" +
|
||||
WorldTimesTable.SESSION_ID + ", " +
|
||||
WorldTimesTable.WORLD_ID + ", " +
|
||||
WorldTimesTable.USER_UUID + ", " +
|
||||
WorldTimesTable.SERVER_UUID + ", " +
|
||||
WorldTimesTable.SURVIVAL + ", " +
|
||||
WorldTimesTable.CREATIVE + ", " +
|
||||
WorldTimesTable.ADVENTURE + ", " +
|
||||
WorldTimesTable.SESSION_ID + ',' +
|
||||
WorldTimesTable.WORLD_ID + ',' +
|
||||
WorldTimesTable.USER_UUID + ',' +
|
||||
WorldTimesTable.SERVER_UUID + ',' +
|
||||
WorldTimesTable.SURVIVAL + ',' +
|
||||
WorldTimesTable.CREATIVE + ',' +
|
||||
WorldTimesTable.ADVENTURE + ',' +
|
||||
WorldTimesTable.SPECTATOR +
|
||||
") VALUES ( " +
|
||||
SessionsTable.SELECT_SESSION_ID_STATEMENT + ", " +
|
||||
WorldTable.SELECT_WORLD_ID_STATEMENT + ", " +
|
||||
SessionsTable.SELECT_SESSION_ID_STATEMENT + ',' +
|
||||
WorldTable.SELECT_WORLD_ID_STATEMENT + ',' +
|
||||
"?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private WorldTimesTable() {
|
||||
|
|
|
@ -48,6 +48,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Task for cleaning the active database.
|
||||
*
|
||||
|
@ -122,11 +124,12 @@ public class DBCleanTask extends AbsRunnable {
|
|||
}
|
||||
|
||||
private Query<List<UUID>> fetchInactivePlayerUUIDs(long keepActiveAfter) {
|
||||
String sql = "SELECT uuid, last_seen FROM (SELECT" +
|
||||
" MAX(" + SessionsTable.SESSION_END + ") as last_seen, " + SessionsTable.USER_UUID +
|
||||
" FROM " + SessionsTable.TABLE_NAME +
|
||||
" GROUP BY " + SessionsTable.USER_UUID + ") as q1" +
|
||||
" WHERE last_seen < ?";
|
||||
String sql = SELECT + "uuid, last_seen" + FROM +
|
||||
'(' + SELECT + "MAX(" + SessionsTable.SESSION_END + ") as last_seen, " +
|
||||
SessionsTable.USER_UUID +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
GROUP_BY + SessionsTable.USER_UUID + ") as q1" +
|
||||
WHERE + "last_seen < ?";
|
||||
return new QueryStatement<List<UUID>>(sql, 20000) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,12 +54,12 @@ public class KeepAliveTask extends AbsRunnable {
|
|||
statement = connection.createStatement();
|
||||
resultSet = statement.executeQuery("/* ping */ SELECT 1");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException pingException) {
|
||||
logger.debug("Something went wrong during SQL Connection upkeep task.");
|
||||
try {
|
||||
connection = iReconnect.reconnect();
|
||||
} catch (SQLException e1) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e1);
|
||||
} catch (SQLException reconnectionError) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), reconnectionError);
|
||||
logger.error("SQL connection maintaining task had to be closed due to exception.");
|
||||
this.cancel();
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
|||
logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, "Gathering completed: " + playerName);
|
||||
} catch (DataExtensionMethodCallException methodCallFailed) {
|
||||
logFailure(playerName, methodCallFailed);
|
||||
gatherer.disableMethodFromUse(methodCallFailed.getMethod());
|
||||
methodCallFailed.getMethod().ifPresent(gatherer::disableMethodFromUse);
|
||||
// Try again
|
||||
updatePlayerValues(gatherer, playerUUID, playerName, event);
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError unexpectedError) {
|
||||
|
@ -199,7 +199,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
|||
logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, "Gathering completed for server");
|
||||
} catch (DataExtensionMethodCallException methodCallFailed) {
|
||||
logFailure("server", methodCallFailed);
|
||||
gatherer.disableMethodFromUse(methodCallFailed.getMethod());
|
||||
methodCallFailed.getMethod().ifPresent(gatherer::disableMethodFromUse);
|
||||
// Try again
|
||||
updateServerValues(gatherer, event);
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError unexpectedError) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.djrapitops.plan.extension.Group;
|
|||
import com.djrapitops.plan.extension.NotReadyException;
|
||||
import com.djrapitops.plan.extension.implementation.MethodType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
@ -32,7 +31,7 @@ import java.util.UUID;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MethodWrapper<T> implements Serializable {
|
||||
public class MethodWrapper<T> {
|
||||
|
||||
private final Method method;
|
||||
private final Class<T> resultType;
|
||||
|
@ -80,7 +79,7 @@ public class MethodWrapper<T> implements Serializable {
|
|||
throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " had invalid parameters.");
|
||||
}
|
||||
} catch (InvocationTargetException notReadyToBeCalled) {
|
||||
if (notReadyToBeCalled.getCause() != null && notReadyToBeCalled.getCause() instanceof NotReadyException) {
|
||||
if (notReadyToBeCalled.getCause() instanceof NotReadyException) {
|
||||
return null; // Data or API not available to make the call.
|
||||
} else {
|
||||
throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " could not be called: " + notReadyToBeCalled.getMessage(), notReadyToBeCalled);
|
||||
|
|
|
@ -26,8 +26,7 @@ import java.sql.SQLException;
|
|||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Transaction to remove method results that correspond to {@link com.djrapitops.plan.extension.annotation.InvalidateMethod} annotations.
|
||||
|
@ -60,7 +59,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidPlayerMethodResults(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionPlayerValueTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionPlayerValueTable.TABLE_NAME +
|
||||
WHERE + ExtensionPlayerValueTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -71,7 +70,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidServerMethodResults(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionServerValueTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionServerValueTable.TABLE_NAME +
|
||||
WHERE + ExtensionServerValueTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -82,7 +81,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidPlayerTableResults(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionPlayerTableValueTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionPlayerTableValueTable.TABLE_NAME +
|
||||
WHERE + ExtensionPlayerTableValueTable.TABLE_ID + "=" + ExtensionTableProviderTable.STATEMENT_SELECT_TABLE_ID;
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -93,7 +92,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidServerTableResults(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionServerTableValueTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionServerTableValueTable.TABLE_NAME +
|
||||
WHERE + ExtensionServerTableValueTable.TABLE_ID + "=" + ExtensionTableProviderTable.STATEMENT_SELECT_TABLE_ID;
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -104,7 +103,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidMethodProvider(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionProviderTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionProviderTable.TABLE_NAME +
|
||||
WHERE + ExtensionProviderTable.PROVIDER_NAME + "=?" +
|
||||
AND + ExtensionProviderTable.PLUGIN_ID + '=' + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID;
|
||||
return new ExecStatement(sql) {
|
||||
|
@ -117,7 +116,7 @@ public class RemoveInvalidResultsTransaction extends Transaction {
|
|||
}
|
||||
|
||||
private Executable deleteInvalidTableProvider(String invalidMethod) {
|
||||
String sql = "DELETE FROM " + ExtensionTableProviderTable.TABLE_NAME +
|
||||
String sql = DELETE_FROM + ExtensionTableProviderTable.TABLE_NAME +
|
||||
WHERE + ExtensionTableProviderTable.TABLE_NAME + "=?" +
|
||||
AND + ExtensionTableProviderTable.PLUGIN_ID + '=' + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID;
|
||||
return new ExecStatement(sql) {
|
||||
|
|
|
@ -119,7 +119,7 @@ public abstract class InfoSystem implements SubSystem {
|
|||
try {
|
||||
logger.getDebugLogger().logOn(DebugChannels.INFO_REQUESTS, "Exception during request: " + original.toString() + ", running locally.");
|
||||
runLocally(infoRequest);
|
||||
} catch (NoServersException e2) {
|
||||
} catch (NoServersException noServers) {
|
||||
throw original;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package com.djrapitops.plan.system.locale;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.locale.lang.*;
|
||||
|
@ -45,7 +44,6 @@ import java.util.stream.Collectors;
|
|||
@Singleton
|
||||
public class LocaleSystem implements SubSystem {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final PlanFiles files;
|
||||
private final PlanConfig config;
|
||||
private final PluginLogger logger;
|
||||
|
@ -55,13 +53,11 @@ public class LocaleSystem implements SubSystem {
|
|||
|
||||
@Inject
|
||||
public LocaleSystem(
|
||||
PlanPlugin plugin,
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.logger = logger;
|
||||
|
|
|
@ -84,6 +84,7 @@ public abstract class ConfigSystem implements SubSystem {
|
|||
setDebugMode();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
throw new EnableException("Failed to save default config: " + e.getMessage(), e);
|
||||
}
|
||||
theme.enable();
|
||||
|
|
|
@ -178,8 +178,9 @@ public class WebServer implements SubSystem {
|
|||
String alias = config.get(WebserverSettings.CERTIFICATE_ALIAS);
|
||||
|
||||
boolean startSuccessful = false;
|
||||
String keyStoreKind = keyStorePath.endsWith(".p12") ? "PKCS12" : "JKS";
|
||||
try (FileInputStream fIn = new FileInputStream(keyStorePath)) {
|
||||
KeyStore keystore = KeyStore.getInstance("JKS");
|
||||
KeyStore keystore = KeyStore.getInstance(keyStoreKind);
|
||||
|
||||
keystore.load(fIn, storepass);
|
||||
Certificate cert = keystore.getCertificate(alias);
|
||||
|
|
|
@ -163,7 +163,7 @@ public class ResponseFactory {
|
|||
public ErrorResponse basicAuthFail(WebUserAuthException e) {
|
||||
try {
|
||||
return PromptAuthorizationResponse.getBasicAuthResponse(e, versionCheckSystem, files);
|
||||
} catch (IOException e1) {
|
||||
} catch (IOException jarReadFailed) {
|
||||
return internalErrorResponse(e, "Failed to parse PromptAuthorizationResponse");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@ import org.apache.commons.text.TextStringBuilder;
|
|||
*/
|
||||
public class HtmlStructure {
|
||||
|
||||
private HtmlStructure() {
|
||||
/* Static method class */
|
||||
}
|
||||
|
||||
public static String separateWithDots(String... elements) {
|
||||
TextStringBuilder builder = new TextStringBuilder();
|
||||
builder.appendWithSeparators(elements, " • ");
|
||||
|
|
|
@ -65,7 +65,7 @@ public class Line {
|
|||
double x2 = end.getX();
|
||||
double y1 = start.getY();
|
||||
double y2 = end.getY();
|
||||
return Math.sqrt(Math.pow((x2 - x1), 2) + (Math.pow((y2 - y1), 2)));
|
||||
return Math.sqrt(Math.pow(x2 - x1, 2) + (Math.pow(y2 - y1, 2)));
|
||||
}
|
||||
|
||||
public double getPerpendicularDistance(Point from) {
|
||||
|
|
|
@ -45,7 +45,7 @@ class ActivityStackGraph extends StackGraph {
|
|||
StackDataSet[] dataSets = new StackDataSet[groups.length];
|
||||
|
||||
for (int i = 0; i < groups.length; i++) {
|
||||
dataSets[i] = new StackDataSet(new ArrayList<>(), groups[i], colors[(i) % maxCol]);
|
||||
dataSets[i] = new StackDataSet(new ArrayList<>(), groups[i], colors[i % maxCol]);
|
||||
}
|
||||
|
||||
for (Long date : activityData.navigableKeySet()) {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
name: Plan
|
||||
author: Rsl1122
|
||||
main: com.djrapitops.plan.PlanBungee
|
||||
version: 4.9.1
|
||||
version: 4.9.2
|
||||
softdepend:
|
||||
- AdvancedBan
|
||||
- LiteBans
|
||||
- LuckPerms
|
||||
- nuVotifier
|
||||
- ViaVersion
|
|
@ -1,7 +1,8 @@
|
|||
name: Plan
|
||||
author: Rsl1122
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 4.9.1
|
||||
version: 4.9.2
|
||||
api-version: 1.13
|
||||
softdepend:
|
||||
- ASkyBlock
|
||||
- AdvancedAchievements
|
||||
|
@ -19,6 +20,7 @@ softdepend:
|
|||
- LuckPerms
|
||||
- mcMMO
|
||||
- MinigamesLib
|
||||
- nuVotifier
|
||||
- ProtocolSupport
|
||||
- RedProtect
|
||||
- SuperbVote
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -35,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
class GeoInfoTest {
|
||||
|
||||
@Test
|
||||
void automaticallyHidesLast16Bits() throws NoSuchAlgorithmException, UnknownHostException {
|
||||
void automaticallyHidesLast16Bits() throws UnknownHostException {
|
||||
InetAddress test = InetAddress.getByName("1.2.3.4");
|
||||
String expected = "1.2.xx.xx";
|
||||
String result = new GeoInfo(test, "Irrelevant", 3).getIp();
|
||||
|
|
|
@ -95,7 +95,7 @@ class TPSMutatorTest {
|
|||
long expected = TimeAmount.MONTH.toMillis(2L) - periodLength;
|
||||
|
||||
TPSMutator tpsMutator = new TPSMutator(testData.stream()
|
||||
.filter(tps -> (tps.getDate() - time) % (periodLength) == 0)
|
||||
.filter(tps -> (tps.getDate() - time) % periodLength == 0)
|
||||
.collect(Collectors.toList()));
|
||||
assertFalse(tpsMutator.all().isEmpty());
|
||||
assertNotEquals(testData, tpsMutator.all());
|
||||
|
@ -111,7 +111,7 @@ class TPSMutatorTest {
|
|||
|
||||
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
|
||||
TPSMutator tpsMutator = new TPSMutator(testData.stream()
|
||||
.filter(tps -> (tps.getDate() - time) % (periodLength) == 0)
|
||||
.filter(tps -> (tps.getDate() - time) % periodLength == 0)
|
||||
.collect(Collectors.toList()))
|
||||
.filterDataBetween(monthAgo, time);
|
||||
|
||||
|
@ -131,7 +131,7 @@ class TPSMutatorTest {
|
|||
Collections.shuffle(randomOrder);
|
||||
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
|
||||
TPSMutator tpsMutator = new TPSMutator(randomOrder.stream()
|
||||
.filter(tps -> (tps.getDate() - time) % (periodLength) == 0)
|
||||
.filter(tps -> (tps.getDate() - time) % periodLength == 0)
|
||||
.collect(Collectors.toList()))
|
||||
.filterDataBetween(monthAgo, time);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,12 +16,19 @@
|
|||
*/
|
||||
package com.djrapitops.plan.db;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import utilities.DBPreparer;
|
||||
import utilities.RandomData;
|
||||
import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Test for the H2 database
|
||||
|
@ -29,21 +36,34 @@ import static org.junit.Assert.assertEquals;
|
|||
* @author Rsl1122, Fuzzlemann
|
||||
* @see SQLiteTest
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class H2Test extends CommonDBTest {
|
||||
@RunWith(JUnitPlatform.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class H2Test implements DatabaseTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
handleSetup("H2");
|
||||
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||
|
||||
private static PlanSystem system;
|
||||
private static Database database;
|
||||
|
||||
@BeforeAll
|
||||
static void setupDatabase(@TempDir Path temp) throws Exception {
|
||||
system = new PluginMockComponent(temp).getPlanSystem();
|
||||
database = new DBPreparer(system, TEST_PORT_NUMBER).prepareH2()
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testH2GetConfigName() {
|
||||
assertEquals("h2", db.getType().getConfigName());
|
||||
@Override
|
||||
public Database db() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testH2GetName() {
|
||||
assertEquals("H2", db.getType().getName());
|
||||
@Override
|
||||
public UUID serverUUID() {
|
||||
return system.getServerInfo().getServerUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanSystem system() {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue