use of com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB 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.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB 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.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB in project cuba by cuba-platform.
the class SoftDeleteTest method setUp.
@Before
public void setUp() throws Exception {
persistence = cont.persistence();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group = new Group();
groupId = group.getId();
group.setName("testGroup");
em.persist(group);
User user = new User();
userId = user.getId();
user.setName("testUser");
user.setLogin("testLogin");
user.setGroup(group);
em.persist(user);
User user1 = new User();
user1Id = user1.getId();
user1.setName("testUser1");
user1.setLogin("testLogin1");
user1.setGroup(group);
em.persist(user1);
Role role1 = em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93"));
UserRole userRole1 = new UserRole();
userRole1Id = userRole1.getId();
userRole1.setUser(user);
userRole1.setRole(role1);
em.persist(userRole1);
Role role2 = new Role();
role2Id = role2.getId();
role2.setName("roleToBeDeleted");
em.persist(role2);
Role role3 = new Role();
role3Id = role3.getId();
role3.setName("roleToBeDeleted3");
em.persist(role3);
UserRole userRole2 = new UserRole();
userRole2Id = userRole2.getId();
userRole2.setUser(user);
userRole2.setRole(role2);
em.persist(userRole2);
UserRole userRole3 = new UserRole();
userRole3Id = userRole3.getId();
userRole3.setUser(user1);
userRole3.setRole(role3);
em.persist(userRole3);
SoftDeleteOneToOneB oneToOneB1 = cont.metadata().create(SoftDeleteOneToOneB.class);
oneToOneB1.setName("oneToOneB1");
em.persist(oneToOneB1);
oneToOneB1Id = oneToOneB1.getId();
SoftDeleteOneToOneB oneToOneB2 = cont.metadata().create(SoftDeleteOneToOneB.class);
oneToOneB2.setName("oneToOneB2");
em.persist(oneToOneB2);
oneToOneB2Id = oneToOneB2.getId();
SoftDeleteOneToOneA oneToOneA1 = cont.metadata().create(SoftDeleteOneToOneA.class);
oneToOneA1.setName("oneToOneA1");
oneToOneA1.setB(oneToOneB1);
em.persist(oneToOneA1);
oneToOneA1Id = oneToOneA1.getId();
SoftDeleteOneToOneA oneToOneA2 = cont.metadata().create(SoftDeleteOneToOneA.class);
oneToOneA2.setName("oneToOneA2");
oneToOneA2.setB(oneToOneB2);
em.persist(oneToOneA2);
oneToOneA2Id = oneToOneA2.getId();
Group group1 = new Group();
group1Id = group1.getId();
group1.setName("testGroup1");
em.persist(group1);
GroupHierarchy groupHierarchy = new GroupHierarchy();
groupHierarchyId = groupHierarchy.getId();
groupHierarchy.setGroup(group1);
groupHierarchy.setParent(group1);
groupHierarchy.setLevel(1);
em.persist(groupHierarchy);
Constraint constraint1 = new Constraint();
constraint1Id = constraint1.getId();
constraint1.setCode("constraint1");
constraint1.setEntityName("sec$Constraint");
constraint1.setGroup(group1);
em.persist(constraint1);
Constraint constraint2 = new Constraint();
constraint2Id = constraint2.getId();
constraint2.setCode("constraint2");
constraint2.setEntityName("sec$Constraint");
constraint2.setGroup(group1);
em.persist(constraint2);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
UserRole ur = em.find(UserRole.class, userRole2Id);
em.remove(ur);
Role r = em.find(Role.class, role2Id);
em.remove(r);
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA1Id);
em.remove(oneToOneA);
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB2Id);
em.remove(oneToOneB);
Constraint constraint = em.find(Constraint.class, constraint2Id);
em.remove(constraint);
// remove from db to prevent cascade delete user role
QueryRunner queryRunner = new QueryRunner();
queryRunner.update(em.getConnection(), "update SEC_ROLE set DELETE_TS = CREATE_TS, DELETED_BY = CREATED_BY where name = 'roleToBeDeleted3'");
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOneMappedByQuery.
@Test
public void testOneToOneMappedByQuery() {
System.out.println("===================== BEGIN testOneToOneMappedByQuery =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
SoftDeleteOneToOneA oneToOneA3 = cont.metadata().create(SoftDeleteOneToOneA.class);
oneToOneA3.setName("oneToOneA3");
oneToOneA3.setB(em.find(SoftDeleteOneToOneB.class, oneToOneB1Id));
em.persist(oneToOneA3);
oneToOneA3Id = oneToOneA3.getId();
tx.commit();
} finally {
tx.end();
}
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"));
List<SoftDeleteOneToOneB> r = em.createQuery("select b from test$SoftDeleteOneToOneB b where b.name = :name", SoftDeleteOneToOneB.class).setParameter("name", "oneToOneB1").setView(view).getResultList();
assertEquals(1, r.size());
assertEquals(r.get(0).getA().getId(), oneToOneA3Id);
assertEquals(r.get(0).getA().getName(), "oneToOneA3");
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneMappedByQuery =====================");
}
Aggregations