Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory


    /**
     * Test that the CacheStatistics is disabled by default.
     */
    public void testDefaultSettings() {
        Object[] props = { "openjpa.DataCache", "true", "openjpa.RemoteCommitProvider", "sjvm" };
        OpenJPAEntityManagerFactory emf1 = createNamedEMF("second-persistence-unit", props);
        assertFalse(emf1.getStoreCache().getStatistics().isEnabled());
        closeEMF(emf1);
    }
View Full Code Here


    }

    public void testMultipleUnits() {
        String[] props = { "openjpa.DataCache", "true", "openjpa.RemoteCommitProvider", "sjvm" };
        OpenJPAEntityManagerFactory emf1 = createNamedEMF("test", props);
        OpenJPAEntityManagerFactory emf2 = createNamedEMF("empty-pu", props);
        assertNotSame(emf1, emf2);
        assertNotSame(emf1.getStoreCache(), emf2.getStoreCache());
        assertNotSame(emf1.getStoreCache().getStatistics(), emf2.getStoreCache().getStatistics());
        assertNotSame(((StoreCacheImpl) emf1.getStoreCache()).getDelegate(), ((StoreCacheImpl) emf2.getStoreCache())
            .getDelegate());
        closeEMF(emf1);
        closeEMF(emf2);
    }
View Full Code Here

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

        addProperties(map);

        OpenJPAEntityManagerFactory emf = emfs.get(map);
        if (emf == null) {
            emf = OpenJPAPersistence.createEntityManagerFactory(
                "TestConv", persistenceXmlResource, map);
            emfs.put(map, emf);
        }
View Full Code Here

    /**
     * Tests that lifecycle listeners are transferred from factory to
     * persistence managers.
     */
    public void testFactoryLifecycleListeners() {
        OpenJPAEntityManagerFactory pmf =
            (OpenJPAEntityManagerFactory) getEmf();
        OpenJPAEntityManagerFactorySPI pmfSPI =
            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(pmf));

        //FIXME jthomas       
        LoadListener listener = new LoadListener() {
            public void afterLoad(LifecycleEvent ev) {
            }

            public void afterRefresh(LifecycleEvent ev) {
            }
        };

        pmfSPI
            .addLifecycleListener(listener, new Class[]{ RuntimeTest4.class });

        try {
            BrokerImpl broker = (BrokerImpl) JPAFacadeHelper.toBroker
                (pmf.createEntityManager());
            MetaDataRepository repos = broker.getConfiguration().
                getMetaDataRepositoryInstance();
            assertTrue("no listeners defined added to Runtimetest4",
                broker.getLifecycleEventManager().hasLoadListeners(
                    new RuntimeTest4("foo"),
View Full Code Here

    /**
     * Tests that the <code>Platform</code> property is set by the
     * concrete PMF implementation.
     */
    public void testPlatform() {
        OpenJPAEntityManagerFactory pmf =
            (OpenJPAEntityManagerFactory) getEmf();
        assertNotNull(pmf.getProperties().getProperty("Platform"));
    }
View Full Code Here

    private void doSerializationTest(boolean auto) throws Exception {
        enhance();
        Map props = new HashMap();
        props.put("openjpa.DetachState", "DetachedStateField=true");

        OpenJPAEntityManagerFactory factory =
            (OpenJPAEntityManagerFactory) getEmf(props);
        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) factory.createEntityManager();

        startTx(pm);
        DetachSMPC pc = new DetachSMPC();
        pc.setIntField(1);
        DetachSMPC rel = new DetachSMPC();
        rel.setIntField(2);
        pc.getRelSet().add(rel);
        pc.getStringIntMap().put("a", new Integer(99));
        pm.persist(pc);
        endTx(pm);
        Object pcoid = pm.getObjectId(pc);
        endEm(pm);

        pm = (OpenJPAEntityManager) factory.createEntityManager();
        pc = (DetachSMPC) pm.find(DetachSMPC.class, pcoid);
        pc.getRelSet();
        pc.getStringIntMap();
        if (!auto) {
            pc = (DetachSMPC) pm.detach(pc);
            assertDetachedSM(pc);
        }
        pc = (DetachSMPC) roundtrip(pc, false);
        assertDetachedSM(pc);
        endEm(pm);

        assertDetachedSM(pc);
        assertSize(1, pc.getRelSet());
        assertEquals(1, pc.getStringIntMap().size());

        pc.setIntField(3);
        ((DetachSMPC) pc.getRelSet().iterator().next()).setIntField(4);
        pc.getStringIntMap().put("b", new Integer(100));

        pc = (DetachSMPC) roundtrip(pc, false);

        assertDetachedSM(pc);
        assertEquals(3, pc.getIntField());
        assertSize(1, pc.getRelSet());
        //assertDetachedSM (b.getDs ().iterator ().next ());
        assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
            .getIntField());
        assertEquals(new Integer(100), pc.getStringIntMap().get("b"));

        pm = (OpenJPAEntityManager) factory.createEntityManager();
        startTx(pm);
        pc = (DetachSMPC) pm.merge(pc);
        assertEquals(3, pc.getIntField());
        assertSize(1, pc.getRelSet());
        assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
            .getIntField());
        assertEquals(2, pc.getStringIntMap().size());
        assertEquals(new Integer(100), pc.getStringIntMap().get("b"));
        endTx(pm);
        endEm(pm);

        pm = (OpenJPAEntityManager) factory.createEntityManager();
        pc = (DetachSMPC) pm.find(DetachSMPC.class, pcoid);
        assertEquals(3, pc.getIntField());
        assertSize(1, pc.getRelSet());
        assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
            .getIntField());
        assertEquals(2, pc.getStringIntMap().size());
        assertEquals(new Integer(100), pc.getStringIntMap().get("b"));

        startTx(pm);
        deleteAll(DetachSMPC.class, pm);
        endTx(pm);
        endEm(pm);
        factory.close();
    }
