From e8416ff70ef7757f2c459fcf8ef357cf35149f05 Mon Sep 17 00:00:00 2001 From: hrj Date: Mon, 12 Apr 2021 16:19:06 +0530 Subject: [PATCH] internal change: make maxAttempts easier to specify --- src/main/scala/lc/database/statements.scala | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/scala/lc/database/statements.scala b/src/main/scala/lc/database/statements.scala index 1439b56..ec0ae24 100644 --- a/src/main/scala/lc/database/statements.scala +++ b/src/main/scala/lc/database/statements.scala @@ -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)) }