|
@@ -16,9 +16,10 @@ class BenchmarkSqlStore(
|
|
|
) : BenchmarkStore(settings) {
|
|
|
|
|
|
companion object {
|
|
|
- private const val SELECT_WORLD: String = "select * from world where id = ?"
|
|
|
+ private const val LOAD_WORLDS: String = "select id, randomNumber from world"
|
|
|
+ private const val SELECT_WORLD: String = "select id, randomNumber from world where id = ?"
|
|
|
private const val UPDATE_WORLD: String = "update world set randomNumber = ? where id = ?"
|
|
|
- private const val SELECT_ALL_FORTUNES: String = "select * from fortune"
|
|
|
+ private const val SELECT_ALL_FORTUNES: String = "select id, message from fortune"
|
|
|
}
|
|
|
|
|
|
private val dataSource: HikariDataSource by lazy {
|
|
@@ -63,19 +64,17 @@ class BenchmarkSqlStore(
|
|
|
override fun replaceWorlds(worlds: List<World>) {
|
|
|
dataSource.connection.use { con: Connection ->
|
|
|
val stmtSelect = con.prepareStatement(SELECT_WORLD)
|
|
|
- val stmtUpdate = con.prepareStatement(UPDATE_WORLD)
|
|
|
-
|
|
|
worlds.forEach {
|
|
|
- val worldId = it.id
|
|
|
- val newRandomNumber = it.randomNumber
|
|
|
-
|
|
|
- stmtSelect.setInt(1, worldId)
|
|
|
+ stmtSelect.setInt(1, it.id)
|
|
|
val rs = stmtSelect.executeQuery()
|
|
|
rs.next()
|
|
|
rs.getInt(2) // Read 'randomNumber' to comply with Test type 5, point 6
|
|
|
+ }
|
|
|
|
|
|
- stmtUpdate.setInt(1, newRandomNumber)
|
|
|
- stmtUpdate.setInt(2, worldId)
|
|
|
+ val stmtUpdate = con.prepareStatement(UPDATE_WORLD)
|
|
|
+ worlds.forEach {
|
|
|
+ stmtUpdate.setInt(1, it.randomNumber)
|
|
|
+ stmtUpdate.setInt(2, it.id)
|
|
|
stmtUpdate.executeUpdate()
|
|
|
}
|
|
|
}
|
|
@@ -83,7 +82,7 @@ class BenchmarkSqlStore(
|
|
|
|
|
|
override fun initWorldsCache(cache: Cache<Int, CachedWorld>) {
|
|
|
dataSource.connection.use { con: Connection ->
|
|
|
- val stmtSelect = con.prepareStatement("select * from world")
|
|
|
+ val stmtSelect = con.prepareStatement(LOAD_WORLDS)
|
|
|
val rs = stmtSelect.executeQuery()
|
|
|
|
|
|
while (rs.next()) {
|