【发布时间】:2014-03-19 09:28:48
【问题描述】:
我正在学习如何使用 jooq。我想知道是否可以在生成的 Record 类中添加一些域级别的方法。
假设记录是这样的:
public class ConCalCompanyRecord extends org.jooq.impl.UpdatableRecordImpl<com.aesthete.csmart.connect.model.db.gen.tables.records.ConCalCompanyRecord> implements org.jooq.Record6<java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.sql.Timestamp, java.sql.Timestamp> {
// properties
// getters and setters
// I would like to add a method like this:
public void isABlueCompany(){
// work with the fields
}
}
但是我知道如果我这样做,一旦我从数据库中再次生成这个类,我的所有更改都会丢失。那么推荐的方法是什么?
一个包装类?记录的子类?如果是其中任何一个,我如何让 jooq 在获取时识别这些类。例如:
connectionFacade.getDSLContext()
.selectFrom(CON_CAL_INSTANCE)
.where(CON_CAL_INSTANCE.DATE.between(
new Date(datesOfTheWeekForDate[0].toDate().getTime()), new Date(datesOfTheWeekForDate[1].toDate().getTime())))
.orderBy(CON_CAL_INSTANCE.DATE)
.fetch()
.into(new RecordHandler<ConCalInstanceRecord>() {
@Override
public void next(ConCalInstanceRecord record) {
calendarEntries.addToList(new com.aesthete.csmart.connect.model.domain.records.ConCalInstance(record));
}
});
在上述情况下,我为记录类提供了一个名为 ConCalInstance 的包装器。如果我需要使用包装器,是否必须为我执行的每个查询编写这样的 RecordHandler? 这样做的推荐方法是什么?
【问题讨论】: