Examples of OpenJPAEntityManagerFactory


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

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

            getLog().trace("testQueryTimeout6 - test is " +
                "being skipped for " + dict.platform);
            return;
        }
        getLog().trace("testQueryTimeout6() - No EM.find() update timeout");
        OpenJPAEntityManagerFactory emf = null;
        OpenJPAEntityManager em = null;
        Integer setTime = new Integer(1000);
       
        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 timeout", setTime.intValue(),
                conf.getQueryTimeout());
            // create EM
            em = emf.createEntityManager();
            assertNotNull(em);

            try {
                long startTime = System.currentTimeMillis();
                QTimeout qt = em.find(QTimeout.class, new Integer(1));
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     * Scenario being tested:
     *   1) By default, ValidationFactory is null
     */
    public void testValidationFactory1() {
        getLog().trace("testValidationFactory1() - Default is null");
        OpenJPAEntityManagerFactory emf = null;

        // create our EMF
        emf = OpenJPAPersistence.createEntityManagerFactory(
            "simple-none-mode",
            "org/apache/openjpa/persistence/validation/persistence.xml");
        assertNotNull(emf);
        // verify default validation mode
        OpenJPAConfiguration conf = emf.getConfiguration();
        assertNotNull(conf);
        assertEquals("Default ValidationFactory",
            null,
            conf.getValidationFactoryInstance());
        closeEMF(emf);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     *   2) An invalid ValidationFactory with a mode of NONE will not
     *      cause an exception
     */
    public void testValidationFactory2() {
        getLog().trace("testValidationFactory2() - ignored invalid factory");
        OpenJPAEntityManagerFactory emf = null;

        // create the Map to test overrides
        //   Just use current class object, as we have no provider to test with
        Map<String,Object> props = new HashMap<String,Object>();
        props.put("javax.persistence.validation.factory",
            this.getClass());

        // create our EMF
        emf = OpenJPAPersistence.createEntityManagerFactory(
            "simple-none-mode",
            "org/apache/openjpa/persistence/validation/persistence.xml",
            props);
        assertNotNull(emf);
        // verify same "validation factory" object is returned
        OpenJPAConfiguration conf = emf.getConfiguration();
        assertNotNull(conf);
        assertEquals("ValidationFactory",
            this.getClass(),
            conf.getValidationFactoryInstance());
        closeEMF(emf);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     *   3) An invalid ValidationFactory with a mode of AUTO will not
     *      cause an exception
     */
    public void testValidationFactory3() {
        getLog().trace("testValidationFactory3() - optional invalid factory");
        OpenJPAEntityManagerFactory emf = null;

        // create the Map to test overrides
        //   Just use current class object, as we have no provider to test with
        Map<String,Object> props = new HashMap<String,Object>();
        props.put("javax.persistence.validation.factory",
            this.getClass());

        // create our EMF
        emf = OpenJPAPersistence.createEntityManagerFactory(
            "simple-auto-mode",
            "org/apache/openjpa/persistence/validation/persistence.xml",
            props);
        assertNotNull(emf);
        // verify same "validation factory" object is returned
        OpenJPAConfiguration conf = emf.getConfiguration();
        assertNotNull(conf);
        assertEquals("ValidationFactory",
            this.getClass(),
            conf.getValidationFactoryInstance());
        closeEMF(emf);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     *   4) An invalid ValidationFactory with a mode of CALLBACK will
     *      cause a fatal exception
     */
    public void testValidationFactory4() {
        getLog().trace("testValidationFactory4() - required invalid factory");
        OpenJPAEntityManagerFactory emf = null;

        // create the Map to test overrides
        //   Just use current class object, as we have no provider to test with
        Map<String,Object> props = new HashMap<String,Object>();
        props.put("javax.persistence.validation.factory",
            this.getClass());
        props.put("javax.persistence.validation.mode",
            String.valueOf(ValidationMode.CALLBACK));

        try {
            // create our EMF
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "simple-callback-mode",
                "org/apache/openjpa/persistence/validation/persistence.xml",
                props);
            assertNotNull(emf);
            // verify validation mode
            OpenJPAConfiguration conf = emf.getConfiguration();
            assertNotNull(conf);
            assertEquals("Validation mode",
                String.valueOf(ValidationMode.CALLBACK),
                conf.getValidationMode());
            fail("Expected an exception when ValidationMode=CALLBACK and " +
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

    /**
     * Verify the use of the "openjpa.FetchGroups" property when used to add a fetch group
     * to the default fetch plan.  Note when overriding that "default" must be included in the list.
     */
    public void testPctxDefaultFetchPlan001() {
        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);
       
        FGManager findMgr = em.find(FGManager.class, mgr.getId());
        em.close();
        emf2.close();
       
        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
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     * fields normally eagerly loaded as per JPA rules to behave as lazy loaded fields.
     *
     * Note that fetch groups are case sensitive, "default" != "Default".
     */
    public void testPctxDefaultFetchPlan002() {
        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());
       
        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());
        assertNull(findMgr.getLastName());
        assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

     *
     * Note that the method does not place "default" back in the list of active fetch groups, OPENJPA-2413
     * was opened to note this behavior.
     */
    public void testClearFetchGroups001() {
        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());
       
        fp.clearFetchGroups(); // OPENJPA-2413: now places "default" in the list of active fetch groups.
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        FGManager mgr = managerSet.iterator().next();
        assertNotNull(mgr);
       
        FGManager findMgr = em.find(FGManager.class, mgr.getId());
        em.close();
        emf2.close();
       
        assertEquals(mgr.getId(), findMgr.getId());
        assertEquals(mgr.getFirstName(), findMgr.getFirstName());
        assertEquals(mgr.getLastName(), findMgr.getLastName());
        assertNull(findMgr.getDescription()); // Should be lazy-loaded       
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.