From 3d7f07980df7286dd20bec699ee624e3003d598a Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 7 Jun 2024 13:25:05 +0200 Subject: [PATCH 1/3] DOPE-217: added usage for the ignored parameters inside the Primitive type ArrayType --- .../expression/unaliased/type/Primitive.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt index dbfc82b9..93ac3c52 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt @@ -12,7 +12,11 @@ import ch.ergon.dope.validtype.ValidType class Primitive : TypeExpression { private val queryString: String - override fun toDopeQuery(): DopeQuery = DopeQuery(queryString = queryString, parameters = emptyMap()) + private val parameters = mutableMapOf() + + override fun toDopeQuery(): DopeQuery { + return DopeQuery(queryString = queryString, parameters = parameters) + } constructor(value: Number) { this.queryString = "$value" @@ -30,7 +34,11 @@ class Primitive : TypeExpression { } constructor(collection: Collection>) { - this.queryString = collection.joinToString(separator = ", ", prefix = "[", postfix = "]") { it.toDopeQuery().queryString } + this.queryString = collection.joinToString(separator = ", ", prefix = "[", postfix = "]") { + val dopeQuery = it.toDopeQuery() + parameters.putAll(dopeQuery.parameters) + dopeQuery.queryString + } } private constructor(primitiveType: PrimitiveType) { From f79dd89e38c22f04d2c66009eef94e2f9a50d3fc Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 7 Jun 2024 13:50:47 +0200 Subject: [PATCH 2/3] DOPE-217: added test --- .../expression/unaliased/type/Primitive.kt | 38 ++++++++++--------- .../kotlin/ch/ergon/dope/ParameterizedTest.kt | 16 +++++++- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt index 93ac3c52..7b0c5e6f 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt @@ -11,43 +11,47 @@ import ch.ergon.dope.validtype.StringType import ch.ergon.dope.validtype.ValidType class Primitive : TypeExpression { - private val queryString: String - private val parameters = mutableMapOf() + private val dopeQuery: DopeQuery - override fun toDopeQuery(): DopeQuery { - return DopeQuery(queryString = queryString, parameters = parameters) - } + override fun toDopeQuery(): DopeQuery = dopeQuery constructor(value: Number) { - this.queryString = "$value" + this.dopeQuery = DopeQuery(queryString = "$value", parameters = emptyMap()) } constructor(value: String) { - this.queryString = "\"$value\"" + this.dopeQuery = DopeQuery(queryString = "\"$value\"", parameters = emptyMap()) } constructor(value: Boolean) { - this.queryString = when (value) { - true -> TRUE.queryString - false -> FALSE.queryString - } + this.dopeQuery = DopeQuery( + queryString = when (value) { + true -> TRUE.toDopeQuery().queryString + false -> FALSE.toDopeQuery().queryString + }, + parameters = emptyMap(), + ) } constructor(collection: Collection>) { - this.queryString = collection.joinToString(separator = ", ", prefix = "[", postfix = "]") { - val dopeQuery = it.toDopeQuery() - parameters.putAll(dopeQuery.parameters) - dopeQuery.queryString - } + val dopeQueryCollection = collection.map { it.toDopeQuery() } + this.dopeQuery = DopeQuery( + queryString = dopeQueryCollection.joinToString(separator = ", ", prefix = "[", postfix = "]") { it.queryString }, + parameters = dopeQueryCollection.fold(emptyMap()) { parameters, field -> + parameters + field.parameters + }, + ) } private constructor(primitiveType: PrimitiveType) { - this.queryString = when (primitiveType) { + val queryString = when (primitiveType) { PrimitiveType.NULL -> "NULL" PrimitiveType.MISSING -> "MISSING" PrimitiveType.TRUE -> "TRUE" PrimitiveType.FALSE -> "FALSE" } + + this.dopeQuery = DopeQuery(queryString, emptyMap()) } companion object { diff --git a/core/src/test/kotlin/ch/ergon/dope/ParameterizedTest.kt b/core/src/test/kotlin/ch/ergon/dope/ParameterizedTest.kt index 5bdcd865..4ff93687 100644 --- a/core/src/test/kotlin/ch/ergon/dope/ParameterizedTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/ParameterizedTest.kt @@ -8,15 +8,16 @@ import ch.ergon.dope.resolvable.expression.unaliased.type.logical.or import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isEqualTo import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isNotEqualTo import ch.ergon.dope.resolvable.expression.unaliased.type.stringfunction.concat +import ch.ergon.dope.resolvable.expression.unaliased.type.toArrayType import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType import junit.framework.TestCase.assertEquals -import kotlin.test.BeforeTest +import org.junit.jupiter.api.BeforeEach import kotlin.test.Test class ParameterizedTest { private lateinit var create: QueryBuilder - @BeforeTest + @BeforeEach fun setup() { create = QueryBuilder() } @@ -138,4 +139,15 @@ class ParameterizedTest { assertEquals(value6, parameters["$3"]) assertEquals(6, parameters.size) } + + @Test + fun `should get correct value inside array parameters`() { + val parameterValue = 3 + val parameter = parameterValue.asParameter() + + val parameters = create.select(listOf(parameter).toArrayType()).build().parameters + + assertEquals(parameterValue, parameters["$1"]) + assertEquals(1, parameters.size) + } } From 7535a3a1154940cea7c5800386cd7a27f69413c9 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 7 Jun 2024 14:24:35 +0200 Subject: [PATCH 3/3] DOPE-217: renaming --- .../resolvable/expression/unaliased/type/Primitive.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt index 7b0c5e6f..812142e9 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/Primitive.kt @@ -34,11 +34,11 @@ class Primitive : TypeExpression { } constructor(collection: Collection>) { - val dopeQueryCollection = collection.map { it.toDopeQuery() } + val dopeQueries = collection.map { it.toDopeQuery() } this.dopeQuery = DopeQuery( - queryString = dopeQueryCollection.joinToString(separator = ", ", prefix = "[", postfix = "]") { it.queryString }, - parameters = dopeQueryCollection.fold(emptyMap()) { parameters, field -> - parameters + field.parameters + queryString = dopeQueries.joinToString(separator = ", ", prefix = "[", postfix = "]") { it.queryString }, + parameters = dopeQueries.fold(emptyMap()) { parameters, dopeQueryElement -> + parameters + dopeQueryElement.parameters }, ) }