use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testMultipleTransactions.
@Test
public void testMultipleTransactions() throws Exception {
try (Transaction tx = persistence.createTransaction()) {
assertTrue(CubaUtil.isSoftDeletion());
EntityManager em = persistence.getEntityManager();
em.setSoftDeletion(false);
assertFalse(CubaUtil.isSoftDeletion());
tx.commit();
}
try (Transaction tx = persistence.createTransaction()) {
assertTrue(CubaUtil.isSoftDeletion());
EntityManager em = persistence.getEntityManager();
em.setSoftDeletion(false);
assertFalse(CubaUtil.isSoftDeletion());
try (Transaction tx1 = persistence.createTransaction()) {
assertTrue(CubaUtil.isSoftDeletion());
tx1.commit();
}
assertFalse(CubaUtil.isSoftDeletion());
tx.commit();
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOneLazy.
@Test
public void testOneToOneLazy() {
System.out.println("===================== BEGIN testOneToOneLazy =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneLazy =====================");
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToMany_Query.
@Test
public void testOneToMany_Query() {
System.out.println("===================== BEGIN testOneToMany_Query =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q = em.createQuery("select u from sec$User u where u.id = ?1");
q.setParameter(1, userId);
User user = (User) q.getSingleResult();
List<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToMany_Query =====================");
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class TestBeforeCommitTxListener method queryWithFlush.
private void queryWithFlush(Collection<Entity> managedEntities, EntityManager entityManager) {
if (!managedEntities.stream().anyMatch(e -> e instanceof User && ((User) e).getLogin().startsWith("TxLstnrTst-")))
return;
TypedQuery<User> query = entityManager.createQuery("select u from sec$User u where u.login like ?1", User.class);
query.setParameter(1, "TxLstnrTst-2-%");
query.setFlushMode(FlushModeType.AUTO);
User result = query.getFirstResult();
assertNotNull(result);
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class TestListenerUsingEntityManager method onBeforeInsert.
@Override
public void onBeforeInsert(Server entity, EntityManager entityManager) {
EntityManager em = persistence.getEntityManager();
FileDescriptor related = new FileDescriptor();
related.setName("Related");
System.out.println(">>>>> persist related: " + related.getId());
em.persist(related);
entity.setData(related.getId().toString());
}
Aggregations