Java eturn from==null?null:Arrays.stream(来自) .map(FooId::getUuid) .collect(收集器.toList()) .toArray(新UUID[起始长度]); } @凌驾 @抑制警告(“未选中”) 公共类fromType(){ 返回(类)UUID[]类; } @凌驾 公共类toType(){ 返回FooId[].class; } }

Java eturn from==null?null:Arrays.stream(来自) .map(FooId::getUuid) .collect(收集器.toList()) .toArray(新UUID[起始长度]); } @凌驾 @抑制警告(“未选中”) 公共类fromType(){ 返回(类)UUID[]类; } @凌驾 公共类toType(){ 返回FooId[].class; } },java,arrays,postgresql,jooq,Java,Arrays,Postgresql,Jooq,装订 公共类FoodBinding扩展了DefaultBinding{ 私有静态最终长serialVersionUID=1L; 公共食品绑定(){ super(新的FooIdConverter()); } @凌驾 公共无效sql(最终绑定SQLContext ctx){ super.sql(ctx); ctx.render().sql(“::uuid[]”); } @凌驾 公共无效寄存器(final BindingRegisterContext ctx)引发SQLException{ ctx.

装订

公共类FoodBinding扩展了DefaultBinding{
私有静态最终长serialVersionUID=1L;
公共食品绑定(){
super(新的FooIdConverter());
}
@凌驾
公共无效sql(最终绑定SQLContext ctx){
super.sql(ctx);
ctx.render().sql(“::uuid[]”);
}
@凌驾
公共无效寄存器(final BindingRegisterContext ctx)引发SQLException{
ctx.statement().registerOutParameter(ctx.index(),Types.ARRAY);
}
@凌驾
public void get(final BindingGetResultSetContext ctx)引发SQLException{
value(_convert(ctx.resultSet().getArray(ctx.index()));
}
@凌驾
public void get(final BindingGetStatementContext ctx)引发SQLException{
value(_convert(ctx.statement().getArray(ctx.index()));
}
@凌驾
public void get(final BindingGetSQLInputContext ctx)抛出SQLException{
值(_convert(ctx.input().readArray());
}
@凌驾
公共无效集(最终BindingSetStatementContext ctx)引发SQLException{
最终编制报表ps=ctx.statement();
ps.setArray(ctx.index(),ps.getConnection().createArrayOf(“uuid”,ctx.value());
}
@凌驾
公共无效集(最终BindingSetSQLOutputContext ctx)引发SQLException{
抛出新的UnsupportedOperationException();
}
受保护的FooId[]\u转换(最终数组)引发SQLException{
if(数组==null){
返回null;
}否则{
从((UUID[])array.getArray()返回converter();
}
}
}

看起来jOOQ代码生成器中有一个bug,它阻止了
UUID[]
类型被覆盖:

有趣的更新,这对未来的访问者非常有用。不过请注意,您也可以在堆栈溢出上回答自己的问题……嘿@LukasEder,谢谢您的关注。我的问题其实是‘什么是正确的方法’,而不是‘我如何才能让它工作’,因为我知道我能够一起解决一些问题,我相信你的答案是正确的。i、 e.应使用常规的定制/强制式机制,仅配备一个转换器。
public class FooIdConverter implements Converter<Object[],FooId[]> {

    private static final long serialVersionUID = 1L;

    @Override
    public FooId[] from(final Object[] from) {
        return from == null ? null : Arrays.stream(from)
                                           .map(that -> new FooId((UUID)that))
                                           .collect(Collectors.toList())
                                           .toArray(new FooId[from.length]);
    }

    @Override
    public UUID[] to(final FooId[] from) {
        return from == null ? null : Arrays.stream(from)
                                           .map(FooId::getUuid)
                                           .collect(Collectors.toList())
                                           .toArray(new UUID[from.length]);
    }

    @Override
    @SuppressWarnings("unchecked")
    public Class<Object[]> fromType() {
        return (Class)UUID[].class;
    }

    @Override
    public Class<FooId[]> toType() {
        return FooId[].class;
    }
}
public class FooIdBinding extends DefaultBinding<Object[], FooId[]> {

    private static final long serialVersionUID = 1L;

    public FooIdBinding() {
        super(new FooIdConverter());
    }

    @Override
    public void sql(final BindingSQLContext<FooId[]> ctx) {
        super.sql(ctx);
        ctx.render().sql("::uuid[]");
    }

    @Override
    public void register(final BindingRegisterContext<FooId[]> ctx) throws SQLException {
        ctx.statement().registerOutParameter(ctx.index(), Types.ARRAY);
    }

    @Override
    public void get(final BindingGetResultSetContext<FooId[]> ctx) throws SQLException {
        ctx.value(_convert(ctx.resultSet().getArray(ctx.index())));
    }

    @Override
    public void get(final BindingGetStatementContext<FooId[]> ctx) throws SQLException {
        ctx.value(_convert(ctx.statement().getArray(ctx.index())));
    }

    @Override
    public void get(final BindingGetSQLInputContext<FooId[]> ctx) throws SQLException {
        ctx.value(_convert(ctx.input().readArray()));
    }

    @Override
    public void set(final BindingSetStatementContext<FooId[]> ctx) throws SQLException {
        final PreparedStatement ps = ctx.statement();
        ps.setArray(ctx.index(), ps.getConnection().createArrayOf("uuid", ctx.value()));
    }

    @Override
    public void set(final BindingSetSQLOutputContext<FooId[]> ctx) throws SQLException {
        throw new UnsupportedOperationException();
    }

    protected FooId[] _convert(final Array array) throws SQLException {
        if (array == null) {
            return null;
        } else {
            return converter().from(((UUID[]) array.getArray()));
        }
    }
}