简体   繁体   English

如何初始化自定义行类型Jooq记录

[英]How to Initialize a custom row type Jooq Record

Similar to this question: How to initialise and create a ResultSet and Record in Jooq? 与此问题类似: 如何在Jooq中初始化和创建ResultSet和Record? but with a custom row type record rather than a simple table record. 但具有自定义的行类型记录而不是简单的表记录。 I am instantiating a jooq record to use in mocking, but the record has more than 22 columns and contains rows from many joined tables, so I am using RecordImpl. 我正在实例化要在模拟中使用的jooq记录,但是该记录有22列以上,并且包含来自许多联接表的行,因此我正在使用RecordImpl。

RecordImpl r1 = new RecordImpl();
r1.set(COURSE.ID.as("course_id"), 1);

This throws exception 这引发异常

java.lang.IllegalArgumentException: Field ("course_id") is not contained in Row () java.lang.IllegalArgumentException:字段(“ course_id”)不包含在Row()中

Note I am not using RecordImpl directly since it is package private, so I use a 注意我不是直接使用RecordImpl,因为它是包私有的,所以我使用

public class RecordWrapper extends RecordImpl {}

How can I set fields directly on an untyped Jooq record? 如何直接在无类型的Jooq记录上设置字段?

You shouldn't instanciate or extend RecordImpl which is part of jOOQ's internal API. 你不应该实例化或扩展RecordImpl这是jOOQ的内部API的一部分。 Instead, use DSLContext.newRecord() , eg 而是使用DSLContext.newRecord() ,例如

Record1<Integer> r1 = ctx.newRecord(COURSE.ID.as("course_id")).values(1);

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

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