Skip to content
Konstantin Triger edited this page Aug 10, 2019 · 3 revisions

Started in Fundamentals, we continue writing tutorial samples with FluentJPA.

Other basic clauses: SELECT, INSERT, DELETE

update join

FluentQuery query = FluentJPA.SQL((LinkTmp linkTmp,
                                   Link link) -> {

    UPDATE(linkTmp).SET(() -> {
        linkTmp.setRel(link.getRel());
        linkTmp.setDescription(link.getDescription());
        linkTmp.setLastUpdate(link.getLastUpdate());
    });
    FROM(link);
    WHERE(linkTmp.getId() == link.getId());
});

use UPDATE clause as the action of the INSERT statement

FluentQuery query = FluentJPA.SQL((Customer cust) -> {

    INSERT().INTO(viewOf(cust, Customer::getName, Customer::getEmail));
    VALUES(row("Microsoft", "[email protected]"));
    ON_CONFLICT(Customer::getName).DO_UPDATE().SET(() -> {
        Customer excluded = EXCLUDED();
        cust.setEmail(excluded.getEmail() + ";" + cust.getEmail());
    });
});