refactoring: RequesterFactory
This commit is contained in:
@@ -230,7 +230,7 @@ class Connection(
|
|||||||
logger?.debug("$duration ms for query: $sqlForLog", values)
|
logger?.debug("$duration ms for query: $sqlForLog", values)
|
||||||
return result
|
return result
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logger?.info("Query Error: $sqlForLog", e)
|
logger?.info("Query Error: $sqlForLog, $values", e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ class Requester(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addQuery(queriesDirectory: File): Requester {
|
fun addQuery(queriesDirectory: File): Requester {
|
||||||
queriesDirectory.walk().filter { it.isDirectory }.forEach { directory ->
|
queriesDirectory.walk()
|
||||||
val path = directory.name
|
.filter { it.isFile && it.extension == "sql" }
|
||||||
directory.walk().filter { it.isFile }.forEach { file ->
|
.forEach {
|
||||||
val sql = file.readText()
|
val path = it.parentFile.nameWithoutExtension
|
||||||
val fullpath = "$path/${file.nameWithoutExtension}"
|
addQuery("$path/${it.nameWithoutExtension}", it.readText())
|
||||||
queries[fullpath] = Query(sql, connection)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -66,20 +64,26 @@ class Requester(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RequesterFactory(
|
class RequesterFactory(
|
||||||
private val host: String = "localhost",
|
private val connection: Connection,
|
||||||
private val port: Int = 5432,
|
|
||||||
private val database: String = "dc-project",
|
|
||||||
private val username: String = "dc-project",
|
|
||||||
private val password: String = "dc-project",
|
|
||||||
private val queriesDirectory: File? = null,
|
private val queriesDirectory: File? = null,
|
||||||
private val functionsDirectory: File? = null
|
private val functionsDirectory: File? = null
|
||||||
) {
|
) {
|
||||||
fun createRequester(): Requester {
|
constructor(
|
||||||
val con =
|
host: String = "localhost",
|
||||||
Connection(host = host, port = port, database = database, username = username, password = password)
|
port: Int = 5432,
|
||||||
val req = Requester(con)
|
database: String = "dc-project",
|
||||||
|
username: String = "dc-project",
|
||||||
|
password: String = "dc-project",
|
||||||
|
queriesDirectory: File? = null,
|
||||||
|
functionsDirectory: File? = null
|
||||||
|
): this(
|
||||||
|
Connection(host = host, port = port, database = database, username = username, password = password),
|
||||||
|
queriesDirectory,
|
||||||
|
functionsDirectory
|
||||||
|
)
|
||||||
|
|
||||||
return initRequester(req)
|
fun createRequester(): Requester {
|
||||||
|
return initRequester(Requester(connection))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRequester(req: Requester): Requester {
|
private fun initRequester(req: Requester): Requester {
|
||||||
|
|||||||
Reference in New Issue
Block a user