简体   繁体   English

使用 jOOQ 将字符串数组传递给 Oracle 查询

[英]Pass String array to Oracle query using jOOQ

I'm using the jOOQ code generator to call an query from an Oracle package.我正在使用 jOOQ 代码生成器从 Oracle 包调用查询。 One of the parameters of the query is a String array.查询的参数之一是字符串数组。

The first issue, is that the code generator used Object as the type of the parameter.第一个问题是代码生成器使用Object作为参数的类型。 The generated documentation tells me to use an explicit Binding , but doesn't say how or where.生成的文档告诉我使用显式Binding ,但没有说明如何或在哪里。 I assume I have to configure something on the GenerationTool .我假设我必须在GenerationTool上配置一些东西。 How do I do that?我怎么做?

The second issue, is what actual value to pass.第二个问题,是传递什么实际值。 I've tried String[] and List<String> , but neither work.我试过String[]List<String> ,但都不起作用。 Then I ended up writing my own simple class:然后我最终编写了自己的简单类:

public class MyStringArray extends ArrayRecordImpl<String> {
  public MyStringArray() {
    super(MySchema.MY_SCHEMA, "ARR_STR", SQLDataType.VARCHAR(255));
  }
}

This works, but feels like a hack.这有效,但感觉就像一个黑客。 How do I do it the "nice" way?我如何以“好”的方式做到这一点?

The most common reason why this happens for user defined types is because the type is in a different schema than the routine referencing it, or it was excluded explicitly using <excludes> .用户定义类型发生这种情况的最常见原因是因为该类型与引用它的例程处于不同的模式中,或者使用<excludes>显式<excludes> In both cases, you can either:在这两种情况下,您都可以:

  • Do as the hint in the Javadoc suggests, and implement your own binding按照 Javadoc 中的提示进行操作,并实现您自己的绑定
  • Much better: include the referenced types in your code generation configuration更好:在代码生成配置中包含引用的类型

The generated Javadoc could be improved because jOOQ knows that the type is a user-defined type and that it's missing from generation output.生成的 Javadoc 可以改进,因为 jOOQ 知道该类型是用户定义的类型并且它在生成输出中丢失。 I've created an issue to improve this: https://github.com/jOOQ/jOOQ/issues/12630我创建了一个问题来改进这个: https : //github.com/jOOQ/jOOQ/issues/12630

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

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