Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactory


     * Pass in 4 out of 5 tokens.
     */
    private void doTest(String valid, String invalid)
        throws Exception {

        OpenJPAEntityManagerFactory emf =
            (OpenJPAEntityManagerFactory) getEmf();
        OpenJPAConfiguration conf =
            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf))
                .getConfiguration();

View Full Code Here


    }

    public void coreTestTransAndChange(ChangeOperation changeOperation,
        boolean asLargeTransaction, boolean isDelete) {
        // Create two pmfs in a cluster that are using RCPTCP.
        OpenJPAEntityManagerFactory pmfSender = createDistinctFactory(
            TCPRemoteCommitProvider.class,
            "Port=5636, Addresses=127.0.0.1:6636");
        OpenJPAEntityManagerFactory pmfReceiver = createDistinctFactory(
            TCPRemoteCommitProvider.class,
            "Port=6636, Addresses=127.0.0.1:5636");
        // Get the datacaches from each pmf
        DataCache dcSender =
            ((OpenJPAEntityManagerFactorySPI) pmfSender).getConfiguration()
                .getDataCacheManagerInstance().getSystemDataCache();
        DataCache dcReceiver =
            ((OpenJPAEntityManagerFactorySPI) pmfReceiver).getConfiguration()
                .getDataCacheManagerInstance().getSystemDataCache();

        deleteAll(RuntimeTest1.class);
        deleteAll(RuntimeTest2.class);

        _runtime1sOids = null;
        _runtime2sOids = null;

        String transType = "normal";
        String rcpType = "OIDs";
        if (asLargeTransaction) {
            transType = "large";
            rcpType = "classes";
        }
        System.out.println("-------------------");
        System.out
            .println(
                "2 PMFs created, acting as a cluster using ports 5636 and 6636");
        System.out.println("Testing scenario:");
        System.out
            .println("  1 Seed datastore with instances of RuntimeTest1 AND "
                + "RuntimeTest2 objs.\n"
                + "  2 pmf2 fills its cache with both sets of objs.\n"
                + "  3 pmf1 does a "
                + transType
                + " tx that invokes an operation of "
                + changeOperation.getName()
                + " to affect a single Runtime1 \n"
                + "    assert that both pmf1 and pmf2's data caches dropped all"
                + "Runtime1s");
        System.out.println("Remote commit event is transmiting " + rcpType);

        // Create runtimes1s and 2s.
        // Noraml transaction
        OpenJPAEntityManager pmSender = (OpenJPAEntityManager) pmfSender
            .createEntityManager();
        seedDataStore(pmSender, NUM_OBJECTS);
        endEm(pmSender);

        // wait a bit so they get stored
        pause(1);

        OpenJPAEntityManager pm2;
        pm2 = (OpenJPAEntityManager) pmfReceiver.createEntityManager();
        performLoadAll(pm2);
        endEm(pm2);

        pmSender = (OpenJPAEntityManager) pmfSender.createEntityManager();
        performLoadAll(pmSender);
        endEm(pmSender);

        // assert that pmf2's data cache now has all the Runtime1 and 2s.
        for (int i = 0; i < _runtime1sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }

        // Modify or delete exactly 1 RuntimeTest1 object during a
        // largeTransaction
        changeOperation.operation(pmfSender, asLargeTransaction);

        // assert that pmf1's data cache now only has Runtime2 objects
        if (asLargeTransaction) {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                assertFalse(dcSender.contains(
                    Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
            }
        } else {
            // Normal transaction
            for (int i = 0; i < _runtime1sOids.length; i++) {
                if (isDelete && i == 0) {
                    assertFalse(dcSender.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                } else {
                    // modified the first elemnt, which just updated it.
                    // (for Kodo's data cache).
                    assertTrue(dcSender.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                }
            }
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcSender.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }
        // wait a tiny bit so the rce propagates
        pause(2);
        // assert the pmf2's data cache also now only has Runtime2 objects
        if (asLargeTransaction) {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                assertFalse(dcReceiver.contains(Id.newInstance(
                    RuntimeTest1.class, _runtime1sOids[i]))); //failing here
            }
        } else {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                if (i == 0) {
                    assertFalse(dcReceiver.contains(Id.newInstance(
                        RuntimeTest1.class,
                        _runtime1sOids[i])))//failing here
                } else {
                    assertTrue(dcReceiver.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                }
            }
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }

        // shutdown
        pmfSender.close();
        pmfReceiver.close();
    }
View Full Code Here

    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

      super(name);
    }
   
    public void DBMetadataTest()
    throws Exception {
        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
        getEmf();
        //FIXME jthomas
       
        //ClassMapping cm = (ClassMapping) KodoJDOHelper.getMetaData
        //    (pmf, RuntimeTest1.class);
View Full Code Here

            System.out.println("### " + columns[i].getName());
    }
   
    public void testSchemaGen()
    throws Exception {
        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
        getEmf();
        OpenJPAEntityManager pm = pmf.createEntityManager();
        JDBCConfiguration con = (JDBCConfiguration) ((OpenJPAEntityManagerSPI) pm).getConfiguration();
        DBDictionary dict = con.getDBDictionaryInstance();
        MappingRepository repos = con.getMappingRepositoryInstance();
        ClassMapping cm = repos.getMapping(RuntimeTest1.class,
                pm.getClassLoader(), true);
        String schemas = cm.getTable().getSchema().getName();
        if (schemas == null)
            schemas = "";
        schemas += "." + cm.getTable().getName();
       
        Map props=new HashMap();
        props.put("openjpa.jdbc.Schemas", schemas);
       
        OpenJPAEntityManagerFactory kpmf =(OpenJPAEntityManagerFactory)
                getEmf(props);
        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) kpmf).getConfiguration();
       
        StringWriter sw = new StringWriter();
       
