From 13f5e1705d447d1fd61c1efe1f8c02884af9452b Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 12:46:51 +0900 Subject: [PATCH 1/9] fix: silently ignores exception when parameter setting to count query --- .../data/jpa/javax/JpqlEntityManagerUtils.kt | 27 ++++++++++++++++++- .../spring/data/jpa/JpqlEntityManagerUtils.kt | 27 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index dd00be131..904c41ea3 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -4,6 +4,7 @@ package com.linecorp.kotlinjdsl.support.spring.data.jpa.javax import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext +import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import javax.persistence.EntityManager @@ -71,7 +72,17 @@ internal object JpqlEntityManagerUtils { createQuery(entityManager, queryEnhancer.applySorting(sort), rendered.params, returnType.java), ) { // Lazy - createQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params, Long::class.javaObjectType) + createCountQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params) + } + } + + private fun createCountQuery( + entityManager: EntityManager, + query: String, + queryParams: Map, + ): TypedQuery { + return entityManager.createQuery(query, Long::class.javaObjectType).apply { + setCountQueryParams(this, queryParams) } } @@ -96,9 +107,23 @@ internal object JpqlEntityManagerUtils { } } + private fun setCountQueryParams(query: Query, params: Map) { + params.forEach { (name, value) -> + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } + } + } + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index 5265e69bc..9e75dd7ca 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -7,6 +7,7 @@ import com.linecorp.kotlinjdsl.render.RenderContext import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import kotlin.reflect.KClass @@ -71,7 +72,17 @@ internal object JpqlEntityManagerUtils { createQuery(entityManager, queryEnhancer.applySorting(sort), rendered.params, returnType.java), ) { // Lazy - createQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params, Long::class.javaObjectType) + createCountQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params) + } + } + + private fun createCountQuery( + entityManager: EntityManager, + query: String, + queryParams: Map, + ): TypedQuery { + return entityManager.createQuery(query, Long::class.javaObjectType).apply { + setCountQueryParams(this, queryParams) } } @@ -96,9 +107,23 @@ internal object JpqlEntityManagerUtils { } } + private fun setCountQueryParams(query: Query, params: Map) { + params.forEach { (name, value) -> + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } + } + } + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) From fe2b4b4afb3a02f7952a4101b941de99a667e7dc Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 16:30:49 +0900 Subject: [PATCH 2/9] fix: use map instead of try-catch --- .../spring/data/jpa/javax/JpqlEntityManagerUtils.kt | 11 +++-------- .../support/spring/data/jpa/JpqlEntityManagerUtils.kt | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 904c41ea3..20a1a7a17 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -4,7 +4,6 @@ package com.linecorp.kotlinjdsl.support.spring.data.jpa.javax import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import javax.persistence.EntityManager @@ -108,13 +107,11 @@ internal object JpqlEntityManagerUtils { } private fun setCountQueryParams(query: Query, params: Map) { + val parameterList = query.parameters.associateBy { it.name } + params.forEach { (name, value) -> - try { + if (parameterList.contains(name)) { query.setParameter(name, value) - } catch (e: RuntimeException) { - if (log.isDebugEnabled) { - log.debug("Silently ignoring", e) - } } } } @@ -125,5 +122,3 @@ internal object JpqlEntityManagerUtils { } } } - -private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index 9e75dd7ca..7acefefbd 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -7,7 +7,6 @@ import com.linecorp.kotlinjdsl.render.RenderContext import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery -import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import kotlin.reflect.KClass @@ -108,13 +107,11 @@ internal object JpqlEntityManagerUtils { } private fun setCountQueryParams(query: Query, params: Map) { + val parameterList = query.parameters.associateBy { it.name } + params.forEach { (name, value) -> - try { + if (parameterList.contains(name)) { query.setParameter(name, value) - } catch (e: RuntimeException) { - if (log.isDebugEnabled) { - log.debug("Silently ignoring", e) - } } } } @@ -125,5 +122,3 @@ internal object JpqlEntityManagerUtils { } } } - -private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) From e914cede53b4ff08545f4cbadef6690cc618b24d Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 17:19:51 +0900 Subject: [PATCH 3/9] fix: test error fix and change map to set --- .../data/jpa/javax/JpqlEntityManagerUtils.kt | 4 +++- .../data/jpa/javax/JpqlEntityManagerUtilsTest.kt | 15 +++++++++++++++ .../spring/data/jpa/JpqlEntityManagerUtils.kt | 2 +- .../spring/data/jpa/JpqlEntityManagerUtilsTest.kt | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 20a1a7a17..d6aed6093 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -107,7 +107,9 @@ internal object JpqlEntityManagerUtils { } private fun setCountQueryParams(query: Query, params: Map) { - val parameterList = query.parameters.associateBy { it.name } + val parameterList = query.parameters.map { + it.name + }.toHashSet() params.forEach { (name, value) -> if (parameterList.contains(name)) { diff --git a/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt b/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt index 8970b0efe..fdc7a8259 100644 --- a/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt @@ -19,6 +19,7 @@ import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancer import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import javax.persistence.EntityManager +import javax.persistence.Parameter import javax.persistence.TypedQuery @ExtendWith(MockKExtension::class) @@ -44,6 +45,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var longTypedQuery1: TypedQuery + @MockK + private lateinit var longTypedQueryParam1: Parameter + + @MockK + private lateinit var longTypedQueryParam2: Parameter + private val sort1 = Sort.by("property1") private val renderedQuery1 = "query" @@ -67,6 +74,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } excludeRecords { longTypedQuery1.equals(any()) } + excludeRecords { longTypedQueryParam1.hashCode() } + excludeRecords { longTypedQueryParam2.hashCode() } } @Test @@ -176,7 +185,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 andThen longTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { longTypedQuery1.parameters } returns setOf(longTypedQueryParam1, longTypedQueryParam2) every { longTypedQuery1.setParameter(any(), any()) } returns longTypedQuery1 + every { longTypedQueryParam1.name } returns renderedParam1.first + every { longTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -198,6 +210,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { queryEnhancer.createCountQueryFor() entityManager.createQuery(countQuery1, Long::class.javaObjectType) + longTypedQuery1.parameters + longTypedQueryParam1.name + longTypedQueryParam2.name longTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) longTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index 7acefefbd..918dfe895 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -107,7 +107,7 @@ internal object JpqlEntityManagerUtils { } private fun setCountQueryParams(query: Query, params: Map) { - val parameterList = query.parameters.associateBy { it.name } + val parameterList = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> if (parameterList.contains(name)) { diff --git a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt index aecd654a2..be7497b0c 100644 --- a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt @@ -12,6 +12,7 @@ import io.mockk.junit5.MockKExtension import io.mockk.mockkObject import io.mockk.verifySequence import jakarta.persistence.EntityManager +import jakarta.persistence.Parameter import jakarta.persistence.TypedQuery import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach @@ -44,6 +45,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var longTypedQuery1: TypedQuery + @MockK + private lateinit var longTypedQueryParam1: Parameter + + @MockK + private lateinit var longTypedQueryParam2: Parameter + private val sort1 = Sort.by("property1") private val renderedQuery1 = "query" @@ -67,6 +74,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } excludeRecords { longTypedQuery1.equals(any()) } + excludeRecords { longTypedQueryParam1.hashCode() } + excludeRecords { longTypedQueryParam2.hashCode() } } @Test @@ -176,7 +185,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 andThen longTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { longTypedQuery1.parameters } returns setOf(longTypedQueryParam1, longTypedQueryParam2) every { longTypedQuery1.setParameter(any(), any()) } returns longTypedQuery1 + every { longTypedQueryParam1.name } returns renderedParam1.first + every { longTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -198,6 +210,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { queryEnhancer.createCountQueryFor() entityManager.createQuery(countQuery1, Long::class.javaObjectType) + longTypedQuery1.parameters + longTypedQueryParam1.name + longTypedQueryParam2.name longTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) longTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } From 20cf102953a334c8bf54b9c18d350911ad27ec10 Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 17:42:34 +0900 Subject: [PATCH 4/9] fix: revert divided methods into one method --- .../data/jpa/javax/JpqlEntityManagerUtils.kt | 24 ++---------- .../jpa/javax/JpqlEntityManagerUtilsTest.kt | 38 +++++++++++++++++++ .../spring/data/jpa/JpqlEntityManagerUtils.kt | 20 +--------- .../data/jpa/JpqlEntityManagerUtilsTest.kt | 38 +++++++++++++++++++ 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index d6aed6093..2914210cd 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -71,17 +71,7 @@ internal object JpqlEntityManagerUtils { createQuery(entityManager, queryEnhancer.applySorting(sort), rendered.params, returnType.java), ) { // Lazy - createCountQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params) - } - } - - private fun createCountQuery( - entityManager: EntityManager, - query: String, - queryParams: Map, - ): TypedQuery { - return entityManager.createQuery(query, Long::class.javaObjectType).apply { - setCountQueryParams(this, queryParams) + createQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params, Long::class.javaObjectType) } } @@ -106,10 +96,8 @@ internal object JpqlEntityManagerUtils { } } - private fun setCountQueryParams(query: Query, params: Map) { - val parameterList = query.parameters.map { - it.name - }.toHashSet() + private fun setParams(query: Query, params: Map) { + val parameterList = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> if (parameterList.contains(name)) { @@ -117,10 +105,4 @@ internal object JpqlEntityManagerUtils { } } } - - private fun setParams(query: Query, params: Map) { - params.forEach { (name, value) -> - query.setParameter(name, value) - } - } } diff --git a/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt b/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt index fdc7a8259..fa0d2a70e 100644 --- a/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-data-jpa-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtilsTest.kt @@ -42,6 +42,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + @MockK private lateinit var longTypedQuery1: TypedQuery @@ -76,6 +82,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { longTypedQuery1.equals(any()) } excludeRecords { longTypedQueryParam1.hashCode() } excludeRecords { longTypedQueryParam2.hashCode() } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -85,7 +93,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -96,6 +107,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -108,7 +122,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -120,6 +137,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -132,7 +152,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -143,6 +166,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -155,7 +181,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -167,6 +196,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -184,7 +216,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 andThen longTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first every { longTypedQuery1.parameters } returns setOf(longTypedQueryParam1, longTypedQueryParam2) every { longTypedQuery1.setParameter(any(), any()) } returns longTypedQuery1 every { longTypedQueryParam1.name } returns renderedParam1.first @@ -205,6 +240,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { queryEnhancer.applySorting(sort1) entityManager.createQuery(sortedQuery1, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index 918dfe895..6f3400be4 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -71,17 +71,7 @@ internal object JpqlEntityManagerUtils { createQuery(entityManager, queryEnhancer.applySorting(sort), rendered.params, returnType.java), ) { // Lazy - createCountQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params) - } - } - - private fun createCountQuery( - entityManager: EntityManager, - query: String, - queryParams: Map, - ): TypedQuery { - return entityManager.createQuery(query, Long::class.javaObjectType).apply { - setCountQueryParams(this, queryParams) + createQuery(entityManager, queryEnhancer.createCountQueryFor(), rendered.params, Long::class.javaObjectType) } } @@ -106,7 +96,7 @@ internal object JpqlEntityManagerUtils { } } - private fun setCountQueryParams(query: Query, params: Map) { + private fun setParams(query: Query, params: Map) { val parameterList = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> @@ -115,10 +105,4 @@ internal object JpqlEntityManagerUtils { } } } - - private fun setParams(query: Query, params: Map) { - params.forEach { (name, value) -> - query.setParameter(name, value) - } - } } diff --git a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt index be7497b0c..cce065fa9 100644 --- a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt @@ -42,6 +42,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + @MockK private lateinit var longTypedQuery1: TypedQuery @@ -76,6 +82,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { longTypedQuery1.equals(any()) } excludeRecords { longTypedQueryParam1.hashCode() } excludeRecords { longTypedQueryParam2.hashCode() } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -85,7 +93,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -96,6 +107,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -108,7 +122,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -120,6 +137,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -132,7 +152,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -143,6 +166,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -155,7 +181,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -167,6 +196,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -184,7 +216,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 andThen longTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first every { longTypedQuery1.parameters } returns setOf(longTypedQueryParam1, longTypedQueryParam2) every { longTypedQuery1.setParameter(any(), any()) } returns longTypedQuery1 every { longTypedQueryParam1.name } returns renderedParam1.first @@ -205,6 +240,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { queryEnhancer.applySorting(sort1) entityManager.createQuery(sortedQuery1, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) From f9af12c95aec9584b112d0d9c4dff467fe3d5f57 Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 17:54:38 +0900 Subject: [PATCH 5/9] fix: debug logging when parameter binding is skipped --- .../spring/data/jpa/javax/JpqlEntityManagerUtils.kt | 9 +++++++++ .../support/spring/data/jpa/JpqlEntityManagerUtils.kt | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 2914210cd..d285f41ef 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -4,6 +4,7 @@ package com.linecorp.kotlinjdsl.support.spring.data.jpa.javax import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext +import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import javax.persistence.EntityManager @@ -102,7 +103,15 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterList.contains(name)) { query.setParameter(name, value) + } else { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterList.joinToString { it }, + ) } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index 6f3400be4..af152acb8 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -7,6 +7,7 @@ import com.linecorp.kotlinjdsl.render.RenderContext import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +import org.slf4j.LoggerFactory import org.springframework.data.domain.Sort import org.springframework.data.jpa.repository.query.QueryEnhancerFactoryAdaptor import kotlin.reflect.KClass @@ -102,7 +103,15 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterList.contains(name)) { query.setParameter(name, value) + } else { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterList.joinToString { it }, + ) } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) From 5be754e92319412051f054a473168a2d3667a83c Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 18:03:03 +0900 Subject: [PATCH 6/9] fix: minor grammar fix --- .../support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt | 2 +- .../support/spring/data/jpa/JpqlEntityManagerUtils.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index d285f41ef..484f7edd8 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -107,7 +107,7 @@ internal object JpqlEntityManagerUtils { log.debug( "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", name, - parameterList.joinToString { it }, + parameterList.joinToString(), ) } } diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index af152acb8..e4d5d210e 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -107,7 +107,7 @@ internal object JpqlEntityManagerUtils { log.debug( "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", name, - parameterList.joinToString { it }, + parameterList.joinToString(), ) } } From 78b44f64328f51e43f9ca3c501d299953cd85490 Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Sat, 12 Oct 2024 16:22:32 +0900 Subject: [PATCH 7/9] fix: apply exception ignore to all in support --- support/eclipselink-javax/build.gradle.kts | 1 + .../javax/JpqlEntityManagerUtils.kt | 15 ++++++++- .../javax/JpqlEntityManagerUtilsTest.kt | 33 +++++++++++++++++++ support/eclipselink/build.gradle.kts | 1 + .../eclipselink/JpqlEntityManagerUtils.kt | 15 ++++++++- .../eclipselink/JpqlEntityManagerUtilsTest.kt | 33 +++++++++++++++++++ support/hibernate-javax/build.gradle.kts | 1 + .../hibernate/JpqlEntityManagerUtils.kt | 15 ++++++++- .../hibernate/JpqlEntityManagerUtilsTest.kt | 33 +++++++++++++++++++ .../hibernate-reactive-javax/build.gradle.kts | 1 + .../reactive/JpqlMutinySessionUtils.kt | 11 ++++++- .../JpqlMutinyStatelessSessionUtils.kt | 11 ++++++- .../reactive/JpqlStageSessionUtils.kt | 11 ++++++- .../JpqlStageStatelessSessionUtils.kt | 11 ++++++- support/hibernate-reactive/build.gradle.kts | 1 + .../reactive/JpqlMutinySessionUtils.kt | 19 +++++++++-- .../JpqlMutinyStatelessSessionUtils.kt | 19 +++++++++-- .../reactive/JpqlStageSessionUtils.kt | 19 +++++++++-- .../JpqlStageStatelessSessionUtils.kt | 19 +++++++++-- support/hibernate/build.gradle.kts | 1 + .../hibernate/JpqlEntityManagerUtils.kt | 15 ++++++++- .../hibernate/JpqlEntityManagerUtilsTest.kt | 33 +++++++++++++++++++ support/spring-batch-javax/build.gradle.kts | 1 + .../batch/javax/JpqlEntityManagerUtils.kt | 15 ++++++++- .../batch/javax/JpqlEntityManagerUtilsTest.kt | 15 +++++++++ support/spring-batch/build.gradle.kts | 1 + .../spring/batch/JpqlEntityManagerUtils.kt | 15 ++++++++- .../batch/JpqlEntityManagerUtilsTest.kt | 15 +++++++++ .../data/jpa/javax/JpqlEntityManagerUtils.kt | 2 +- .../spring/data/jpa/JpqlEntityManagerUtils.kt | 2 +- .../data/jpa/JpqlEntityManagerUtilsTest.kt | 4 +-- 31 files changed, 366 insertions(+), 22 deletions(-) diff --git a/support/eclipselink-javax/build.gradle.kts b/support/eclipselink-javax/build.gradle.kts index 8000c1859..08a5a6f41 100644 --- a/support/eclipselink-javax/build.gradle.kts +++ b/support/eclipselink-javax/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { compileOnly(libs.eclipselink2) compileOnly(libs.javax.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt index b01e863d5..b5b284233 100644 --- a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt +++ b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt @@ -2,6 +2,7 @@ package com.linecorp.kotlinjdsl.support.eclipselink.javax import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext +import org.slf4j.LoggerFactory import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery @@ -74,8 +75,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { + val parameterNameSet = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterNameSet.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterNameSet.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt index 0bc3a241f..f8f0b14eb 100644 --- a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt +++ b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt @@ -16,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import javax.persistence.EntityManager +import javax.persistence.Parameter import javax.persistence.TypedQuery @ExtendWith(MockKExtension::class) @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -71,6 +83,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -83,7 +98,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -95,6 +113,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -107,7 +128,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -118,6 +142,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -130,7 +157,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -142,6 +172,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/eclipselink/build.gradle.kts b/support/eclipselink/build.gradle.kts index f1200b5fd..e1d9116e3 100644 --- a/support/eclipselink/build.gradle.kts +++ b/support/eclipselink/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { compileOnly(libs.eclipselink3) compileOnly(libs.jakarta.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt index ab93bdbbc..6c0d2abbf 100644 --- a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt +++ b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt @@ -5,6 +5,7 @@ import com.linecorp.kotlinjdsl.render.RenderContext import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { @@ -74,8 +75,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { + val parameterNameSet = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterNameSet.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterNameSet.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt index 8f07778fc..ec82ea2d9 100644 --- a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt +++ b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt @@ -12,6 +12,7 @@ import io.mockk.junit5.MockKExtension import io.mockk.mockkObject import io.mockk.verifySequence import jakarta.persistence.EntityManager +import jakarta.persistence.Parameter import jakarta.persistence.TypedQuery import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -71,6 +83,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -83,7 +98,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -95,6 +113,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -107,7 +128,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -118,6 +142,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -130,7 +157,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -142,6 +172,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/hibernate-javax/build.gradle.kts b/support/hibernate-javax/build.gradle.kts index c4f394655..5247048d9 100644 --- a/support/hibernate-javax/build.gradle.kts +++ b/support/hibernate-javax/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { @Suppress("VulnerableLibrariesLocal", "RedundantSuppression") compileOnly(libs.hibernate5.core) compileOnly(libs.javax.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 651b18f5a..004fc1e74 100644 --- a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -4,6 +4,7 @@ package com.linecorp.kotlinjdsl.support.hibernate import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext +import org.slf4j.LoggerFactory import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery @@ -76,8 +77,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { + val parameterNameSet = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterNameSet.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterNameSet.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt index b67494ffe..5ba14e054 100644 --- a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt +++ b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt @@ -16,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import javax.persistence.EntityManager +import javax.persistence.Parameter import javax.persistence.TypedQuery @ExtendWith(MockKExtension::class) @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -71,6 +83,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -83,7 +98,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -95,6 +113,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -107,7 +128,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -118,6 +142,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -130,7 +157,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -142,6 +172,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/hibernate-reactive-javax/build.gradle.kts b/support/hibernate-reactive-javax/build.gradle.kts index 609758488..438bfdb47 100644 --- a/support/hibernate-reactive-javax/build.gradle.kts +++ b/support/hibernate-reactive-javax/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { compileOnly(libs.hibernate.reactive1.core) compileOnly(libs.javax.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt index 6bc81ce75..d126571fa 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.mutiny.Mutiny +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlMutinySessionUtils { @@ -73,7 +74,15 @@ internal object JpqlMutinySessionUtils { private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlMutinySessionUtils::class.java) diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt index 0e63c7070..ce4a3ef40 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.mutiny.Mutiny +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlMutinyStatelessSessionUtils { @@ -73,7 +74,15 @@ internal object JpqlMutinyStatelessSessionUtils { private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlMutinyStatelessSessionUtils::class.java) diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt index e6d3b2db2..cffbe32bf 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.stage.Stage +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlStageSessionUtils { @@ -73,7 +74,15 @@ internal object JpqlStageSessionUtils { private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlStageSessionUtils::class.java) diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt index cb8f5e5dc..6d2285a73 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.stage.Stage +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlStageStatelessSessionUtils { @@ -73,7 +74,15 @@ internal object JpqlStageStatelessSessionUtils { private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlStageStatelessSessionUtils::class.java) diff --git a/support/hibernate-reactive/build.gradle.kts b/support/hibernate-reactive/build.gradle.kts index f4a48ce1b..dce0bceca 100644 --- a/support/hibernate-reactive/build.gradle.kts +++ b/support/hibernate-reactive/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { compileOnly(libs.hibernate.reactive2.core) compileOnly(libs.jakarta.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt index 340ed988f..9e048a14e 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.mutiny.Mutiny +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlMutinySessionUtils { @@ -73,13 +74,27 @@ internal object JpqlMutinySessionUtils { private fun setParams(query: Mutiny.SelectionQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } private fun setParams(query: Mutiny.MutationQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlMutinySessionUtils::class.java) diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt index 209055e65..ac81cdf98 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.mutiny.Mutiny +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlMutinyStatelessSessionUtils { @@ -73,13 +74,27 @@ internal object JpqlMutinyStatelessSessionUtils { private fun setParams(query: Mutiny.SelectionQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlMutinyStatelessSessionUtils::class.java) diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt index c8c2e32b4..37dc59865 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.stage.Stage +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlStageSessionUtils { @@ -73,13 +74,27 @@ internal object JpqlStageSessionUtils { private fun setParams(query: Stage.SelectionQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } private fun setParams(query: Stage.MutationQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlStageSessionUtils::class.java) diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt index 6810a1959..5502ac605 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import org.hibernate.reactive.stage.Stage +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlStageStatelessSessionUtils { @@ -73,13 +74,27 @@ internal object JpqlStageStatelessSessionUtils { private fun setParams(query: Stage.SelectionQuery, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> - query.setParameter(name, value) + try { + query.setParameter(name, value) + } catch (e: RuntimeException) { + if (log.isDebugEnabled) { + log.debug("Silently ignoring", e) + } + } } } } + +private val log = LoggerFactory.getLogger(JpqlStageStatelessSessionUtils::class.java) diff --git a/support/hibernate/build.gradle.kts b/support/hibernate/build.gradle.kts index 317a45270..c8b31e378 100644 --- a/support/hibernate/build.gradle.kts +++ b/support/hibernate/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { compileOnly(libs.hibernate6.core) compileOnly(libs.jakarta.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 93acccd8d..b0b3144be 100644 --- a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -7,6 +7,7 @@ import com.linecorp.kotlinjdsl.render.RenderContext import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { @@ -76,8 +77,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { + val parameterNameSet = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterNameSet.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterNameSet.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt index 34635291b..a77fff747 100644 --- a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt +++ b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt @@ -12,6 +12,7 @@ import io.mockk.junit5.MockKExtension import io.mockk.mockkObject import io.mockk.verifySequence import jakarta.persistence.EntityManager +import jakarta.persistence.Parameter import jakarta.persistence.TypedQuery import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) @@ -71,6 +83,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -83,7 +98,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -95,6 +113,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -107,7 +128,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) @@ -118,6 +142,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } @@ -130,7 +157,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -142,6 +172,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/spring-batch-javax/build.gradle.kts b/support/spring-batch-javax/build.gradle.kts index 2aa244fc9..b70314812 100644 --- a/support/spring-batch-javax/build.gradle.kts +++ b/support/spring-batch-javax/build.gradle.kts @@ -4,6 +4,7 @@ dependencies { @Suppress("VulnerableLibrariesLocal", "RedundantSuppression") compileOnly(libs.spring.batch4.infrastructure) compileOnly(libs.javax.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt index f4a2d283f..8c291e3b3 100644 --- a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt @@ -4,6 +4,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams +import org.slf4j.LoggerFactory import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery @@ -33,8 +34,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: JpqlRenderedParams) { + val parameterList = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterList.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterList.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/spring-batch-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtilsTest.kt b/support/spring-batch-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtilsTest.kt index 0391a5277..590abeb26 100644 --- a/support/spring-batch-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-batch-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtilsTest.kt @@ -16,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import javax.persistence.EntityManager +import javax.persistence.Parameter import javax.persistence.TypedQuery @ExtendWith(MockKExtension::class) @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -72,6 +84,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/spring-batch/build.gradle.kts b/support/spring-batch/build.gradle.kts index 3e00e6afb..e42f97e65 100644 --- a/support/spring-batch/build.gradle.kts +++ b/support/spring-batch/build.gradle.kts @@ -3,6 +3,7 @@ dependencies { compileOnly(libs.spring.boot3.starter) compileOnly(libs.spring.batch5.infrastructure) compileOnly(libs.jakarta.persistence.api) + compileOnly(libs.slf4j) compileOnly(projects.jpqlDsl) compileOnly(projects.jpqlQueryModel) compileOnly(projects.jpqlRender) diff --git a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt index 374f83c7c..b7e6cbb93 100644 --- a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt +++ b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt @@ -7,6 +7,7 @@ import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +import org.slf4j.LoggerFactory import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { @@ -33,8 +34,20 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: JpqlRenderedParams) { + val parameterNameSet = query.parameters.map { it.name }.toHashSet() + params.forEach { (name, value) -> - query.setParameter(name, value) + if (parameterNameSet.contains(name)) { + query.setParameter(name, value) + } else if (log.isDebugEnabled) { + log.debug( + "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", + name, + parameterNameSet.joinToString(), + ) + } } } } + +private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) diff --git a/support/spring-batch/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtilsTest.kt b/support/spring-batch/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtilsTest.kt index 4656703ca..6a9e30801 100644 --- a/support/spring-batch/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-batch/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtilsTest.kt @@ -12,6 +12,7 @@ import io.mockk.junit5.MockKExtension import io.mockk.mockkObject import io.mockk.verifySequence import jakarta.persistence.EntityManager +import jakarta.persistence.Parameter import jakarta.persistence.TypedQuery import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach @@ -35,6 +36,12 @@ class JpqlEntityManagerUtilsTest : WithAssertions { @MockK private lateinit var stringTypedQuery1: TypedQuery + @MockK + private lateinit var stringTypedQueryParam1: Parameter + + @MockK + private lateinit var stringTypedQueryParam2: Parameter + private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" private val renderedParam2 = "queryParam2" to "queryParamValue2" @@ -51,6 +58,8 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } } @Test @@ -60,7 +69,10 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { renderer.render(any(), any(), any()) } returns rendered1 every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 + every { stringTypedQuery1.parameters } returns setOf(stringTypedQueryParam1, stringTypedQueryParam2) every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 + every { stringTypedQueryParam1.name } returns renderedParam1.first + every { stringTypedQueryParam2.name } returns renderedParam2.first // when val actual = JpqlEntityManagerUtils @@ -72,6 +84,9 @@ class JpqlEntityManagerUtilsTest : WithAssertions { verifySequence { renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) + stringTypedQuery1.parameters + stringTypedQueryParam1.name + stringTypedQueryParam2.name stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) } diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 484f7edd8..0e8dbc988 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -103,7 +103,7 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterList.contains(name)) { query.setParameter(name, value) - } else { + } else if (log.isDebugEnabled) { log.debug( "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", name, diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index e4d5d210e..f3afb2f42 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -103,7 +103,7 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterList.contains(name)) { query.setParameter(name, value) - } else { + } else if (log.isDebugEnabled) { log.debug( "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", name, diff --git a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt index cce065fa9..373200dd9 100644 --- a/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt +++ b/support/spring-data-jpa/src/test/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtilsTest.kt @@ -79,11 +79,11 @@ class JpqlEntityManagerUtilsTest : WithAssertions { excludeRecords { JpqlRendererHolder.get() } excludeRecords { stringTypedQuery1.equals(any()) } + excludeRecords { stringTypedQueryParam1.hashCode() } + excludeRecords { stringTypedQueryParam2.hashCode() } excludeRecords { longTypedQuery1.equals(any()) } excludeRecords { longTypedQueryParam1.hashCode() } excludeRecords { longTypedQueryParam2.hashCode() } - excludeRecords { stringTypedQueryParam1.hashCode() } - excludeRecords { stringTypedQueryParam2.hashCode() } } @Test From 2e58f1e2d663d7af69bc40912e54caf2194cf9da Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Mon, 14 Oct 2024 11:33:58 +0900 Subject: [PATCH 8/9] refactor: logging with string template --- .../eclipselink/javax/JpqlEntityManagerUtils.kt | 6 +++--- .../support/eclipselink/JpqlEntityManagerUtils.kt | 6 +++--- .../support/hibernate/JpqlEntityManagerUtils.kt | 6 +++--- .../support/hibernate/JpqlEntityManagerUtils.kt | 6 +++--- .../spring/batch/javax/JpqlEntityManagerUtils.kt | 10 +++++----- .../support/spring/batch/JpqlEntityManagerUtils.kt | 6 +++--- .../spring/data/jpa/javax/JpqlEntityManagerUtils.kt | 10 +++++----- .../support/spring/data/jpa/JpqlEntityManagerUtils.kt | 10 +++++----- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt index b5b284233..b9efb6c7d 100644 --- a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt +++ b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt @@ -82,9 +82,9 @@ internal object JpqlEntityManagerUtils { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterNameSet.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt index 6c0d2abbf..9b1c4183b 100644 --- a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt +++ b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt @@ -82,9 +82,9 @@ internal object JpqlEntityManagerUtils { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterNameSet.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 004fc1e74..8e26493e0 100644 --- a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -84,9 +84,9 @@ internal object JpqlEntityManagerUtils { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterNameSet.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index b0b3144be..35cf7ba50 100644 --- a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -84,9 +84,9 @@ internal object JpqlEntityManagerUtils { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterNameSet.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt index 8c291e3b3..746bc2046 100644 --- a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt @@ -34,16 +34,16 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: JpqlRenderedParams) { - val parameterList = query.parameters.map { it.name }.toHashSet() + val parameterNameSet = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> - if (parameterList.contains(name)) { + if (parameterNameSet.contains(name)) { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterList.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt index b7e6cbb93..00cb833d2 100644 --- a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt +++ b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt @@ -41,9 +41,9 @@ internal object JpqlEntityManagerUtils { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterNameSet.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 0e8dbc988..44ab17778 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -98,16 +98,16 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { - val parameterList = query.parameters.map { it.name }.toHashSet() + val parameterNameSet = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> - if (parameterList.contains(name)) { + if (parameterNameSet.contains(name)) { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterList.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index f3afb2f42..b2f219ea0 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -98,16 +98,16 @@ internal object JpqlEntityManagerUtils { } private fun setParams(query: Query, params: Map) { - val parameterList = query.parameters.map { it.name }.toHashSet() + val parameterNameSet = query.parameters.map { it.name }.toHashSet() params.forEach { (name, value) -> - if (parameterList.contains(name)) { + if (parameterNameSet.contains(name)) { query.setParameter(name, value) } else if (log.isDebugEnabled) { log.debug( - "No parameter named '{}' in query with named parameters [{}], parameter binding skipped", - name, - parameterList.joinToString(), + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", ) } } From fe8ff03da79b5f784fe37238befc8e37b7b673ef Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Tue, 15 Oct 2024 18:20:53 +0900 Subject: [PATCH 9/9] refactor: debug logic into else statement --- .../eclipselink/javax/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../support/eclipselink/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../support/hibernate/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../support/hibernate/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../spring/batch/javax/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../support/spring/batch/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../data/jpa/javax/JpqlEntityManagerUtils.kt | 14 ++++++++------ .../spring/data/jpa/JpqlEntityManagerUtils.kt | 14 ++++++++------ 8 files changed, 64 insertions(+), 48 deletions(-) diff --git a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt index b9efb6c7d..89c4cb4ae 100644 --- a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt +++ b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt @@ -80,12 +80,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt index 9b1c4183b..4c01b1604 100644 --- a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt +++ b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt @@ -80,12 +80,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 8e26493e0..a91b2b215 100644 --- a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -82,12 +82,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 35cf7ba50..f92a6a326 100644 --- a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -82,12 +82,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt index 746bc2046..7a3a17865 100644 --- a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/JpqlEntityManagerUtils.kt @@ -39,12 +39,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt index 00cb833d2..650dba396 100644 --- a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt +++ b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/JpqlEntityManagerUtils.kt @@ -39,12 +39,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt index 44ab17778..e0b5cbf83 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/JpqlEntityManagerUtils.kt @@ -103,12 +103,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } } diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt index b2f219ea0..58d53d322 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/JpqlEntityManagerUtils.kt @@ -103,12 +103,14 @@ internal object JpqlEntityManagerUtils { params.forEach { (name, value) -> if (parameterNameSet.contains(name)) { query.setParameter(name, value) - } else if (log.isDebugEnabled) { - log.debug( - "No parameter named '$name' in query " + - "with named parameters [${parameterNameSet.joinToString()}], " + - "parameter binding skipped", - ) + } else { + if (log.isDebugEnabled) { + log.debug( + "No parameter named '$name' in query " + + "with named parameters [${parameterNameSet.joinToString()}], " + + "parameter binding skipped", + ) + } } } }