-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: silently ignores exception when parameter setting to count query #781
Changes from 7 commits
13f5e17
fe2b4b4
e914ced
20cf102
f9af12c
5be754e
78b44f6
2e58f1e
fe8ff03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String, Any?>) { | ||
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {} 로 로그를 파라메터 파싱하는것보다는 $name 과 같이 처리하는게 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성능상 문제 있을까 하여 따로 파라미터로 전달한 것이었는데, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {} 로 가져가는게 오히려 성능에 더 문제가 있을 수 있습니다 (일단 스트링 파싱을 해야하고 replace 후 재생성을 해야하니 문자열 연결보다 더 성능이 좋을 수는 없을것 같습니다 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
그렇겠네요. 하나 배웠습니다! |
||
name, | ||
parameterNameSet.joinToString(), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val log = LoggerFactory.getLogger(JpqlEntityManagerUtils::class.java) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으로는 if else의 레벨을 맞추는 것을 선호합니다.
parameterNameSet
에name
이 포함되어 있는지 여부와 log가debug
레벨인지 여부는 같은 레벨의 비지니스로 보기 어렵다고 생각합니다.그래서 개인적으로는 else 블록 안에서 if를 추가하는 것을 선호합니다.
그러면 코드를 해석할 때,
파라미터 이름이 없으면 다른 작업을 하게 되는데 그 중에서 로그 레벨이 debug면 로그를 출력한다
와 같이 읽을 수 있기 때문입니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거는 저도 조금 이상해 보이긴 했습니다 저는 수정하는게 좋을것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else 안에 if 들어가는 코드여서 바깥으로 뺐는데, 말씀해주신 대로 코드를 바꾸는 게 맞는 것 같습니다.
수정해서 커밋하겠습니다!