So I ran into this issue and was wondering if this was an implementation
over sight of it's intended.

I have the following snippet of code:

For reference, the record has a serial ID, that has little value though for
legacy reasons is the primary key of the record.

        ApiSettingParameterRecord record =
dslContext.newRecord(INTEGRATION.API_SETTING_PARAMETER);
        record.setActive(true);
        record.setDataSource(entity.getDataSource());
        record.setName(entity.getName());
        record.setType(entity.getType());
        record.setLength(entity.getLength());
        record.setUiOrder(entity.getUiOrder());
        record.setUiLabel(entity.getUiLabel());
        record.setIsPopulated(entity.getIsPopulated());
        record.setUrl(entity.getUrl());
        record.setAutoPopulated(entity.getAutoPopulated());
        record.setVisible(entity.getVisible());
        record.setVersion(entity.getVersion());

        dslContext.insertInto(record.getTable())
            .set(record)
            .onConflict(INTEGRATION.API_SETTING_PARAMETER.DATA_SOURCE,
INTEGRATION.API_SETTING_PARAMETER.VERSION,
INTEGRATION.API_SETTING_PARAMETER.ACTIVE,
INTEGRATION.API_SETTING_PARAMETER.UI_ORDER)
            .doUpdate()
            .set(record)
            .execute();

​

After the code executes, I'd like to be able to do


record.refresh();

​

Which in this case doesn't work since the PKey is null.

record.refresh() to get the ID of the record that was inserted,

Instead, I'm forced to do a select using the onConflict conditional.

ie.


        record =
                dslContext.select(record.fields())
                        .from(INTEGRATION.API_SETTING_PARAMETER)

.where(INTEGRATION.API_SETTING_PARAMETER.NAME.eq(entity.getName()))

.and(INTEGRATION.API_SETTING_PARAMETER.DATA_SOURCE.eq(entity.getDataSource()))

.and(INTEGRATION.API_SETTING_PARAMETER.VERSION.eq(entity.getVersion()))

.and(INTEGRATION.API_SETTING_PARAMETER.ACTIVE.eq(Boolean.TRUE))

.orderBy(INTEGRATION.API_SETTING_PARAMETER.ACTIVE.desc())
                        .fetchOneInto(ApiSettingParameterRecord.class);

​
If this was a normal insert I could simply do a .returning(id); but that's
not supported with upserts, that's not feasible.

Is the pattern I was trying to use unsupported?




-- 
Thank you
Samir Faci
https://keybase.io/csgeek

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to