Examples of OpenJPAEntityManagerFactorySPI


Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

     */
    @Override
    protected OpenJPAEntityManagerFactorySPI createNamedEMF(String pu, Object... props) {
        Map<String, Object> map = getPropertiesMap(props);
        EMFKey key = new EMFKey(pu, map);
        OpenJPAEntityManagerFactorySPI oemf = _emfs.get(key);
        if (_fresh || oemf == null || !oemf.isOpen()) {
            oemf = super.createNamedEMF(pu, props);
            if (!_fresh) {
                _emfs.put(key, oemf);
            }
        }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

    @Override
    protected OpenJPAEntityManagerFactorySPI createNamedOpenJPAEMF(String pu,
            String res, Map<String,Object> props) {
        EMFKey key = new EMFKey(pu, props);
        OpenJPAEntityManagerFactorySPI oemf = _emfs.get(key);
        if (_fresh || oemf == null || !oemf.isOpen()) {
            oemf = super.createNamedOpenJPAEMF(pu, res, props);
            if (!_fresh) {
                _emfs.put(key, oemf);
            }
        }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

   
    /**
     * Verifies the data cache metrics are available through simple instrumentation.
     */
    public void testDataCacheInstrument() {
        OpenJPAEntityManagerFactorySPI oemf = createEMF(
            "openjpa.Instrumentation", DC_PROVIDER,
            "openjpa.DataCache", "true(EnableStatistics=true)",
            "openjpa.RemoteCommitProvider", "sjvm",
            "openjpa.jdbc.SynchronizeMappings", "buildSchema",
            CacheableEntity.class);

        // Verify an EMF was created with the supplied instrumentation
        assertNotNull(oemf);

        // Verify the instrumentation value was stored in the config
        String instrValue = oemf.getConfiguration().getInstrumentation();
        assertEquals(DC_PROVIDER, instrValue);

        // Verify an instrumentation manager is available
        InstrumentationManager mgr = oemf.getConfiguration().getInstrumentationManagerInstance();
        assertNotNull(mgr);
       
        // Get the data cache instrument
        Set<InstrumentationProvider> providers = mgr.getProviders();
        assertNotNull(providers);
        assertEquals(1, providers.size());
        InstrumentationProvider provider = providers.iterator().next();
        assertEquals(provider.getClass(), SimpleProvider.class);
        Instrument inst = provider.getInstrumentByName(DCInstrument.NAME);
        assertNotNull(inst);
        assertTrue(inst instanceof DataCacheInstrument);
        DataCacheInstrument dci = (DataCacheInstrument)inst;
        assertEquals(dci.getCacheName(), "default");
       
        OpenJPAEntityManagerSPI oem = oemf.createEntityManager();
       
        CacheableEntity ce = new CacheableEntity();
        int id = new Random().nextInt();
        ce.setId(id);
       
        oem.getTransaction().begin();
        oem.persist(ce);
        oem.getTransaction().commit();
        oem.clear();
        assertTrue(oemf.getCache().contains(CacheableEntity.class, id));
        ce = oem.find(CacheableEntity.class, id);
       
        assertTrue(dci.getHitCount() > 0);
        assertTrue(dci.getReadCount() > 0);
        assertTrue(dci.getWriteCount() > 0);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

            em.close();
        }
    }
   
    public void testUpdateNoEvict(){
        OpenJPAEntityManagerFactorySPI emf = createNamedEMF(getPersistenceUnitName(), noEvictProps);
        Cache cache = emf.getCache();
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        try {
            CachedEntityStatistics e = createEntity(em);
            assertTrue(cache.contains(CachedEntityStatistics.class, e.getId()));
            em.clear();

            String update = "UPDATE CachedEntityStatistics s SET s.firstName = :name WHERE s.id = :id";
            String name = "name_" + System.currentTimeMillis();
            // execute update, this should result in a cache eviction
            em.getTransaction().begin();
            assertEquals(1, em.createQuery(update).setParameter("name", name).setParameter("id", e.getId())
                .executeUpdate());
            em.getTransaction().commit();
            assertTrue(cache.contains(CachedEntityStatistics.class, e.getId()));

            CachedEntityStatistics postUpdate = em.find(CachedEntityStatistics.class, e.getId());
            assertNotEquals(name, postUpdate.getFirstName());
        }finally{
            emf.close();
        }
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

    private static class FixedMap<K, V> extends LinkedHashMap<K, V> {
        private static final long serialVersionUID = -3153852097468390779L;

        @Override
        protected boolean removeEldestEntry(Map.Entry<K,V> entry) {
            OpenJPAEntityManagerFactorySPI oemf = (OpenJPAEntityManagerFactorySPI)entry.getValue();
            if (this.size() > 2) {
                // if the eldest should be removed, then try to close it first
                if (oemf != null && oemf.isOpen()) {
                    try {
                        // same code as AbstractPersistenceTestCase.closeAllOpenEMs()
                        for (Broker b:((AbstractBrokerFactory)JPAFacadeHelper.toBrokerFactory(oemf)).getOpenBrokers()) {
                            if (b != null && !b.isClosed()) {
                                EntityManager em = JPAFacadeHelper.toEntityManager(b);
                                if (em == null || !em.isOpen()) {
                                    continue;
                                }
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                em.close();
                            }
                        }
                        oemf.close();
                    } catch (Exception e) {
                        // no-op - eat it
                    }
                }
                return true;
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

    /**
     * Verifies multiple instrumentation providers can be specified.
     */
    public void testMultipleProviderConfig() {
        OpenJPAEntityManagerFactorySPI oemf = createEMF(
            "openjpa.Instrumentation",
            MULTI_PROVIDER,
            "openjpa.DataCache",
            "true(EnableStatistics=true)",
            "openjpa.QueryCache",
            "true",
            "openjpa.RemoteCommitProvider",
            "sjvm");
       
        // Verify an EMF was created with the supplied instrumentation
        assertNotNull(oemf);

        // Verify the instrumentation value was stored in the config
        String instrValue = oemf.getConfiguration().getInstrumentation();
        assertEquals(MULTI_PROVIDER, instrValue);

        // Verify an instrumentation manager is available
        InstrumentationManager mgr = oemf.getConfiguration().getInstrumentationManagerInstance();
        assertNotNull(mgr);
       
        // Verify the manager is managing the correct provider
        Set<InstrumentationProvider> providers = mgr.getProviders();
        assertNotNull(providers);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

            emf.close();
        }
    }

    public void testDeleteNoEvict() throws Exception {
        OpenJPAEntityManagerFactorySPI emf = createNamedEMF(getPersistenceUnitName(), noEvictProps);
        Cache cache = emf.getCache();
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        try {
            CachedEntityStatistics e = createEntity(em);
            assertTrue(cache.contains(CachedEntityStatistics.class, e.getId()));
            em.clear();
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

  public void setUp() throws Exception {
    super.setUp(PObject.class);
  }
 
    public void testConfigurationIsEqualByValueAndHashCode() {
    OpenJPAEntityManagerFactorySPI emf1 = createEMF(FRESH_EMF);
    assertNotNull(emf1);
    OpenJPAConfiguration conf1 = emf1.getConfiguration();
   
    OpenJPAEntityManagerFactorySPI emf2 = createEMF(FRESH_EMF);
    assertNotNull(emf2);
    OpenJPAConfiguration conf2 = emf2.getConfiguration();
   
    try {
          assertFalse(emf1==emf2);
          assertFalse(emf1.equals(emf2));
          assertFalse(conf1==conf2);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

        assertTrue(spec.isSame("JPA"));
    }

    public void testSpecificationVersionIsJPA2() {
       
        OpenJPAEntityManagerFactorySPI emf1 = null;
        try {
          emf1 =
            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
            createEntityManagerFactory("persistence2_0",
            "org/apache/openjpa/conf/META-INF/" +
            "persistence-2_0-config.xml");

            Specification spec = emf1.getConfiguration().getSpecificationInstance();
            int major = spec.getVersion();
            assertEquals(2, major);
            assertTrue(spec.isSame("JPA"));
        } finally {
            clear(emf1);
View Full Code Here

Examples of org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI

    protected ClassMapping [] getMappings() {
        return (ClassMapping [] ) emf.getConfiguration().getMetaDataRepositoryInstance().getMetaDatas();  
    }
   
    protected void setUnsupportedDatabases(Class<?> ... dbs) {
        OpenJPAEntityManagerFactorySPI tempEMF = emf;
        if (tempEMF == null) {
            tempEMF = createEMF();
        }
        DBDictionary dict = ((JDBCConfiguration)tempEMF.getConfiguration()).getDBDictionaryInstance();
        for (Class<?> db : dbs) {
            if (dict.getClass().getCanonicalName().equalsIgnoreCase(db.getCanonicalName())) {
                setTestsDisabled(true);
                break;
            }
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.