QueryRunner explanations with simpler examples

Good day

AfterUpdateEntityListener
onAfterUpdate() method is called after a record was updated in the database, but before transaction commit**. This method does not allow modifications of the current persistence context, however, database modifications can be done using QueryRunner.**

I am new to cuba. Looking at the above definition of an AfterUpdateEntityListener it says that one can do database modifications using QueryRunner. I don’t understand. I tried looking at the example of a QueryRunner but was unable to understand. Please do provide me with more insight about a QueryRunner, with simpler examples.

Thank you in advance.

Hi,

Here it is:

package com.company.sales.listener;

import com.company.sales.entity.Customer;
import com.haulmont.bali.db.QueryRunner;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.listener.AfterUpdateEntityListener;
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import java.sql.Connection;
import java.sql.SQLException;

@Component("sales_NewEntityListener")
public class NewEntityListener implements AfterUpdateEntityListener<Customer> {

    @Inject
    private Persistence persistence;

    @Override
    public void onAfterUpdate(Customer entity, Connection connection) {
        QueryRunner queryRunner = new QueryRunner();
        try {
            queryRunner.update(connection,
                    "update sales_customer set foo = ? where id = ?",
                    new Object[] {"some-foo", persistence.getDbTypeConverter().getSqlObject(entity.getId())});
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}