I want to update a column only when the given value is not null in the POJO I am receiving.
I want to implement this SQL:
Update TABLE table_name SET column_name = COALESCE(value, column_name)
Here is the function I have written in JOOQ
public int updateCompany(final Company company) {
return dslContext.update(COMPANY)
.set(COMPANY.REGISTERED_NAME, company.getRegisteredName())
.set(COMPANY.TRADING_NAME, coalesce(COMPANY.TRADING_NAME, company.getTradingName()))
.set(COMPANY.ADDRESS_ID, coalesce(COMPANY.ADDRESS_ID, company.getAddressId()))
.where(COMPANY.ID.eq(company.getId()))
.execute();
}