use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testMinimal.
@Test
public void testMinimal() {
FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.INSTANCE_NAME).build();
assertFalse(containsSystemProperties(view));
assertTrue(view.containsProperty("name"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testProperty.
@Test
public void testProperty() {
FetchPlan view = ViewBuilder.of(Pet.class).add("name").build();
assertFalse(containsSystemProperties(view));
assertTrue(view.containsProperty("name"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testRefLocalView.
@Test
public void testRefLocalView() {
FetchPlan view = ViewBuilder.of(Pet.class).add("owner", FetchPlan.LOCAL).build();
assertFalse(containsSystemProperties(view));
assertNotNull(view.getProperty("owner"));
FetchPlan ownerView = view.getProperty("owner").getFetchPlan();
assertNotNull(ownerView);
assertTrue(containsSystemProperties(ownerView));
assertTrue(ownerView.containsProperty("name"));
assertFalse(ownerView.containsProperty("address"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
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 = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan 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 = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan 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 = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan 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 io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testOneToMany.
@Test
public void testOneToMany() {
System.out.println("===================== BEGIN testOneToMany =====================");
// test fetchMode = AUTO
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan 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 = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan 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