Search in sources :

Example 1 with TransactionParams

use of com.haulmont.cuba.core.TransactionParams in project cuba by cuba-platform.

the class EntityCacheTestClass method testAccessConnectionWithCacheInvalidation.

@Test
@Ignore
public void testAccessConnectionWithCacheInvalidation() {
    appender.clearMessages();
    try (Transaction tx = cont.persistence().createTransaction()) {
        cont.persistence().getEntityManager().getConnection();
        ViewRepository viewRepository = AppBeans.get(ViewRepository.class);
        View view = viewRepository.getView(cont.metadata().getClassNN(User.class), "user.browse");
        cont.entityManager().find(User.class, this.user.getId(), view);
        tx.commit();
    }
    // User, Group
    assertEquals(2, appender.filterMessages(m -> m.contains("> SELECT")).count());
    appender.clearMessages();
    try (Transaction tx = cont.persistence().createTransaction()) {
        cont.persistence().getEntityManager().getConnection();
        ViewRepository viewRepository = AppBeans.get(ViewRepository.class);
        View view = viewRepository.getView(cont.metadata().getClassNN(User.class), "user.browse");
        cont.entityManager().find(User.class, this.user.getId(), view);
        tx.commit();
    }
    // User, Group
    assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
    appender.clearMessages();
    try (Transaction tx = cont.persistence().createTransaction(new TransactionParams().setReadOnly(true))) {
        try (Transaction tx1 = cont.persistence().getTransaction()) {
            cont.persistence().getEntityManager().getConnection();
            tx1.commit();
        }
        ViewRepository viewRepository = AppBeans.get(ViewRepository.class);
        View view = viewRepository.getView(cont.metadata().getClassNN(User.class), "user.browse");
        Query query = cont.entityManager().createQuery("select u from sec$User u where u.id = :id").setParameter("id", user.getId());
        query.setView(View.copy(view).setLoadPartialEntities(true));
        ((QueryImpl) query).setSingleResultExpected(true);
        User userL = (User) query.getSingleResult();
        // User userL = cont.entityManager().find(User.class, user.getId(), view);
        assertNotNull(userL);
        tx.commit();
    }
    // User, Group
    assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
}
Also used : TransactionParams(com.haulmont.cuba.core.TransactionParams) QueryImpl(com.haulmont.cuba.core.sys.QueryImpl) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) TypedQuery(com.haulmont.cuba.core.TypedQuery)

Aggregations

Query (com.haulmont.cuba.core.Query)1 Transaction (com.haulmont.cuba.core.Transaction)1 TransactionParams (com.haulmont.cuba.core.TransactionParams)1 TypedQuery (com.haulmont.cuba.core.TypedQuery)1 QueryImpl (com.haulmont.cuba.core.sys.QueryImpl)1