use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testOneToOneQuery_InnerJoinOnClause.
@Test
public void testOneToOneQuery_InnerJoinOnClause() {
System.out.println("===================== BEGIN testOneToOneQuery_InnerJoinOnClause =====================");
// test fetchMode = AUTO
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
try {
FetchPlan 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);
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneQuery_InnerJoinOnClause =====================");
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteTest method testOneToOne_InnerJoinOnClause.
@Test
public void testOneToOne_InnerJoinOnClause() {
System.out.println("===================== BEGIN testOneToOne_InnerJoinOnClause =====================");
// test fetchMode = AUTO
System.out.println("===================== BEGIN testOneToOne_InnerJoinOnClause fetchMode = AUTO =====================");
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
try {
FetchPlan view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"));
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
} finally {
tx.end();
}
// test fetchMode = BATCH
System.out.println("===================== BEGIN testOneToOne_InnerJoinOnClause fetchMode = BATCH =====================");
tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
try {
FetchPlan view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.BATCH);
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
} finally {
tx.end();
}
// test fetchMode = UNDEFINED
System.out.println("===================== BEGIN testOneToOne_InnerJoinOnClause fetchMode = UNDEFINED =====================");
tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
try {
FetchPlan view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
assertNotNull(oneToOneA);
assertNotNull(oneToOneA.getB());
assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
} finally {
setPrintInnerJoinInWhereClause(em, prevValue);
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOne =====================");
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ReportGsonSerializationSupport method readUnresolvedProperty.
@Override
protected void readUnresolvedProperty(Entity entity, String propertyName, JsonReader in) throws IOException {
if (entity instanceof DataSet && "fetchPlan".equals(propertyName)) {
String fetchPlanDefinition = in.nextString();
FetchPlan fetchPlan = gsonBuilder.create().fromJson(fetchPlanDefinition, FetchPlan.class);
((DataSet) entity).setFetchPlan(fetchPlan);
} else {
super.readUnresolvedProperty(entity, propertyName, in);
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EclipseLinkDetachedTest method testNotSerializedFetchGroup.
@Test
public void testNotSerializedFetchGroup() throws Exception {
Transaction tx;
EntityManager em;
User user;
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
FetchPlan view = new View(User.class).addProperty("login").setLoadPartialEntities(true);
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
assertEquals("testLogin", user.getLogin());
// unfetched
try {
user.getName();
fail();
} catch (IllegalStateException ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "group"));
user.getGroup();
} catch (IllegalStateException ignored) {
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EclipseLinkDetachedTest method testSerializedFetchGroupMerge.
@Test
public void testSerializedFetchGroupMerge() throws Exception {
Transaction tx;
EntityManager em;
User user;
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
FetchPlan view = new View(User.class).addProperty("login").setLoadPartialEntities(true);
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = testSupport.reserialize(user);
assertEquals("testLogin", user.getLogin());
// exception on getting not loaded references
try {
user.getName();
fail();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "group"));
user.getGroup();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "userRoles"));
user.getUserRoles().size();
} catch (Exception ignored) {
}
user.setLogin("testLogin-1");
// merge
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
user = em.merge(user);
tx.commit();
} finally {
tx.end();
}
user = testSupport.reserialize(user);
assertEquals("testLogin-1", user.getLogin());
// loaded by mapping rules
assertEquals("testUser", user.getName());
// exception on getting not loaded references
try {
assertFalse(entityStates.isLoaded(user, "group"));
user.getGroup();
} catch (Exception ignored) {
}
try {
user.getUserRoles().size();
} catch (Exception ignored) {
}
// find without view
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
user = em.find(User.class, userId);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = testSupport.reserialize(user);
assertEquals("testLogin-1", user.getLogin());
assertEquals("testUser", user.getName());
}
Aggregations