run.smt.ktest.db.query.impl.SelectBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktest-db Show documentation
Show all versions of ktest-db Show documentation
Database intergration for kTest
package run.smt.ktest.db.query.impl
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
/**
* Represents SELECT query
*/
class SelectBuilder(_query: String? = null) : RespondingQueryImpl(_query) { init {
singleLoader { jdbcTemplate ->
val jdbc = NamedParameterJdbcTemplate(jdbcTemplate)
if (forPrimitive) {
jdbc.queryForObject(query, parameterImplementation(), mapTo.java)
} else {
jdbc.queryForObject(query, parameterImplementation(), SimpleRowMapper(mapTo))
}
}
listLoader { jdbcTemplate ->
val jdbc = NamedParameterJdbcTemplate(jdbcTemplate)
if (forPrimitive) {
jdbc.queryForList(query, parameterImplementation(), mapTo.java)
} else {
jdbc.query(query, parameterImplementation(), SimpleRowMapper(mapTo))
}
}
mapLoader { jdbcTemplate ->
NamedParameterJdbcTemplate(jdbcTemplate).queryForMap(query, parameterImplementation())
}
} }