Lint
This commit is contained in:
@@ -22,7 +22,7 @@ class Connection(
|
||||
private val password: String,
|
||||
private val host: String = "localhost",
|
||||
private val port: Int = 5432
|
||||
): Executable {
|
||||
) : Executable {
|
||||
private lateinit var connection: ConnectionPool<PostgreSQLConnection>
|
||||
private val serializer = Serializer()
|
||||
private val logger: Logger? by LoggerDelegate()
|
||||
@@ -38,7 +38,7 @@ class Connection(
|
||||
|
||||
fun <A> inTransaction(f: (Connection) -> CompletableFuture<A>) = connect().inTransaction(f)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?>,
|
||||
@@ -62,14 +62,14 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
sql: String,
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(sql, object: TypeReference<R>() {}, values, block)
|
||||
select(sql, object : TypeReference<R>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
@@ -80,14 +80,14 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
sql: String,
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(sql, object: TypeReference<R>() {}, values, block)
|
||||
select(sql, object : TypeReference<R>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?>,
|
||||
@@ -104,14 +104,14 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
sql: String,
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(sql, object: TypeReference<List<R>>() {}, values, block)
|
||||
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
@@ -146,16 +146,16 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
values: Map<String, Any?> = emptyMap(),
|
||||
noinline block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R> =
|
||||
select(sql, page, limit, object: TypeReference<List<R>>() {}, values, block)
|
||||
select(sql, page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: Map<String, Any?>,
|
||||
@@ -166,12 +166,12 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
sql: String,
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(sql, object: TypeReference<List<R>>() {}, values, block)
|
||||
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
override fun exec(sql: String, values: List<Any?>): QueryResult {
|
||||
return stopwatchQuery(sql, values) {
|
||||
@@ -256,6 +256,5 @@ class Connection(
|
||||
logger?.info("Query Error: $sqlForLog, $values", e)
|
||||
throw e
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,33 +13,33 @@ interface EmbedExecutable {
|
||||
/**
|
||||
* Select One entity with list of parameters
|
||||
*/
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?> = emptyList(),
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
/* Select Miltiples */
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?> = emptyList(),
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R>
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: Map<String, Any?>,
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R>
|
||||
|
||||
/* Select Paginated */
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
|
||||
@@ -7,14 +7,14 @@ import fr.postgresjson.entity.EntityI
|
||||
interface Executable {
|
||||
/* Select One */
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?> = emptyList(),
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
@@ -23,14 +23,14 @@ interface Executable {
|
||||
|
||||
/* Select Miltiples */
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?> = emptyList(),
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R>
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: Map<String, Any?>,
|
||||
@@ -39,7 +39,7 @@ interface Executable {
|
||||
|
||||
/* Select Paginated */
|
||||
|
||||
fun <R: EntityI> select(
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.github.jasync.sql.db.QueryResult
|
||||
import fr.postgresjson.definition.Function
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
class Function(val definition: Function, override val connection: Connection): EmbedExecutable {
|
||||
class Function(val definition: Function, override val connection: Connection) : EmbedExecutable {
|
||||
override fun toString(): String {
|
||||
return definition.name
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
/**
|
||||
* Select One entity with list of parameters
|
||||
*/
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -28,22 +28,22 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
return connection.select(sql, typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(object: TypeReference<R>() {}, values, block)
|
||||
select(object : TypeReference<R>() {}, values, block)
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
value: R,
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(object: TypeReference<R>() {}, listOf(value), block)
|
||||
select(object : TypeReference<R>() {}, listOf(value), block)
|
||||
|
||||
/**
|
||||
* Select One entity with named parameters
|
||||
*/
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -54,13 +54,13 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
return connection.select(sql, typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(object: TypeReference<R>() {}, values, block)
|
||||
select(object : TypeReference<R>() {}, values, block)
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
vararg values: Pair<String, Any?>,
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
@@ -71,7 +71,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
/**
|
||||
* Select list of entities with list of parameters
|
||||
*/
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?>,
|
||||
block: (QueryResult, List<R>) -> Unit
|
||||
@@ -82,16 +82,16 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
return connection.select(sql, typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(object: TypeReference<List<R>>() {}, values, block)
|
||||
select(object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
/**
|
||||
* Select list of entities with named parameters
|
||||
*/
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: Map<String, Any?>,
|
||||
block: (QueryResult, List<R>) -> Unit
|
||||
@@ -102,13 +102,13 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
return connection.select(sql, typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(object: TypeReference<List<R>>() {}, values, block)
|
||||
select(object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
vararg values: Pair<String, Any?>,
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
@@ -119,7 +119,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
/**
|
||||
* Select Multiple with pagination
|
||||
*/
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
@@ -137,21 +137,21 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
return connection.select(sql, page, limit, typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
values: Map<String, Any?> = emptyMap(),
|
||||
noinline block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R> =
|
||||
select(page, limit, object: TypeReference<List<R>>() {}, values, block)
|
||||
select(page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
vararg values: Pair<String, Any?>,
|
||||
noinline block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R> =
|
||||
select(page, limit, object: TypeReference<List<R>>() {}, values.toMap(), block)
|
||||
select(page, limit, object : TypeReference<List<R>>() {}, values.toMap(), block)
|
||||
|
||||
/* Execute function without traitements */
|
||||
|
||||
@@ -195,11 +195,11 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
val parameters = definition.getParametersIndexedByName()
|
||||
val placeholders = values
|
||||
.filter { entry ->
|
||||
val parameter = parameters[entry.key] ?: parameters["_"+entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist")
|
||||
val parameter = parameters[entry.key] ?: parameters["_" + entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist")
|
||||
parameter.default === null || entry.value !== null
|
||||
}
|
||||
.map { entry ->
|
||||
val parameter = parameters[entry.key] ?: parameters["_"+entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist")
|
||||
val parameter = parameters[entry.key] ?: parameters["_" + entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist")
|
||||
""""${parameter.name}" := :${parameter.name}::${parameter.type}"""
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package fr.postgresjson.connexion
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
data class Paginated<T: EntityI>(
|
||||
data class Paginated<T : EntityI>(
|
||||
val result: List<T>,
|
||||
val offset: Int,
|
||||
val limit: Int,
|
||||
|
||||
@@ -4,15 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference
|
||||
import com.github.jasync.sql.db.QueryResult
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
|
||||
class Query(override val name: String, private val sql: String, override val connection: Connection): EmbedExecutable {
|
||||
class Query(override val name: String, private val sql: String, override val connection: Connection) : EmbedExecutable {
|
||||
override fun toString(): String {
|
||||
return sql
|
||||
}
|
||||
|
||||
/* Select One */
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -20,13 +19,13 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
return connection.select(this.toString(), typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(object: TypeReference<R>() {}, values, block)
|
||||
select(object : TypeReference<R>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -34,15 +33,15 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
return connection.select(this.toString(), typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> selectOne(
|
||||
inline fun <reified R : EntityI> selectOne(
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
select(object: TypeReference<R>() {}, values, block)
|
||||
select(object : TypeReference<R>() {}, values, block)
|
||||
|
||||
/* Select Multiples */
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?>,
|
||||
block: (QueryResult, List<R>) -> Unit
|
||||
@@ -50,13 +49,13 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
return connection.select(this.toString(), typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
values: List<Any?> = emptyList(),
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(object: TypeReference<List<R>>() {}, values, block)
|
||||
select(object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: Map<String, Any?>,
|
||||
block: (QueryResult, List<R>) -> Unit
|
||||
@@ -64,13 +63,13 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
return connection.select(this.toString(), typeReference, values, block)
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(object: TypeReference<List<R>>() {}, values, block)
|
||||
select(object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
override fun <R: EntityI> select(
|
||||
override fun <R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
@@ -82,13 +81,13 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
|
||||
/* Select Paginated */
|
||||
|
||||
inline fun <reified R: EntityI> select(
|
||||
inline fun <reified R : EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
values: Map<String, Any?> = emptyMap(),
|
||||
noinline block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R> =
|
||||
select(page, limit, object: TypeReference<List<R>>() {}, values, block)
|
||||
select(page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||
|
||||
/* Execute function without traitements */
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class Requester(
|
||||
password: String = "dc-project",
|
||||
queriesDirectory: File? = null,
|
||||
functionsDirectory: File? = null
|
||||
): this(
|
||||
) : this(
|
||||
Connection(host = host, port = port, database = database, username = username, password = password),
|
||||
queriesDirectory,
|
||||
functionsDirectory
|
||||
|
||||
Reference in New Issue
Block a user