简体   繁体   English

从 JOOQ 解析器结果中获取表/列元数据

[英]Get table/column metadata from JOOQ parser result

Using the JOOQ parser API, I'm able to parse the following query and get the parameters map from the resulting Query object.使用 JOOQ 解析器 API,我能够解析以下查询并从结果 Query 对象中获取参数映射。 From this, I can tell that there is one parameter, and it's name is "something".由此,我可以看出有一个参数,它的名称是“某物”。

However, I haven't been able to figure out how to determine that the parameter "something" is assigned to a column named "BAZ" and that column is part of the table "BAR".但是,我无法弄清楚如何确定参数“something”被分配给名为“BAZ”的列,并且该列是表“BAR”的一部分。

Does the parser API have a way to get the table/column metadata associated to each parameter?解析器 API 是否可以获取与每个参数关联的表/列元数据?

String sql = "SELECT A.FOO FROM BAR A WHERE A.BAZ = :something";

DSLContext context = DSL.using...
Parser parser = context.parser();
Query query = parser.parseQuery(sql);


Map<String, Param<?>> params = query.getParams();

As of jOOQ 3.11, the SPI that can be used to access the internal expression tree is theVisitListener SPI, which you have to attach to your context.configuration() prior to parsing.从 jOOQ 3.11 开始,可用于访问内部表达式树的 SPI 是VisitListener SPI,您必须在解析之前将其附加到context.configuration() It will then be invoked whenever you traverse that expression tree, eg on your query.getParams() call.每当您遍历该表达式树时,它就会被调用,例如在您的query.getParams()调用中。

However, there's quite a bit of manual plumbing that needs to be done.然而,有相当多的手动管道需要完成。 For example, the VisitListener will only see A.BAZ as a column reference without knowing directly that A is the renamed table BAR .例如, VisitListener只会将A.BAZ视为列引用,而不会直接知道A是重命名的表BAR You will have to keep track of such renaming yourself when you visit the BAR A expression.当您访问BAR A表达式时,您必须自己跟踪此类重命名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM