use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class EclipseLinkDetachedTest method testSerializedFetchGroupMerge.
@Test
public void testSerializedFetchGroupMerge() throws Exception {
Transaction tx;
EntityManager em;
User user;
tx = cont.persistence().createTransaction();
try {
em = cont.persistence().getEntityManager();
View view = new View(User.class).addProperty("login").setLoadPartialEntities(true);
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = reserialize(user);
assertEquals("testLogin", user.getLogin());
// exception on getting not loaded references
try {
user.getName();
fail();
} catch (Exception ignored) {
}
try {
user.getGroup();
fail();
} catch (Exception ignored) {
}
try {
user.getUserRoles().size();
fail();
} catch (Exception ignored) {
}
user.setLogin("testLogin-1");
// merge
tx = cont.persistence().createTransaction();
try {
em = cont.persistence().getEntityManager();
user = em.merge(user);
tx.commit();
} finally {
tx.end();
}
user = reserialize(user);
assertEquals("testLogin-1", user.getLogin());
// loaded by mapping rules
assertEquals("testUser", user.getName());
// exception on getting not loaded references
try {
user.getGroup();
fail();
} catch (Exception ignored) {
}
try {
user.getUserRoles().size();
fail();
} catch (Exception ignored) {
}
// find without view
tx = cont.persistence().createTransaction();
try {
em = cont.persistence().getEntityManager();
user = em.find(User.class, userId);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = reserialize(user);
assertEquals("testLogin-1", user.getLogin());
assertEquals("testUser", user.getName());
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testJoinOnWithToManyView2.
// join on, view contains ToMany attribute, fetch = JOIN
@Test
public void testJoinOnWithToManyView2() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("constraints", new View(Constraint.class, View.LOCAL), FetchMode.JOIN);
TypedQuery<Group> query = em.createQuery("select g from sec$Group g join sys$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
query.setView(view);
List<Group> result = query.getResultList();
tx.commit();
}
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testJoinOnWithParentReference.
// join on, view contains parent attribute
@Test
public void testJoinOnWithParentReference() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("parent");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g join sys$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
query.setView(view);
List<Group> result = query.getResultList();
tx.commit();
}
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testCrossJoinViewParentReference.
// cross join, view with the reference to the parent entity
@Test
public void testCrossJoinViewParentReference() throws Exception {
List<Group> result;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("parent");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g, sec$User u where u.group = g", Group.class);
query.setView(view);
result = query.getResultList();
tx.commit();
}
for (Group g : result) {
g = reserialize(g);
if (g.equals(rootGroup))
assertNull(g.getParent());
else if (g.equals(group))
assertEquals(rootGroup, g.getParent());
}
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testCrossJoinWithToManyView.
// cross join, view has ToMany reference
@Test
public void testCrossJoinWithToManyView() throws Exception {
List<Group> result;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("constraints");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g, sec$User u where u.group = g", Group.class);
query.setView(view);
result = query.getResultList();
tx.commit();
}
for (Group group : result) {
group = reserialize(group);
group.getConstraints().size();
}
}
Aggregations