use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToManyLazy.
@Test
public void testOneToManyLazy() {
System.out.println("===================== BEGIN testOneToManyLazy =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
User user = em.find(User.class, userId);
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 testOneToManyLazy =====================");
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOneMappedByLazy.
@Test
public void testOneToOneMappedByLazy() {
System.out.println("===================== BEGIN testOneToOneMappedByLazy =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id);
assertNotNull(oneToOneB);
assertNull(oneToOneB.getA());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneMappedByLazy =====================");
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToMany_CleanupMode.
@Test
public void testOneToMany_CleanupMode() {
System.out.println("===================== BEGIN testOneToMany_CleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
View view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView").addProperty("role", new View(Role.class, "testView").addProperty("name")));
User user = em.find(User.class, userId, view);
List<UserRole> userRoles = user.getUserRoles();
assertEquals(2, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToMany_CleanupMode =====================");
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class SoftDeleteTest method testQuery_CleanupMode.
@Test
public void testQuery_CleanupMode() {
System.out.println("===================== BEGIN testQuery_CleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
query.setParameter(1, "roleToBeDeleted");
List<Role> list = query.getResultList();
assertTrue(!list.isEmpty());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testQuery_CleanupMode =====================");
}
use of com.haulmont.cuba.core.Transaction 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 =====================");
}
Aggregations