View Full Code Here

    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

    }

    public void testInitialValueMutableValueFailures() {
        Map props = new HashMap();
        props.put("openjpa.RestoreMutableValues", "false");
        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
            getEmf(props);

        OpenJPAEntityManager pm = (OpenJPAEntityManager)
            pmf.createEntityManager();
        RuntimeTest1 rt1 = getObject(pm);

        Date d = rt1.getDateField();
        OpenJPAStateManager sm = getStateManager(rt1, pm);
        FieldMetaData fmd = sm.getMetaData().getField("dateField");
        try {
            sm.fetchInitialField(fmd.getIndex());
            fail("should get an exception if RestoreMutableValues is false");
        } catch (org.apache.openjpa.util.UserException e) {
            // expected
        }
        endEm(pm);
        pmf.close();
    }
View Full Code Here

    }

    public void testInitialValueDate() {
        Map props = new HashMap();
        props.put("openjpa.RestoreState", "all");
        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
            getEmf(props);
        OpenJPAEntityManager pm = (OpenJPAEntityManager)
            pmf.createEntityManager();
        startTx(pm);
        RuntimeTest1 rt1 = getObject(pm);

        Date d = rt1.getDateField();
View Full Code Here

    public void testPerClassSequenceFactory()
        throws Exception {
        Map props=new HashMap();
        props.put("openjpa.Sequence", "table");
       
        OpenJPAEntityManagerFactory factory =(OpenJPAEntityManagerFactory)
                getEmf(props);

        JDBCConfiguration conf = (JDBCConfiguration)
            factory.getConfiguration();
        ClassMapping mapping1 = conf.getMappingRepositoryInstance().
            getMapping(RuntimeTest1.class, null, true);
        ClassMapping mapping2 = conf.getMappingRepositoryInstance().
            getMapping(PerClassTestObject.class, null, true);
        ClassMapping mapping3 = conf.getMappingRepositoryInstance().
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory

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.