jooq:如何为静态DSL方法配置方言? [英] jooq: How to configure dialect for static DSL methods?
问题描述
我用POSTGRES_9_4
方言得到了dsl
.我尝试将自定义选择查询与org.jooq.impl.DSL.Condition
一起使用:
I've got dsl
with POSTGRES_9_4
dialect. I try to use custom selection query with org.jooq.impl.DSL.Condition
:
dsl.selectFrom(TAG_JSON).where(condition("translations ??| array[?]", normValues)).fetch(mapper);
它引发异常:
org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.ArrayList is not supported in dialect DEFAULT
at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:757)
at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:704)
at org.jooq.impl.DSL.getDataType(DSL.java:14371)
at org.jooq.impl.Utils.queryParts(Utils.java:1565)
at org.jooq.impl.SQLImpl.<init>(SQLImpl.java:64)
at org.jooq.impl.DSL.sql(DSL.java:6240)
at org.jooq.impl.DSL.condition(DSL.java:7323)
为什么使用DEFAULT
方言?如何配置全局一个?
Why DEFAULT
dialect is used? How to configure global one?
推荐答案
错误消息有点误导.您的意图似乎是让array[?]
将List<String>
作为单个绑定值传递给数组构造函数.这行不通.您有两种选择:
The error message is a bit misleading. Your intention seems for array[?]
to take a List<String>
as a single bind value to pass to an array constructor. This won't work. You have two options:
绑定单个数组
condition("translations <op> ?::text[]", normValues.toArray(new String[0]))
将数组绑定为绑定值列表
Binding the array as a list of bind values
condition("translations <op> {0}", list(
normValues.stream().map(DSL::val).toArray(QueryPart[]::new)
))
这正在使用 DSL.list()
创建绑定变量列表.
This is using DSL.list()
to create a list of bind variables.
注意,在两种情况下,我都避免使用您的??|
运算符,因为jOOQ解析纯SQL文本以获得绑定值(?
),并且当前不将??|
识别为非绑定变量序列(我已经为此注册了一个问题).如果该运算符具有文本替代表示形式,则建议使用该替代形式.
Note, in both cases, I have avoided your ??|
operator because jOOQ parses plain SQL text for bind values (?
) and currently doesn't recognise ??|
as a non-bind variable sequence (I've registered an issue for this). If that operator has a textual alternative representation, I recommend using that instead.
这篇关于jooq:如何为静态DSL方法配置方言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!