Skip to content

Commit

Permalink
fix: use map instead of try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
bagger3025 committed Oct 11, 2024
1 parent 13f5e17 commit fe2b4b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,13 +107,11 @@ internal object JpqlEntityManagerUtils {
}

private fun setCountQueryParams(query: Query, params: Map<String, Any?>) {
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)
}
}
}
}
Expand All @@ -125,5 +122,3 @@ internal object JpqlEntityManagerUtils {
}
}
}

private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,13 +107,11 @@ internal object JpqlEntityManagerUtils {
}

private fun setCountQueryParams(query: Query, params: Map<String, Any?>) {
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)
}
}
}
}
Expand All @@ -125,5 +122,3 @@ internal object JpqlEntityManagerUtils {
}
}
}

private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java)

0 comments on commit fe2b4b4

Please sign in to comment.