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());
}
Aggregations