I'm trying to implement a jOOQ RecordUnmapper
to adjust a record that I will later insert/update.
My attempt below, problem is that the Record
class cannot be instantiated. How to create the Record
object? Also, how to use the unmapper in insert/update?
public class TableUnmapper implements RecordUnmapper<Table, Record> {
@Override
public Record unmap(Table t) throws MappingException {
Record r = new Record(); // <-- this line does not compile
r.from(t);
r.set(TABLES.TITLE_FONT_FAMILY, t.getTitleFont().getFontFamily());
return r;
}
}
Record
is an interface, so you can't directly create an instance of the interface, you have to instantiate a class that implements the Record
interface, if you use Jooq code generator, you probably already have a TableRecord
class, this is the class you can use for this purpouse,
then the unmapper should look something like:
public class TableUnmapper implements RecordUnmapper<Table, TableRecord> {
@Override
public TableRecord unmap(Table t) throws MappingException {
TableRecord r = new TableRecord(t.getSomeAttribute());
r.setAttribute(t.getSomeOtherAttribute());
return r;
}
}
To use the unmapper:
DSLContext create;
Table table = new Table(/* Whatever Arguments */);
TableUnmapper unmapper = new TableRecordUnmapper();
// Insert
create.insertInto(TABLES).set(unmapper.unmap(table));
// update
create.executeUpdate(unmapper.unmap(table));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.