From fe2b4b4afb3a02f7952a4101b941de99a667e7dc Mon Sep 17 00:00:00 2001 From: bagger3025 Date: Fri, 11 Oct 2024 16:30:49 +0900 Subject: [PATCH] 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)