use of com.haulmont.cuba.core.EntityManager 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.EntityManager 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.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOne.
@Test
public void testOneToOne() {
System.out.println("===================== BEGIN testOneToOne =====================");
// test fetchMode = AUTO
System.out.println("===================== BEGIN testOneToOne fetchMode = AUTO =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"));
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
tx.commit();
} finally {
tx.end();
}
// test fetchMode = BATCH
System.out.println("===================== BEGIN testOneToOneBy fetchMode = BATCH =====================");
tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.BATCH);
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
tx.commit();
} finally {
tx.end();
}
// test fetchMode = UNDEFINED
System.out.println("===================== BEGIN testOneToOneBy fetchMode = UNDEFINED =====================");
tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOne =====================");
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOneMappedBy.
@Test
public void testOneToOneMappedBy() {
System.out.println("===================== BEGIN testOneToOneMappedBy =====================");
// test fetchMode = AUTO
System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = AUTO =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"));
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
assertNotNull(oneToOneB);
assertNull(oneToOneB.getA());
tx.commit();
} finally {
tx.end();
}
// test fetchMode = BATCH
System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = BATCH =====================");
tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.BATCH);
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
assertNotNull(oneToOneB);
assertNull(oneToOneB.getA());
tx.commit();
} finally {
tx.end();
}
// test fetchMode = UNDEFINED
System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = UNDEFINED =====================");
tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
assertNotNull(oneToOneB);
assertNull(oneToOneB.getA());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneMappedBy =====================");
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SoftDeleteTest method testRemoveNotManaged.
@Test
public void testRemoveNotManaged() {
System.out.println("===================== BEGIN testRemoveNotManaged =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
UserRole userRole = em.find(UserRole.class, userRole1Id);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
em.remove(userRole);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
UserRole deletedUserRole = em.find(UserRole.class, userRole1Id);
assertNull(deletedUserRole);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testRemoveNotManaged =====================");
}
Aggregations