属于外部依赖性的类方法的拦截器
我们的代码中有一个方面,它在休眠类别上一直是尖锐的。
我们的外观类看起来像这样:
@PointCut("(execution(* *.getQueryString(..))" + "|| execution(* *.getQuery(..)))" + "&& (target(org.hibernate.engine.NamedSQLQueryDefinition))")
public void aroundNamedSQLQueryDefinitionGetQuery() {
}
@Around("aroundNamedSQLQueryDefinitionGetQuery")
public String addExtraFilter(ProceedingJoinPoint pjp) throws Exception {
//Logic to add extra filter to the Query.
}
现在我们正在尝试将此代码迁移到Quarkus。我们已经用属于我们模块的代码上的拦截器代替了方面。
但是,我们如何在休眠课上添加拦截器? 有其他方法可以实现这一目标吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
a quarkus伸展允许您操纵冬眠类(或您自己的类)。
为了踩踏基本扩展名,
然后,在
[whything]处理器
的类中,您可以添加andationTransFormerBuildItem
(我尚未测试过,我可能没有您预定的方法。我只做
getquerystring
不是getQuery
...但是它显示了这个想法。)您可能还需要告诉Quarkus interceptor是否不在主要应用程序代码库中:
可能是注释路线不是最适合您的用例的路线,您可以更直接地进行更改。值得浏览所有的quarkus构建项目,就像是一个内置的库扩展功能。例如,您可以将
@record
用于< bytecode 。A Quarkus extension would allow you to manipulate the Hibernate classes (or your own classes).
To scaffold a basic extension,
Then, in the
[whatever]Processor
class that gets created, you could add anAnnotationTransformerBuildItem
(I haven't tested that, and I may not have quite the method names you intended. I only did
getQueryString
notgetQuery
... but it shows the idea.)You may also need to tell Quarkus about your interceptor if it's not in the main application codebase:
It may be that the annotation route isn't the best for your use case, and you could make the changes you needed more directly. It's worth browsing all the Quarkus build items, which are kind of like a library of built-in extension capabilities. For example, you can use
@Record
to create bytecode.