From 56c67981dbce60d7c7b41b687ef36b24439f8b72 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Thu, 6 Apr 2023 21:41:10 +0200 Subject: [PATCH] test vararg for ExecutableRaw.execute --- .../fr/postgresjson/connexion/ExecutableRaw.kt | 12 ------------ .../kotlin/fr/postgresjson/serializer/Serializer.kt | 8 -------- src/test/kotlin/fr/postgresjson/ConnectionTest.kt | 11 ++++++++++- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/fr/postgresjson/connexion/ExecutableRaw.kt b/src/main/kotlin/fr/postgresjson/connexion/ExecutableRaw.kt index 2cafb96..59249a1 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/ExecutableRaw.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/ExecutableRaw.kt @@ -7,18 +7,6 @@ import kotlin.jvm.Throws typealias SelectCallback = QueryResult.(R?) -> Unit sealed interface ExecutableRaw : Executable { - /** - * Select with one entity as argument - */ - @Throws(DataNotFoundException::class) - fun execute( - sql: String, - typeReference: TypeReference, - value: R, - block: SelectCallback = {} - ): R? = - execute(sql, typeReference, listOf(value), block) - /** * Select with [List] of parameters */ diff --git a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt index 0725087..524e0e7 100644 --- a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt +++ b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt @@ -34,14 +34,6 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) { inline fun deserialize(json: String): E? { return this.mapper.readValue(json) } - - fun deserializeList(json: String, valueTypeRef: TypeReference): E { - return mapper.readValue(json, valueTypeRef) - } - - inline fun deserializeList(json: String): E { - return deserializeList(json, object : TypeReference() {}) - } } inline fun QueryResult.deserialize(): E? { diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index 35332f8..5d5e246 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -109,7 +109,16 @@ class ConnectionTest : TestAbstract() { @Test fun `test update Entity`() { val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96")) - val objUpdated: ObjTest? = connection.execute("select ?::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), obj) + val objUpdated: ObjTest? = connection.execute("select ?::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), listOf(obj)) + assertNotNull(objUpdated) + assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id) + assertEquals("after", objUpdated.name) + } + + @Test + fun `test update Entity with vararg`() { + val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96")) + val objUpdated: ObjTest? = connection.execute("select :obj::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), "obj" to obj) assertNotNull(objUpdated) assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id) assertEquals("after", objUpdated.name)