如何使用extackJ获取JOOQ查询文本而不更改查询方法本身?

发布于 2025-02-10 08:35:26 字数 805 浏览 2 评论 0 原文

有一个使用JOOQ的项目。 该方法的示例:

public List<A> getA(List<String> C) {
    return context
            .select(...)
            .from(...)
            .join(...).on(...)
            .where(...)
            .fetch().map(...);
}

您需要使用factionj获取请求文本。

根据第一个,HPQL和JDBC的一切都可以 - 我们根据第二次的注释 - 我们使用公共JDBC类的查询拦截了参数。

JDBC的示例点:

@Pointcut("target(org.springframework.jdbc.core.JdbcTemplate) && " +
        "args(String, ..) && (call(* query(..)) || call(* update(..)) || call(* batchUpdate(..)))")
public void executeMetricsRepository() { }

但是您在这里可以做什么?它是随着方面的应用,因为不考虑重写每个请求。

这里有两个部分-Fetch()和Map()。但是对 - 获取。

提取----&gt;接口org.jooq.resultQuery

继承类:

ApptractresultQuery和SelectImpl。但这是包装私有化的。

There is a project using JOOQ.
Example of the method:

public List<A> getA(List<String> C) {
    return context
            .select(...)
            .from(...)
            .join(...).on(...)
            .where(...)
            .fetch().map(...);
}

You need to use AspectJ to get the request text.

Everything is OK with HPQL and JDBC, according to the first - we work with the annotation, according to the second - we intercept the parameter with the query from the public JDBC class.

Example point for JDBC:

@Pointcut("target(org.springframework.jdbc.core.JdbcTemplate) && " +
        "args(String, ..) && (call(* query(..)) || call(* update(..)) || call(* batchUpdate(..)))")
public void executeMetricsRepository() { }

But what can you do here? It is with the application of the aspect, because rewriting each request is not considered.

There are two parts here - fetch() and map(). But interested in - fetch.

fetch ---> interface org.jooq.ResultQuery

Inherited classes:

AbstractResultQuery and SelectImpl. But it is package-private.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄断弥空 2025-02-17 08:35:26

我不确定您是否必须使用这种基于注释的方法

,但我不确定您是否不确定您是否必须在应用程序中提取 每个 JOOQ查询的SQL查询非常容易通过添加 到您的JOOQ 配置,例如,

configuration.set(ExecuteListener.onRenderEnd(ctx -> {

    // Or, do whatever.
    System.out.println(ctx.sql());
}));

使用eactive

j JOOQ query 类型具有查询的生​​成的SQL。这比上述方法的效率要低一些,因为它将第二次重新生成SQL字符串,但这可能与您的应用程序无关?

Alternative approach without AspectJ

I'm not sure if you have to use this annotation based approach, but it is very easy to extract the SQL query for every jOOQ query in your application by adding an ExecuteListener to your jOOQ Configuration, e.g.

configuration.set(ExecuteListener.onRenderEnd(ctx -> {

    // Or, do whatever.
    System.out.println(ctx.sql());
}));

Possibility to use AspectJ

The jOOQ Query type has a Query.getSQL() method which can be used to extract the generated SQL for any Query. That's a bit less efficient than the above approach, because it will re-generate the SQL string a second time, but that might be irrelevant to your application?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文