internal change: make maxAttempts easier to specify

This commit is contained in:
hrj 2021-04-12 16:19:06 +05:30
parent 8840a13a8f
commit e8416ff70e
1 changed files with 14 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import lc.database.DBConn
import java.sql.Statement
import java.sql.PreparedStatement
class Statements(dbConn: DBConn) {
class Statements(dbConn: DBConn, maxAttempts: Int) {
private val stmt = dbConn.getStatement()
@ -71,13 +71,14 @@ class Statements(dbConn: DBConn) {
)
val tokenPstmt: PreparedStatement = dbConn.con.prepareStatement(
"SELECT token " +
"FROM challenge " +
"WHERE attempted < 10 AND " +
"contentLevel = ? AND " +
"contentType = ? AND " +
"contentInput = ? " +
"ORDER BY RAND() LIMIT 1"
s"""
SELECT token
FROM challenge
WHERE attempted < $maxAttempts AND
contentLevel = ? AND
contentType = ? AND
contentInput = ?
ORDER BY RAND() LIMIT 1"""
)
val deleteAnswerPstmt: PreparedStatement = dbConn.con.prepareStatement(
@ -85,9 +86,9 @@ class Statements(dbConn: DBConn) {
)
val challengeGCPstmt: PreparedStatement = dbConn.con.prepareStatement(
"DELETE FROM challenge " +
"WHERE attempted >= 10 AND " +
"token NOT IN (SELECT token FROM mapId)"
s"""DELETE FROM challenge
WHERE attempted >= $maxAttempts AND
token NOT IN (SELECT token FROM mapId)"""
)
val mapIdGCPstmt: PreparedStatement = dbConn.con.prepareStatement(
@ -110,5 +111,6 @@ class Statements(dbConn: DBConn) {
object Statements {
private val dbConn: DBConn = new DBConn()
val tlStmts: ThreadLocal[Statements] = ThreadLocal.withInitial(() => new Statements(dbConn))
private val maxAttempts = 10
val tlStmts: ThreadLocal[Statements] = ThreadLocal.withInitial(() => new Statements(dbConn, maxAttempts))
}