View Full Code Here

    public void doCleanUpTest(boolean commit) {
        Map props = new HashMap();
        props.put("openjpa.SavepointManager",
            TrackingSavepointManager.class.getName());
        OpenJPAEntityManagerFactory pmf = getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();
        startTx(pm);
        pm.setSavepoint("test");
        pm.setSavepoint("test2");
        if (commit)
            endTx(pm);
View Full Code Here

    private void doOrderingTest(boolean rollback) {
        Map props = new HashMap();
        props.put("openjpa.SavepointManager",
            TrackingSavepointManager.class.getName());
        OpenJPAEntityManagerFactory pmf = getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();
        startTx(pm);
        pm.setSavepoint("before");
        pm.setSavepoint("before2");
        pm.setSavepoint("test");
        pm.setSavepoint("test2");
View Full Code Here

    public void testDisallowFlush() {
        Map props = new HashMap();
        props.put("openjpa.SavepointManager",
            TrackingSavepointManager.class.getName() + "(AllowFlush=false)");
        OpenJPAEntityManagerFactory pmf = getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();
        startTx(pm);
        pm.persist(new RuntimeTest1());
        pm.setSavepoint("a");
        try {
            pm.flush();
View Full Code Here

    public void testDisallowFlush2() {
        Map props = new HashMap();
        props.put("openjpa.SavepointManager",
            TrackingSavepointManager.class.getName() + "(AllowFlush=false)");
        OpenJPAEntityManagerFactory pmf = getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();

        startTx(pm);
        pm.persist(new RuntimeTest1());
        pm.flush();
        try {
View Full Code Here

    public void testAllowFlush() {
        Map props = new HashMap();
        props.put("openjpa.SavepointManager",
            TrackingSavepointManager.class.getName() + "(AllowFlush=true)");
        OpenJPAEntityManagerFactory pmf = getEmf(props);
        OpenJPAEntityManager pm = pmf.createEntityManager();

        startTx(pm);
        pm.persist(new RuntimeTest1());
        pm.setSavepoint("a");
        try {
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.