Examples of OpenJPAEntityManagerFactory


Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    /**
     * The resetFetchGroups() method restores the fetch plan's active fetch plans to
     * the PCtx's configured default.
     */
    public void testResetFetchGroups001() {
        OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
            FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
            "openjpa.FetchGroups", "Default,DescFetchGroup");
       
        OpenJPAEntityManager em = emf2.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
       
        // OPENJPA-2413: now places "default" in the list of active fetch groups.
        fp.clearFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        // Reset to the PCtx default Fetch Plan
        fp.resetFetchGroups();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        // Verify that the PCtx default fetch plan was properly restored.  "default" should not be enabled
        // since it was not listed by openjpa.FetchGroups.
        FGManager mgr = managerSet.iterator().next();
        assertNotNull(mgr);
       
        FGManager findMgr = em.find(FGManager.class, mgr.getId());
        em.close();
        emf2.close();
       
        assertEquals(mgr.getId(), findMgr.getId()); // Identity is always loaded
//        assertNull(findMgr.getFirstName()); // Commented out, for OPENJPA-2420
//        assertNull(findMgr.getLastName());
        assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
     * The PCtx's default fetch plan is modified by the "openjpa.FetchGroups" property.
     * 
     */
    public void testFinderCache004() {
        OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
            FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
            "openjpa.FetchGroups", "default,DescFetchGroup");
       
        OpenJPAEntityManager em = emf2.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        FGManager mgr = managerSet.iterator().next();
        assertNotNull(mgr);
       
        {
            // First find, to prime the Finder Cache
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        // Remove a fetch group to the fetch plan and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Restore the fetch group previously removed, and verify expected behavior
        fp.addFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }  
       
        // Remove a fetch group to the fetch plan and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Reset the fetch plan, and verify expected behavior
        fp.resetFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        // Clear all fetch groups, and verify expected behavior
        // OPENJPA-2413: now places "default" in the list of active fetch groups.
        fp.clearFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        em.close();
        emf2.close();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     *
     * In this variant, a find using a modified fetch plan is first executed, which should not be added
     * to the finder cache. 
     */
    public void testFinderCache005() {
        OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
            FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
            "openjpa.FetchGroups", "default,DescFetchGroup");
       
        OpenJPAEntityManager em = emf2.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        FGManager mgr = managerSet.iterator().next();
        assertNotNull(mgr);
       
        fp.removeFetchGroup("DescFetchGroup");
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Restore the "DescFetchGroup" fetch group, and verify expected behavior
        fp.addFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }  
       
        // Remove the "DescFetchGroup" fetch group, and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Reset the fetch plan, and verify expected behavior
        fp.resetFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        // Remove the "DescFetchGroup" fetch group, and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Clear all fetch groups, and verify expected behavior
        // OPENJPA-2413: now places "default" in the list of active fetch groups.
        fp.clearFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        em.close();
        emf2.close();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

        props.put("javax.persistence.query.timeout", "7000");
    }
   
    public void testNoProperties() {
        getLog().trace("testNoProperties() - no properties in persistence.xml");
        OpenJPAEntityManagerFactory emf1 = null, emf2 = null;
        OpenJPAEntityManager em1 = null, em2 = null;
       
        try {
            OpenJPAQuery q;
            Map<String, Object> hints;
            Integer timeout;
            Integer lTime = new Integer(0);
            Integer qTime = new Integer(0);
           
            // create our PU without properties
            emf1 = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-no-properties", "persistence3.xml");
            assertNotNull(emf1);
            emf2 = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-no-properties", "persistence3.xml", props);
            assertNotNull(emf2);
           
            //=============
            // Test for 1a)
            //=============
            // verify no config properties from persistence.xml
            OpenJPAConfiguration conf1 = emf1.getConfiguration();
            assertNotNull(conf1);
            assertEquals("Expected no default lock timeout", lTime.intValue(),
                conf1.getLockTimeout());
            assertEquals("Expected no default query timeout", qTime.intValue(),
                conf1.getQueryTimeout());
            // verify Query receives no properties
            em1 = emf1.createEntityManager();
            assertNotNull(em1);
            q = em1.createNamedQuery("NoHintList");
            // verify no Query hints
            hints = q.getHints();
            assertFalse(hints.containsKey("javax.persistence.lock.timeout"));
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

        }
    }

    public void testWithProperties() {
        getLog().trace("testWithProperties() - properties in persistence.xml");
        OpenJPAEntityManagerFactory emf1 = null, emf2 = null;
        OpenJPAEntityManager em1 = null, em2 = null;
       
        try {
            OpenJPAQuery q;
            Map<String, Object> hints;
            Integer timeout;
            Integer lTime = new Integer(10000);
            Integer qTime = new Integer(5000);
           
            // create our PU with properties
            emf1 = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-with-properties", "persistence3.xml");
            assertNotNull(emf1);
            emf2 = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-with-properties", "persistence3.xml", props);
            assertNotNull(emf2);
           
            //=============
            // Test for 1b)
            //=============
            // verify properties in persistence.xml
            OpenJPAConfiguration conf1 = emf1.getConfiguration();
            assertNotNull(conf1);
            assertEquals("Default PU lock timeout", lTime.intValue(),
                conf1.getLockTimeout());
            assertEquals("Default PU query timeout.", qTime.intValue(),
                conf1.getQueryTimeout());
            // verify Query receives the properties
            em1 = emf1.createEntityManager();
            assertNotNull(em1);
            q = em1.createNamedQuery("NoHintList");   
            // Cannot verify properties are passed through as Query hints
            //     See explanation and commented out test in testNoProperties()
            // verify timeout properties supplied in persistence.xml
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    public void testRollback() {
        //FIXME
        //PersistenceManagerFactory factory = getPMFactory(new String[]{
        //    "openjpa.RestoreMutableValues", "true",
        //});
        OpenJPAEntityManagerFactory factory =null;
        OpenJPAEntityManager pm = factory.createEntityManager();
        LRSPC pc = (LRSPC) pm.getObjectId(_oid);
        startTx(pm);
        pc.getStringCollection().remove("val2");
        pc.getStringCollection().add("val4");
        rollbackTx(pm);
        assertTrue(pc.getStringCollection().contains("val2"));
        assertFalse(pc.getStringCollection().contains("val4"));
        pm.close();
        factory.close();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

                "kodo-prefixed properties must be converted to openjpa. " +
                    "Properties: " + keys);

        addProperties(map);

        OpenJPAEntityManagerFactory emf = emfs.get(map);
        if (emf != null) {
            return emf;
        }

        if (props != null) {
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    public void testJDBCListener() {
        Map props=new HashMap();
        props.put("openjpa.jdbc.JDBCListeners", Listener.class.getName());
       
        OpenJPAEntityManagerFactory factory =(OpenJPAEntityManagerFactory)
                getEmf(props);

        commitOccurred = false;
        OpenJPAEntityManager pm = factory.createEntityManager();    
       
        pm.getTransaction().begin();
        assertFalse(commitOccurred);
        pm.persist(new RuntimeTest1("Listener test", 99));
        pm.getTransaction().commit();
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    public TestSchemaGenerator(String name) {
        super(name);
    }

    public void testSchemaGen() throws Exception {
        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory) getEmf();
        OpenJPAEntityManager pm = pmf.createEntityManager();
        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) pmf).getConfiguration();

        StringWriter sw = new StringWriter();

        SchemaTool.Flags flags = new SchemaTool.Flags();
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    public void testConstraintAnalysis() {
        //FIXME jthomas
        //PersistenceManagerFactory factory = getPMFactory(new String[]{
          //  "openjpa.jdbc.SchemaFactory", "native(ForeignKeys=true)",
        //});
        OpenJPAEntityManagerFactory factory=null;
        OpenJPAEntityManager pm = factory.createEntityManager();
        startTx(pm);
       
       deleteAll( MappingTest1.class,pm);
       deleteAll( MappingTest2.class,pm);
        endTx(pm);
        pm.close();

        pm = factory.createEntityManager();
        startTx(pm);
        for (int i = 0; i < 10; i++) {
            MappingTest5 pc1 = new MappingTest5();
            pc1.setPk1(i);
            pc1.setPk2(i + 1);
            MappingTest5 pc2 = new MappingTest5();
            pc2.setPk1(i + 10);
            pc2.setPk2(i + 11);
            pc1.setVertRel(pc2);
            pc2.setVertRel(pc1);
            pm.persist(pc1);
        }
        endTx(pm);
        pm.close();

        assertSizes(20, MappingTest5.class);

        pm = factory.createEntityManager();
        startTx(pm);
        deleteAll(MappingTest2.class,pm);
        endTx(pm);
        pm.close();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.