remove id in EntityI interface & remove usless EntitiesCollections
This commit is contained in:
@@ -38,14 +38,14 @@ 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?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
): R? {
|
||||
val primaryObject = values.firstOrNull {
|
||||
it is EntityI<*> && typeReference.type.typeName == it::class.java.name
|
||||
it is EntityI && typeReference.type.typeName == it::class.java.name
|
||||
} as R?
|
||||
val result = exec(sql, compileArgs(values))
|
||||
val json = result.rows[0].getString(0)
|
||||
@@ -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)
|
||||
|
||||
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)
|
||||
|
||||
override fun <R: EntityI<*>> select(
|
||||
override fun <R: EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
values: List<Any?>,
|
||||
@@ -96,7 +96,7 @@ class Connection(
|
||||
val result = exec(sql, compileArgs(values))
|
||||
val json = result.rows[0].getString(0)
|
||||
return if (json === null) {
|
||||
listOf<EntityI<*>>() as List<R>
|
||||
listOf<EntityI>() as List<R>
|
||||
} else {
|
||||
serializer.deserializeList(json, typeReference)
|
||||
}.also {
|
||||
@@ -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)
|
||||
|
||||
override fun <R: EntityI<*>> select(
|
||||
override fun <R: EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
@@ -131,7 +131,7 @@ class Connection(
|
||||
return line.run {
|
||||
val json = rows[0].getString(0)
|
||||
val entities = if (json === null) {
|
||||
listOf<EntityI<*>>() as List<R>
|
||||
listOf<EntityI>() as List<R>
|
||||
} else {
|
||||
serializer.deserializeList(json, typeReference)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI<*>> select(
|
||||
inline fun <reified R: EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
@@ -155,7 +155,7 @@ class Connection(
|
||||
): Paginated<R> =
|
||||
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,7 +166,7 @@ class Connection(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified R: EntityI<*>> select(
|
||||
inline fun <reified R: EntityI> select(
|
||||
sql: String,
|
||||
values: Map<String, Any?>,
|
||||
noinline block: SelectCallback<R> = {}
|
||||
@@ -201,10 +201,8 @@ class Connection(
|
||||
|
||||
private fun compileArgs(values: List<Any?>): List<Any?> {
|
||||
return values.map {
|
||||
if (it is EntityI<*>) {
|
||||
serializer.serialize(it).apply {
|
||||
serializer.collection.set<Any?, EntityI<Any?>>(it as EntityI<Any?>)
|
||||
}
|
||||
if (it is EntityI) {
|
||||
serializer.serialize(it)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,13 +28,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: List<Any?> = emptyList(),
|
||||
noinline block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
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? =
|
||||
@@ -43,7 +43,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
/**
|
||||
* 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)
|
||||
|
||||
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,7 +82,7 @@ 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> =
|
||||
@@ -91,7 +91,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
/**
|
||||
* 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)
|
||||
|
||||
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,7 +137,7 @@ 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(),
|
||||
@@ -145,7 +145,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
||||
): Paginated<R> =
|
||||
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?>,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -12,7 +12,7 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
|
||||
/* Select One */
|
||||
|
||||
override fun <R: EntityI<*>> select(
|
||||
override fun <R: EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: List<Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -20,13 +20,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)
|
||||
|
||||
override fun <R: EntityI<*>> select(
|
||||
override fun <R: EntityI> select(
|
||||
typeReference: TypeReference<R>,
|
||||
values: Map<String, Any?>,
|
||||
block: (QueryResult, R?) -> Unit
|
||||
@@ -34,7 +34,7 @@ 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? =
|
||||
@@ -42,7 +42,7 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
|
||||
/* 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 +50,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)
|
||||
|
||||
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 +64,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)
|
||||
|
||||
override fun <R: EntityI<*>> select(
|
||||
override fun <R: EntityI> select(
|
||||
page: Int,
|
||||
limit: Int,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
@@ -82,7 +82,7 @@ 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(),
|
||||
|
||||
Reference in New Issue
Block a user