use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testRefView.
@Test
public void testRefView() {
FetchPlan view = ViewBuilder.of(Pet.class).add("owner", builder -> builder.add("name")).build();
assertFalse(containsSystemProperties(view));
assertNotNull(view.getProperty("owner"));
FetchPlan ownerView = view.getProperty("owner").getFetchPlan();
assertNotNull(ownerView);
assertFalse(containsSystemProperties(ownerView));
assertTrue(ownerView.containsProperty("name"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testBuild.
@Test
public void testBuild() {
FetchPlan view = ViewBuilder.of(Pet.class).build();
assertNotNull(view);
assertFalse(containsSystemProperties(view));
assertFalse(view.containsProperty("name"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testReferenceToDeletedEntityOneToManyThroughManyToOne.
@Test
public void testReferenceToDeletedEntityOneToManyThroughManyToOne() {
FetchPlan constraintView = new View(Constraint.class).addProperty("code");
FetchPlan groupView = new View(Group.class).addProperty("name").addProperty("constraints", constraintView, FetchMode.BATCH);
FetchPlan groupHierarchyView = new View(GroupHierarchy.class).addProperty("group", groupView, FetchMode.BATCH);
GroupHierarchy groupHierarchy = persistence.callInTransaction((em) -> em.find(GroupHierarchy.class, groupHierarchyId, groupHierarchyView));
assertNotNull(groupHierarchy);
assertNotNull(groupHierarchy.getGroup());
assertEquals(1, groupHierarchy.getGroup().getConstraints().size());
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testManyToOne_InnerJoinOnClause.
@Test
public void testManyToOne_InnerJoinOnClause() throws SQLException {
System.out.println("===================== BEGIN testManyToOne =====================");
JdbcTemplate jdbcTemplate = new JdbcTemplate(persistence.getDataSource());
jdbcTemplate.update("update TEST_GROUP set DELETE_TS = current_timestamp, DELETED_BY = 'admin' where ID = ?", groupId.toString());
// test without view
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
Group group = null;
try {
User user = em.find(User.class, userId);
group = user.getGroup();
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
FetchPlan view;
// test fetchMode = AUTO (JOIN is used)
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"));
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
Group group;
try {
User user = em.find(User.class, userId, view);
group = user.getGroup();
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
// test fetchMode = UNDEFINED
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.UNDEFINED);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
Group group;
try {
User user = em.find(User.class, userId, view);
group = user.getGroup();
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
// test fetchMode = BATCH
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.BATCH);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
Group group;
try {
User user = em.find(User.class, userId, view);
group = user.getGroup();
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
System.out.println("===================== END testManyToOne =====================");
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testManyToOne.
@Test
public void testManyToOne() throws SQLException {
System.out.println("===================== BEGIN testManyToOne =====================");
JdbcTemplate jdbcTemplate = new JdbcTemplate(persistence.getDataSource());
jdbcTemplate.update("update TEST_GROUP set DELETE_TS = current_timestamp, DELETED_BY = 'admin' where ID = ?", groupId.toString());
// test without view
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user = em.find(User.class, userId);
Group group = user.getGroup();
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
FetchPlan view;
// test fetchMode = AUTO (JOIN is used)
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"));
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user = em.find(User.class, userId, view);
Group group = user.getGroup();
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
// test fetchMode = UNDEFINED
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.UNDEFINED);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user = em.find(User.class, userId, view);
Group group = user.getGroup();
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
// test fetchMode = BATCH
view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.BATCH);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user = em.find(User.class, userId, view);
Group group = user.getGroup();
tx.commit();
assertNotNull(group);
assertTrue(group.isDeleted());
}
System.out.println("===================== END testManyToOne =====================");
}
Aggregations