Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.EntityManagerImpl


    public void setUp() {
        super.setUp(p);
    }

    public void testCacheHit() throws Exception {
        EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
        // Change the eager field to lazy to make testing easier.
        ClassMetaData cmd =
            em.getConfiguration().getMetaDataRepositoryInstance().getMetaData(CachedEntityStatistics.class, null, true);
        cmd.getField("eagerList").setInDefaultFetchGroup(false);
        try {
            em.getTransaction().begin();
            CachedEntityStatistics e = new CachedEntityStatistics();
            CachedEntityStatistics lazy = new CachedEntityStatistics();
            Set<CachedEntityStatistics> lazyList = new HashSet<CachedEntityStatistics>();
            lazyList.add(lazy);
            e.setLazyList(lazyList);
            em.persist(e);
            em.persist(lazy);
            em.flush();
            em.clear();

            // Should prime the cache
            em.find(CachedEntityStatistics.class, e.getId()).getLazyList();
            em.clear();
            sql.clear();

            CachedEntityStatistics c = em.find(CachedEntityStatistics.class, e.getId());
            c.getLazyList();
            assertEquals(0, sql.size());

            em.getTransaction().commit();
        } finally {
            if (em.getTransaction().isActive())
                em.getTransaction().rollback();
            em.close();
        }
    }
View Full Code Here


    public void testRoundtrip() {
        List<String> list = new ArrayList<String>();
        list.add("xxx");
        list.add("yyy");
        ResultList resultList = new ListResultList(list);
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        em.close();
        RuntimeExceptionTranslator trans = PersistenceExceptions.getRollbackTranslator(em);
        DistinctResultList distinctResultList = new DistinctResultList(resultList, trans);
        try {
            roundtrip(distinctResultList);
        } catch (Exception e) {
View Full Code Here

    public void testRoundtrip() {
        List<String> list = new ArrayList<String>();
        list.add("xxx");
        list.add("yyy");
        ResultList resultList = new ListResultList(list);
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        em.close();
        RuntimeExceptionTranslator trans = PersistenceExceptions.getRollbackTranslator(em);
        DistinctResultList distinctResultList = new DistinctResultList(resultList, trans);
        try {
            roundtrip(distinctResultList);
        } catch (Exception e) {
View Full Code Here

        props.put("openjpa.jdbc.QuerySQLCache", "true");

        OpenJPAEntityManagerFactorySPI emf1 = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.
                                             cast(Persistence.createEntityManagerFactory("test", props));
        try {
            EntityManagerImpl em = (EntityManagerImpl)emf1.createEntityManager();
   
            em.getTransaction().begin();
   
            for (int i = 1; i < 3; i++) {
                TblParent p = new TblParent();
                p.setParentId(i);
                TblChild c = new TblChild();
                c.setChildId(i);
                c.setTblParent(p);
                p.addTblChild(c);
                em.persist(p);
                em.persist(c);
   
                TblGrandChild gc = new TblGrandChild();
                gc.setGrandChildId(i);
                gc.setTblChild(c);
                c.addTblGrandChild(gc);
   
                em.persist(p);
                em.persist(c);
                em.persist(gc);
            }
            em.flush();
            em.getTransaction().commit();
            em.clear();
   
            for (int i = 1; i < 3; i++) {
                TblParent p = em.find(TblParent.class, i);
                int pid = p.getParentId();
                assertEquals(pid, i);
                Collection<TblChild> children = p.getTblChildren();
                boolean hasChild = false;
                for (TblChild c : children) {
                    hasChild = true;
                    Collection<TblGrandChild> gchildren = c.getTblGrandChildren();
                    int cid = c.getChildId();
                    assertEquals(cid, i);
                    boolean hasGrandChild = false;
                    for (TblGrandChild gc : gchildren) {
                        hasGrandChild = true;
                        int gcId = gc.getGrandChildId();
                        assertEquals(gcId, i);
                    }
                    assertTrue(hasGrandChild);
                }
                assertTrue(hasChild);
                em.close();
            }
        } finally {
            closeEMF(emf1);
        }
    }
View Full Code Here

   
    public void testEMConfig001() {
        Map propMap = new HashMap();
        EntityManager em = emf.createEntityManager(propMap);
       
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());
    }
View Full Code Here

        em.clear();
    }
   
    public void testNullParamsWithNumericPosition01() {
        // Verify Query SQL Cache is enabled
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());
              
        Query q = em.createQuery("SELECT o from QCEntity o WHERE o.amount=?1");
       
        // Test with NULL parameter, SQL should contain a IS NULL predicate
        resetSQL();
View Full Code Here

    public void testEMConfig002() {
        Map propMap = new HashMap();
        propMap.put("openjpa.jdbc.QuerySQLCache", "true(EnableStatistics=true)");
        EntityManager em = emf.createEntityManager(propMap);
       
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());
    }
View Full Code Here

        assertEquals(1, resultListNull2.size());
    }
   
    public void testNullParamsWithNumericPosition02() {
        // Verify Query SQL Cache is enabled
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());
                     
        // Test with NULL parameter, SQL should contain a IS NULL predicate
        resetSQL();
        Query q1 = em.createQuery("SELECT o from QCEntity o WHERE o.amount=?1");
        q1.setParameter(1, null);
View Full Code Here

    public void testEMConfig003() {
        Map propMap = new HashMap();
        propMap.put("openjpa.jdbc.QuerySQLCache", "false");
        EntityManager em = emf.createEntityManager(propMap);
       
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertFalse(eml.getQuerySQLCache());
    }
View Full Code Here

        assertEquals(1, resultListNull2.size());
    }
   
    public void testNullParamsWithNamedQuery01() {
        // Verify Query SQL Cache is enabled
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());       
       
        Query q = em.createNamedQuery("QCEntity.getByAmount");
       
        resetSQL();      
        q.setParameter("amount", null);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.EntityManagerImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.