Search in sources :

Example 26 with FetchPlan

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 =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) SoftDeleteOneToOneA(com.haulmont.cuba.core.model.SoftDeleteOneToOneA) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 27 with FetchPlan

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 =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) SoftDeleteOneToOneA(com.haulmont.cuba.core.model.SoftDeleteOneToOneA) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 28 with FetchPlan

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);
    }
}
Also used : DataSet(io.jmix.reports.entity.DataSet) FetchPlan(io.jmix.core.FetchPlan)

Example 29 with FetchPlan

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) {
    }
}
Also used : User(com.haulmont.cuba.core.model.common.User) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 30 with FetchPlan

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());
}
Also used : User(com.haulmont.cuba.core.model.common.User) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Aggregations

FetchPlan (io.jmix.core.FetchPlan)61 Test (org.junit.jupiter.api.Test)48 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)45 View (com.haulmont.cuba.core.global.View)35 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)10 Pet (com.haulmont.cuba.core.model.Pet)5 SoftDeleteOneToOneA (com.haulmont.cuba.core.model.SoftDeleteOneToOneA)5 Group (com.haulmont.cuba.core.model.common.Group)5 User (com.haulmont.cuba.core.model.common.User)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 DataManager (com.haulmont.cuba.core.global.DataManager)3 LoadContext (com.haulmont.cuba.core.global.LoadContext)3 FetchPlanProperty (io.jmix.core.FetchPlanProperty)3 Metadata (io.jmix.core.Metadata)3 MetadataTools (io.jmix.core.MetadataTools)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 SoftDeleteOneToOneB (com.haulmont.cuba.core.model.SoftDeleteOneToOneB)2 Permission (com.haulmont.cuba.core.model.common.Permission)2 QueryImpl (com.haulmont.cuba.core.sys.QueryImpl)2 Entity (io.jmix.core.Entity)2