Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.EntityManagerImpl


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


        em.clear();
    }
   
    public void testNullParamsWithNamedQuery02() {
        // Verify Query SQL Cache is enabled
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());       
       
        resetSQL();
        Query q1A = em.createNamedQuery("QCEntity.getByAmount");
        q1A.setParameter("amount", null);
        List resultListNull1A = q1A.getResultList();
View Full Code Here

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

     * This test asserts that the ObjectId obtained from the Broker is the same for the following cases: [ An Entity
     * that exists in the current persistence context, a detached Entity with a DetachedStateManager, and a detached
     * Entity with no DetachedStateManager]
     */
    public void testGetObjectId() {
        EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
        Broker broker = em.getBroker();

        em.getTransaction().begin();
        A a = new A();
        em.persist(a);
        Object oidInPersistenceContext = broker.getObjectId(a);
        em.getTransaction().commit();
        em.clear();
        Object oidDetached = broker.getObjectId(a);
        em.close();

        em = (EntityManagerImpl) emf.createEntityManager();
        broker = em.getBroker();
        A a2 = new A();
        a2.setId(a.getId());

        Object oidDetachedNoSm = broker.getObjectId(a2);

View Full Code Here

                                                          + TblParent.class.getName() + ")");
        props.put("openjpa.jdbc.QuerySQLCache", "true");

        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.
                                             cast(Persistence.createEntityManagerFactory("test", props));
        EntityManagerImpl em = (EntityManagerImpl)emf.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();
        emf.close();
    }
View Full Code Here

        props.put("openjpa.jdbc.QuerySQLCache", "false");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        BrokerImpl broker = (BrokerImpl) em.getBroker();
        DelegatingStoreManager dstore = broker.getStoreManager();
        JDBCStoreManager jstore =
            (JDBCStoreManager)dstore.getInnermostDelegate();
       
        em.getTransaction().begin();
        Person p = new Person();
        p.setId(1);
        em.persist(p);
        em.flush();
        em.getTransaction().commit();
       
        Person p1 = em.find(Person.class, 1);

        assertFalse(jstore.isQuerySQLCacheOn());
       
        em.getTransaction().begin();
        em.remove(p);
        em.flush();
        em.getTransaction().commit();
       
        em.close();
        emf.close();
    }
View Full Code Here

            "org.apache.openjpa.kernel.TestQuerySQLCache.CustomCacheMap");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        BrokerImpl broker = (BrokerImpl) em.getBroker();
        DelegatingStoreManager dstore = broker.getStoreManager();
        JDBCStoreManager jstore =
            (JDBCStoreManager)dstore.getInnermostDelegate();
       
        em.getTransaction().begin();
        Person p = new Person();
        p.setId(1);
        em.persist(p);
        em.flush();
        em.getTransaction().commit();
       
        Person p1 = em.find(Person.class, 1);

        assertTrue(jstore.isQuerySQLCacheOn());

        Map sqlCache = jstore.getQuerySQLCache();
        Set keys = sqlCache.keySet();
        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            Map cacheMap = (Map) iter.next();
            assertTrue((cacheMap instanceof
                org.apache.openjpa.kernel.TestQuerySQLCache.CustomCacheMap));
            //make sure there is an entry in the cache
            assertEquals(1, cacheMap.size());  
        }
       
        em.getTransaction().begin();
        em.remove(p);
        em.flush();
        em.getTransaction().commit();
       
        em.close();
        emf.close();
    }
View Full Code Here

        props.put("openjpa.jdbc.QuerySQLCache", "all");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        BrokerImpl broker = (BrokerImpl) em.getBroker();
        DelegatingStoreManager dstore = broker.getStoreManager();
        JDBCStoreManager jstore =
            (JDBCStoreManager)dstore.getInnermostDelegate();

        em.getTransaction().begin();
        Person p = new Person();
        p.setId(1);
        em.persist(p);
        em.flush();
        em.getTransaction().commit();
       
        Person p1 = em.find(Person.class, 1);
        Map sqlCache = jstore.getQuerySQLCache();
        Set keys = sqlCache.keySet();
        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            Map cacheMap = (Map) iter.next();
            //make sure there is an entry in the cache
            assertEquals(1, cacheMap.size());  
        }
       
        em.getTransaction().begin();
        em.remove(p);
        em.flush();
        em.getTransaction().commit();
       
        em.close();
        emf.close();
    }
View Full Code Here

        props.put("openjpa.jdbc.QuerySQLCache", "true");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        BrokerImpl broker = (BrokerImpl) em.getBroker();
        DelegatingStoreManager dstore = broker.getStoreManager();
        JDBCStoreManager jstore =
            (JDBCStoreManager)dstore.getInnermostDelegate();
       
        em.getTransaction().begin();
        Person p = new Person();
        p.setId(1);
        em.persist(p);
        em.flush();
        em.getTransaction().commit();
       
        Person p1 = em.find(Person.class, 1);
        Map sqlCache = jstore.getQuerySQLCache();
        Set keys = sqlCache.keySet();
        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            Map cacheMap = (Map) iter.next();
            //make sure there is an entry in the cache
            assertEquals(1, cacheMap.size());  
        }
       
        em.getTransaction().begin();
        em.remove(p);
        em.flush();
        em.getTransaction().commit();
       
        em.close();
        emf.close();
    }
View Full Code Here

        props.put("openjpa.jdbc.QuerySQLCache", "all");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        BrokerImpl broker = (BrokerImpl) em.getBroker();
        DelegatingStoreManager dstore = broker.getStoreManager();
        JDBCStoreManager jstore =
            (JDBCStoreManager)dstore.getInnermostDelegate();

        em.getTransaction().begin();
        Person p = new Person();
        p.setId(1);
        em.persist(p);
        em.flush();
        em.getTransaction().commit();
       
        Person p1 = em.find(Person.class, 1);
        Map sqlCache = jstore.getQuerySQLCache();
        Set keys = sqlCache.keySet();
        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            Map cacheMap = (Map) iter.next();
            //make sure there is an entry in the cache
            assertEquals(1, cacheMap.size());  
        }
       
        em.getTransaction().begin();
        em.remove(p);
        em.flush();
        em.getTransaction().commit();
       
        em.close();
        emf.close();
    }
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.