forked from SteamWar/SteamWar
Remove outdated SQL-related Java classes (GDPRQuery, Field, SelectStatement, SqlTypeMapper, Statement) and update references across modules.
Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
@@ -19,49 +19,70 @@
|
||||
|
||||
package de.steamwar.sql
|
||||
|
||||
import de.steamwar.sql.internal.Statement
|
||||
import de.steamwar.sql.internal.Statement.ResultSetUser
|
||||
import de.steamwar.sql.internal.useDb
|
||||
import org.jetbrains.exposed.v1.core.IntegerColumnType
|
||||
import org.jetbrains.exposed.v1.core.VarCharColumnType
|
||||
import java.sql.ResultSet
|
||||
|
||||
private val getNum: ResultSetUser<Int?> = ResultSetUser { res ->
|
||||
if (res.next()) {
|
||||
res.getInt("num")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
private val getNum: (ResultSet) -> Int? = {
|
||||
if (it.next()) it.getInt("num") else null
|
||||
}
|
||||
|
||||
private val eventFightParticipation = Statement("SELECT FightPlayer.UserID, COUNT(UserID) as num FROM FightPlayer INNER JOIN Fight on FightPlayer.FightID = Fight.FightID WHERE Fight.Server LIKE '%vs%' AND FightPlayer.UserID = ? GROUP BY FightPlayer.UserID")
|
||||
private const val eventFightParticipation =
|
||||
"SELECT FightPlayer.UserID, COUNT(UserID) as num FROM FightPlayer INNER JOIN Fight on FightPlayer.FightID = Fight.FightID WHERE Fight.Server LIKE '%vs%' AND FightPlayer.UserID = ? GROUP BY FightPlayer.UserID"
|
||||
|
||||
fun getEventFightParticipation(user: SteamwarUser): Int? = eventFightParticipation.select(getNum, user.id)
|
||||
fun getEventFightParticipation(user: SteamwarUser) = useDb {
|
||||
exec(
|
||||
eventFightParticipation, args = listOf(
|
||||
IntegerColumnType() to user.getId()
|
||||
)
|
||||
) { getNum(it) }
|
||||
}
|
||||
|
||||
private val eventParticipation = Statement("SELECT FightPlayer.UserID, COUNT(DISTINCT EventID) as num FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID INNER JOIN EventFight EF on F.FightID = EF.Fight WHERE F.FightID = FightPlayer.FightID AND FightPlayer.FightID = EF.Fight AND F.Server LIKE '%vs%' AND FightPlayer.UserID = ? GROUP BY FightPlayer.UserID")
|
||||
private const val eventParticipation =
|
||||
"SELECT FightPlayer.UserID, COUNT(DISTINCT EventID) as num FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID INNER JOIN EventFight EF on F.FightID = EF.Fight WHERE F.FightID = FightPlayer.FightID AND FightPlayer.FightID = EF.Fight AND F.Server LIKE '%vs%' AND FightPlayer.UserID = ? GROUP BY FightPlayer.UserID"
|
||||
|
||||
fun getEventParticipation(user: SteamwarUser): Int? = eventParticipation.select(getNum, user.id)
|
||||
fun getEventParticipation(user: SteamwarUser) = useDb {
|
||||
exec(
|
||||
eventParticipation, args = listOf(
|
||||
IntegerColumnType() to user.getId()
|
||||
)
|
||||
) { getNum(it) }
|
||||
}
|
||||
|
||||
private val acceptedSchematics = Statement("SELECT NodeOwner, COUNT(DISTINCT NodeId) AS num FROM SchematicNode WHERE NodeType != 'normal' AND NodeType IS NOT NULL AND NodeType NOT LIKE 'c%' AND NodeOwner = ?")
|
||||
private const val acceptedSchematics =
|
||||
"SELECT NodeOwner, COUNT(DISTINCT NodeId) AS num FROM SchematicNode WHERE NodeType != 'normal' AND NodeType IS NOT NULL AND NodeType NOT LIKE 'c%' AND NodeOwner = ?"
|
||||
|
||||
fun getAcceptedSchematics(user: SteamwarUser): Int? = acceptedSchematics.select(getNum, user.id)
|
||||
fun getAcceptedSchematics(user: SteamwarUser) =
|
||||
useDb { exec(acceptedSchematics, args = listOf(IntegerColumnType() to user.getId())) { getNum(it) } }
|
||||
|
||||
private val fightCount = Statement("SELECT COUNT(*) AS num FROM FightPlayer WHERE UserID = ?")
|
||||
private val fightCount = "SELECT COUNT(*) AS num FROM FightPlayer WHERE UserID = ?"
|
||||
|
||||
fun getFightCount(user: SteamwarUser): Int? = fightCount.select(getNum, user.id)
|
||||
fun getFightCount(user: SteamwarUser) =
|
||||
useDb { exec(fightCount, args = listOf(IntegerColumnType() to user.getId())) { getNum(it) } }
|
||||
|
||||
private val rankedList = Statement("SELECT UserName, Elo FROM UserData, UserElo WHERE UserID = id AND GameMode = ? AND Season = ? ORDER BY Elo DESC")
|
||||
private const val rankedList =
|
||||
"SELECT UserName, Elo FROM UserData, UserElo WHERE UserID = id AND GameMode = ? AND Season = ? ORDER BY Elo DESC"
|
||||
|
||||
fun getRankedList(gamemode: String): List<Pair<String, Int>> = rankedList.select({ res ->
|
||||
val list = mutableListOf<Pair<String, Int>>()
|
||||
while (res.next()) {
|
||||
list.add(res.getString("UserName") to res.getInt("Elo"))
|
||||
fun getRankedList(gamemode: String): List<Pair<String, Int>> = useDb {
|
||||
exec(rankedList, args = listOf(VarCharColumnType() to gamemode, IntegerColumnType() to Season.getSeason())) {
|
||||
val list = mutableListOf<Pair<String, Int>>()
|
||||
while (it.next()) {
|
||||
list.add(it.getString("UserName") to it.getInt("Elo"))
|
||||
}
|
||||
list
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
private const val fightList =
|
||||
"SELECT DATE(StartTime) AS Datum, GameMode AS Modus, COUNT(*) AS Anzahl FROM Fight WHERE DATE(StartTime) >= DATE(NOW()) - INTERVAL 1 WEEK GROUP BY Datum, GameMode ORDER BY Datum ASC"
|
||||
|
||||
fun getFightList(): List<Triple<String, String, Int>> = useDb {
|
||||
exec(fightList) {
|
||||
val list = mutableListOf<Triple<String, String, Int>>()
|
||||
while (it.next()) {
|
||||
list.add(Triple(it.getString("Datum"), it.getString("Modus"), it.getInt("Anzahl")))
|
||||
}
|
||||
list
|
||||
}
|
||||
list
|
||||
}, gamemode, Season.getSeason())
|
||||
|
||||
private val fightList = Statement("SELECT DATE(StartTime) AS Datum, GameMode AS Modus, COUNT(*) AS Anzahl FROM Fight WHERE DATE(StartTime) >= DATE(NOW()) - INTERVAL 1 WEEK GROUP BY Datum, GameMode ORDER BY Datum ASC")
|
||||
|
||||
fun getFightList(): List<Triple<String, String, Int>> = fightList.select({ res ->
|
||||
val list = mutableListOf<Triple<String, String, Int>>()
|
||||
while (res.next()) {
|
||||
list.add(Triple(res.getString("Datum"), res.getString("Modus"), res.getInt("Anzahl")))
|
||||
}
|
||||
list
|
||||
})
|
||||
} ?: emptyList()
|
||||
|
||||
Reference in New Issue
Block a user