Proper method for GridPro database update?

I’ve searched far and wide for best practices on updating my items in the database when edited in a GridPro, but I can’t find a complete example. I’ve found a forum post referencing Vaadin 13 that suggests using an ItemUpdater but said example makes no database calls. Can someone point me in the right direction?

Did I not ask the right question, or am I asking something obvious?

How do you retrieve the items from database? Updating should go the same way, just the other way round.

I’m not asking the specifics on the database access, just what method is used within the GridPro to make the calls.

Couple of ways I can think of - either inside the ItemUpdater (as with SimpleObject::getText2 column),
or by listening to item property changes in addItemPropertyChangedListener(...).

    public GridPro<SimpleObject> createGridPro() {
        var grid = new GridPro<SimpleObject>();
        grid.addColumn(SimpleObject::getId);
        grid.addEditColumn(SimpleObject::getText).text(SimpleObject::setText);
        grid.addEditColumn(SimpleObject::getText2).text((item, text2) -> {
            // save to database ...
            item.setText2(text2);
            myDBService.save(item)
        });

        grid.addItemPropertyChangedListener(changeEvent -> {
            SimpleObject item = changeEvent.getItem();
            // save to database ...
            myDBService.save(item)
        });

        grid.setItems(new SimpleObject(1L, "Test 1", "Text 2 one"), new SimpleObject(2L, "Test 2", "Text 2 two"), new SimpleObject(3L, "Test 3", "Text 2 three"));
        return grid;
    }

Would further updates to the item throw a StaleObjectStateException or similar?

Or does the item get replaced?

Or also up to me in the listener/updater?

Doesn’t get replaced automatically, as far as I know, depends on what you do in myDBService.save(item) to the original object. If you update it / refresh it afterwards, so that it can be saved again once changed, then it should be fine.

Very good, thanks for the advice!

When it comes to databases it’s usually trial-and-error with these things.
You might want to call grid.getDataProvider().refreshItem(item) if the save has changed something in the object.
So that the Grid also displays the latest data for it.

The question is fine of course, the somewhat slow response is usually due to

  1. Not being that familiar with the issue context
  2. Not being available, as most our time is spent in customer projects, “expert on demand” chats or working on internal stuff.
    Still we try to get to everything eventually :crossed_fingers:

No worries, I saw other questions after mine get a response and I assumed I was asking something trivial. Usually when I can’t find my answer after a day of searching I go back to the docs, figuring I missed something very important. Looks like I did miss something in this case, like the use of lambdas in the EditColumnConfigurator.