Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.EntityManagerImpl


        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", "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", "true");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
       
        em.getTransaction().begin();
        for (int i = 0; i < 2; 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 = 0; i < 2; 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", "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", "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", "true");
        OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
            OpenJPAPersistence.cast(
                Persistence.createEntityManagerFactory("test", props));
       
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();

        em.getTransaction().begin();
        em.createQuery("Delete from TblGrandChild").executeUpdate();
        em.createQuery("Delete from TblChild").executeUpdate();
        em.createQuery("Delete from TblParent").executeUpdate();
        em.getTransaction().commit();
        em.close();
       
        em = (EntityManagerImpl) emf.createEntityManager();
       
       
        em.getTransaction().begin();
        for (int i = 0; i < 2; 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 = 0; i < 2; 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", "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

        super(entityManagerProvider);
    }
   
    @Override
    public String getQueryStringOfNamedQuery(String queryName) {
        EntityManagerImpl entityManagerImpl = (EntityManagerImpl) getEntityManager().getDelegate();
        return entityManagerImpl.createNamedQuery(queryName).getQueryString();
    }
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.