Examples of OpenJPAEntityManagerFactory


Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

                supportsSelectForUpdate;
    }
   
    public void testVirtualSuperclass() {
       
        OpenJPAEntityManagerFactory pmf =(OpenJPAEntityManagerFactory)
                getEmf(getProps());
        OpenJPAEntityManager pm = (OpenJPAEntityManager) pmf.createEntityManager();
        //FIXME jthomas
        //Sequence gen = pm.getIdentitySequence(SeqF.class);
        Sequence gen=null;
        long next = ((Number) gen.getIncrement()).longValue();
        //FIXME jthomas
        //gen = pm.getIdentitySequence(SeqG.class);
        assertEquals(next + 1, ((Number) gen.getIncrement()).longValue());
        pm.close();
        pmf.close();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    public void testIgnoreVirtualSuperclass() {
       
        Map props=new HashMap();
        props.put("TableName", "JDO_CLASS_SEQUENCE");
        props.put("IgnoreVirtual", "true");
        OpenJPAEntityManagerFactory pmf =(OpenJPAEntityManagerFactory)
                getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();
        //FIXME jthomas
        //Sequence gen = pm.getIdentitySequence(SeqF.class);
        Sequence gen =null;
        long next = ((Number) gen.getIncrement()).longValue();
        //FIXME jthomas
        //Sequence gen2 = pm.getIdentitySequence(SeqG.class);
        Sequence gen2 =null;
        long next2 = ((Number) gen2.getIncrement()).longValue();
        if (next2 != next + 1)
            return; // valid.
        assertTrue(((Number) gen.getIncrement()).longValue() != next2 + 1);
       
        pm.close();
        pmf.close();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    }

    public void testFetchGroupsFromConfiguration() {
        Map props = new HashMap();
        props.put("openjpa.FetchGroups", "default,fg1,fg2");
        OpenJPAEntityManagerFactory factory = getEmf(props);

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) factory.createEntityManager();
        checkGroups(pm, new String[]{ "fg1", "fg2" });
        factory.close();
    }
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

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

            getLog().trace("testQueryTimeout21b - test is " +
                "being skipped for " + dict.platform);
            return;
        }
        getLog().trace("testQueryTimeout21b() - Map(timeout=0)");
        OpenJPAEntityManagerFactory emf = null;
        OpenJPAEntityManager em = null;
        Integer setTime = new Integer(0);
        // create the Map to test overrides
        Map<String,String >props = new HashMap<String,String>();
        props.put("javax.persistence.query.timeout", "0");
       
        try {
            // create our EMF with our timeout property
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-no-properties", "persistence3.xml", props);
            assertNotNull(emf);
            // verify Map properties updated the config
            OpenJPAConfiguration conf = emf.getConfiguration();
            assertNotNull(conf);
            assertEquals("Map provided query timeout", setTime.intValue(),
                conf.getQueryTimeout());
            // verify no default javax.persistence.query.timeout is supplied
            // as the Map properties are not passed through as hints
            em = emf.createEntityManager();
            assertNotNull(em);
            OpenJPAQuery q = em.createNamedQuery("NoHintSingle");
            Map<String, Object> hints = q.getHints();
            assertFalse(hints.containsKey("javax.persistence.query.timeout"));
            // verify internal config values were updated
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

                "being skipped for " + dict.platform);
            return;
        }
        getLog().trace("testQueryTimeout31c() - PU(timeout=1000), " +
            "executeUpdate timeout");
        OpenJPAEntityManagerFactory emf = null;
        OpenJPAEntityManager em = null;
        Integer setTime = new Integer(1000);
        boolean bRetry = true;

        try {
            // create our EMF with our PU set timeout property
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-1000msecs", "persistence3.xml");
            assertNotNull(emf);
            // verify PU properties updated the config
            OpenJPAConfiguration conf = emf.getConfiguration();
            assertNotNull(conf);
            assertEquals("PU provided query timeout", setTime.intValue(),
                conf.getQueryTimeout());
            // create EM and Query
            em = emf.createEntityManager();
            assertNotNull(em);
            OpenJPAQuery q = em.createNativeQuery(nativeUpdateStr);
            q.setParameter(1, new String("updated"));
            // verify no default javax.persistence.query.timeout is supplied
            Map<String, Object> hints = q.getHints();
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

                "being skipped for " + dict.platform);
            return;
        }
        getLog().trace("testQueryTimeout32a() - PU(1000), Map(0), " +
            "QueryHint(1000)");
        OpenJPAEntityManagerFactory emf = null;
        OpenJPAEntityManager em = null;
        Integer setTime = new Integer(0);

        // create the Map to test overrides
        Map<String,String> props = new HashMap<String,String>();
        props.put("javax.persistence.query.timeout", "0");
       
        try {
            // create our EMF with our PU set timeout property
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-1000msecs", "persistence3.xml", props);
            assertNotNull(emf);
            // verify Map properties overrode the PU properties in config
            OpenJPAConfiguration conf = emf.getConfiguration();
            assertNotNull(conf);
            assertEquals("Map provided query timeout", setTime.intValue(),
                conf.getQueryTimeout());
            // create EM and named query
            em = emf.createEntityManager();
            assertNotNull(em);
            OpenJPAQuery q = em.createNamedQuery("Hint1000msec");
            setTime = 1000;
            // verify javax.persistence.query.timeout hint via annotation set
            Map<String, Object> hints = q.getHints();
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

                "being skipped for " + dict.platform);
            return;
        }
        getLog().trace("testQueryTimeout33c() - PU(timeout=0), setHint(1000)," +
            " executeUpdate timeout");
        OpenJPAEntityManagerFactory emf = null;
        OpenJPAEntityManager em = null;
        Integer setTime = new Integer(0);       
        boolean bRetry = true;

        try {
            // create our EMF with our PU set timeout property
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "qtimeout-0msecs", "persistence3.xml");
            assertNotNull(emf);
            // verify PU properties updated the config
            OpenJPAConfiguration conf = emf.getConfiguration();
            assertNotNull(conf);
            assertEquals("PU provided no query timeout", setTime.intValue(),
                conf.getQueryTimeout());
            // create EM and Query
            em = emf.createEntityManager();
            assertNotNull(em);
            // Following fails to cause a SQLException, but takes 2+ secs
            // Query q = em.createQuery("UPDATE QTimeout q SET q.stringField =
            //     + ":strVal WHERE q.id > 0");
            // q.setParameter("strVal", new String("updated"));
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.