jooq:如何为静态DSL方法配置方言? [英] jooq: How to configure dialect for static DSL methods?

查看:154
本文介绍了jooq:如何为静态DSL方法配置方言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