Skip to content

Commit

Permalink
close cassandra session upon query execution
Browse files Browse the repository at this point in the history
  • Loading branch information
celcius112 committed Sep 3, 2024
1 parent c90ea4f commit fb80f9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ import com.ekino.oss.jcv.db.cassandra.DbComparatorCassandra
import com.ekino.oss.jcv.db.config.DBValidators
import org.skyscreamer.jsonassert.JSONCompareMode

class DBComparatorBuilder {
class DBComparatorBuilder(
private var mode: JSONCompareMode,
private var validators: List<JsonValidator<*>>
) {

constructor()

constructor(
mode: JSONCompareMode,
validators: List<JsonValidator<*>>
) {
this.mode = mode
this.validators = validators
}

private lateinit var mode: JSONCompareMode
private lateinit var validators: List<JsonValidator<*>>
// todo(any): this datasource should not be nullable.
// It is however required because a builder can be built without one.
private var datasource: CassandraDataSource? = null
private var customMapper: CassandraMapper? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import com.ekino.oss.jcv.db.model.RowModel
import com.ekino.oss.jcv.db.model.TableModel
import java.net.InetSocketAddress

class QueryConverter(private val dataSource: CassandraDataSource? = null) {
class QueryConverter(private val dataSource: CassandraDataSource?) {
fun fromQueryToTableModel(query: String): TableModel {
val session = buildCqlSession(dataSource)

val resultSet = session.execute(query)
return fromResultSetToTableModel(resultSet)
return buildCqlSession().use { session ->
val resultSet = session.execute(query)
fromResultSetToTableModel(resultSet)
}
}

private fun buildCqlSession(dataSource: CassandraDataSource? = null): CqlSession {
dataSource ?: throw DbAssertException("You have to defined a valida datource")
private fun buildCqlSession(): CqlSession {
dataSource ?: throw DbAssertException("You have to defined a valida datasource")

val builder = CqlSession
.builder()
Expand Down

0 comments on commit fb80f9b

Please sign in to comment.