use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class SoftDeleteNotFoundDeletedTest method testLoadDeletedObject.
@Test
public void testLoadDeletedObject() {
View taskView_Message = new View(SoftDelete_Task.class).addProperty("message");
View taskView_Service = new View(SoftDelete_Task.class).addProperty("service", new View(SoftDelete_Service.class).addProperty("code"));
View taskValueView = new View(SoftDelete_TaskValue.class).addProperty("task", taskView_Message);
View projectView = new View(SoftDelete_Project.class).addProperty("name").addProperty("aValue", taskValueView).addProperty("task", taskView_Service);
LoadContext<SoftDelete_Project> loadContext = new LoadContext<>(SoftDelete_Project.class).setView(projectView).setId(projectId);
SoftDelete_Project project = dataManager.load(loadContext);
Assert.assertNotNull(project);
Assert.assertNotNull(project.getTask());
Assert.assertTrue(project.getTask().isDeleted());
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class SoftDeleteTest method testReferenceToDeletedEntityOneToManyThroughManyToOne.
@Test
public void testReferenceToDeletedEntityOneToManyThroughManyToOne() {
View constraintView = new View(Constraint.class).addProperty("code");
View groupView = new View(Group.class).addProperty("name").addProperty("constraints", constraintView, FetchMode.BATCH);
View groupHierarchyView = new View(GroupHierarchy.class).addProperty("group", groupView, FetchMode.BATCH);
GroupHierarchy groupHierarchy = cont.persistence().callInTransaction((em) -> em.find(GroupHierarchy.class, groupHierarchyId, groupHierarchyView));
assertNotNull(groupHierarchy);
assertNotNull(groupHierarchy.getGroup());
assertEquals(1, groupHierarchy.getGroup().getConstraints().size());
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToOneQuery.
@Test
public void testOneToOneQuery() {
System.out.println("===================== BEGIN testOneToOneQuery =====================");
// test 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"));
List<SoftDeleteOneToOneA> r = em.createQuery("select a from test$SoftDeleteOneToOneA a where a.name = :name", SoftDeleteOneToOneA.class).setParameter("name", "oneToOneA2").setView(view).getResultList();
assertEquals(1, r.size());
assertEquals(r.get(0).getB().getId(), oneToOneB2Id);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneQuery =====================");
}
use of com.haulmont.cuba.core.global.View 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 =====================");
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class SoftDeleteTest method testOneToMany.
@Test
public void testOneToMany() {
System.out.println("===================== BEGIN testOneToMany =====================");
// test fetchMode = AUTO
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
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(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
} finally {
tx.end();
}
// test fetchMode = JOIN
tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView"), FetchMode.JOIN);
User user = em.find(User.class, userId, view);
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 =====================");
}
Aggregations