Java Examples for javax.persistence.Cache

The following java examples will help you to understand the usage of javax.persistence.Cache. These source code samples are taken from different open source projects.

Example 1
Project: fb-contrib-master  File: SJVU_Sample.java View source code
public void fpExternalJavax() {
    Cache c = new Cache() {

        @Override
        public boolean contains(Class arg0, Object arg1) {
            return false;
        }

        @Override
        public void evict(Class arg0, Object arg1) {
        }

        @Override
        public void evict(Class arg0) {
        }

        @Override
        public void evictAll() {
        }

        @Override
        public <T> T unwrap(Class<T> arg0) {
            return null;
        }
    };
}
Example 2
Project: openjpa-master  File: TestUpdateSingleValuedAssociation.java View source code
public void updateByQuery(String jpql, Object... params) {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Query query = em.createQuery(jpql);
    for (int i = 0; params != null && i < params.length; i = +2) {
        query.setParameter(params[i].toString(), params[i + 1]);
    }
    query.executeUpdate();
    em.getTransaction().commit();
    Cache cache = emf.getCache();
    if (cache != null) {
        cache.evictAll();
    }
}
Example 3
Project: saos-master  File: SecondLevelCacheTest.java View source code
@Test
public void test() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evictAll();
    Statistics statistics = ((Session) (entityManager.getDelegate())).getSessionFactory().getStatistics();
    statistics.clear();
    CommonCourt commonCourt = testPersistenceObjectFactory.createCcCourt(CommonCourtType.APPEAL);
    commonCourtRepository.findOne(commonCourt.getId());
    commonCourtRepository.findOne(commonCourt.getId());
    Assert.assertTrue(cache.contains(CommonCourt.class, commonCourt.getId()));
    Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
    Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));
    cache.evict(CommonCourt.class);
    cache.evict(CommonCourtDivision.class);
    Assert.assertFalse(cache.contains(CommonCourt.class, commonCourt.getId()));
    Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
    Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));
    // 1 commonCourt + 2 ccDivision + 2 ccDivisionType
    Assert.assertEquals(5, statistics.getSecondLevelCachePutCount());
    Assert.assertEquals(2, statistics.getSecondLevelCacheHitCount());
    Assert.assertEquals(0, statistics.getSecondLevelCacheMissCount());
}
Example 4
Project: transgalactica-master  File: CacheTest.java View source code
@Test
public void testCacheMecanicienSpecialiteEntity() {
    Cache l2 = emf.getCache();
    EntityManager em = emf.createEntityManager();
    assertFalse(l2.contains(JpaMecanicienSpecialiteEntity.class, 1L));
    // Mise en cache L2 sur find.
    JpaMecanicienSpecialiteEntity e1 = em.find(JpaMecanicienSpecialiteEntity.class, 1L);
    assertTrue(l2.contains(JpaMecanicienSpecialiteEntity.class, 1L));
    JpaMecanicienSpecialiteEntity e2 = em.find(JpaMecanicienSpecialiteEntity.class, 1L);
    assertSame(e1, e2);
    EntityManager em2 = emf.createEntityManager();
    JpaMecanicienSpecialiteEntity e3 = em2.find(JpaMecanicienSpecialiteEntity.class, 1L);
    // Pourquoi le L2 ne renvoi pas les même
    assertNotSame(e1, e3);
    // instance?
    assertEquals(e1, e3);
}
Example 5
Project: hibernate4-memcached-master  File: QueryCacheTest.java View source code
@Test
public void createQueryCacheAndEvictAllThenRetry() throws Exception {
    List<Author> beforeResults = getAuthorsWithQuery("Author query", "어�나�");
    log.warn("#####################################################################");
    HibernateEntityManagerFactory entityManagerFactory = (HibernateEntityManagerFactory) EntityTestUtils.getEntityManagerFactory();
    org.hibernate.Cache cache = entityManagerFactory.getSessionFactory().getCache();
    cache.evictEntityRegions();
    cache.evictQueryRegions();
    cache.evictDefaultQueryRegion();
    cache.evictCollectionRegions();
    log.warn("just eviected all.");
    List<Author> againResults = getAuthorsWithQuery("Author query again after evict all", "어�나�");
    assertThat(againResults).isEqualTo(beforeResults);
    log.warn("#####################################################################");
}
Example 6
Project: skysail-server-ext-master  File: SkysailServerExtJenkinsOsgiIT.java View source code
@Test
public void a() {
    ComponentProvider dummyComponentProvider = new ComponentProvider() {

        @Override
        public Component getComponent() {
            return new Component();
        }

        @Override
        public Verifier getVerifier() {
            return Mockito.mock(Verifier.class);
        }
    };
    EntityManagerFactory dummyEmf = new EntityManagerFactory() {

        @Override
        public EntityManager createEntityManager() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EntityManager createEntityManager(Map map) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public CriteriaBuilder getCriteriaBuilder() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Metamodel getMetamodel() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isOpen() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void close() {
        // TODO Auto-generated method stub
        }

        @Override
        public Map<String, Object> getProperties() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Cache getCache() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public PersistenceUnitUtil getPersistenceUnitUtil() {
            // TODO Auto-generated method stub
            return null;
        }
    };
    // Mockito.mock(EntityManagerFactory.class);
    // provide the required services, so that the configuration constraints are fulfilled.
    context.registerService(ComponentProvider.class.getName(), dummyComponentProvider, null);
    Dictionary props = new Hashtable();
    props.put("osgi.unit.name", "JenkinsPU");
    context.registerService(EntityManagerFactory.class.getName(), dummyEmf, props);
    // check the service which should have been created by the configuration
    ServiceReference serviceReference = context.getServiceReference(ApplicationProvider.class.getName());
    // assertThat(serviceReference, is(notNullValue()));
    ApplicationProvider service = (ApplicationProvider) context.getService(serviceReference);
    Application applicationFromService = service.getApplication();
    assertTrue(applicationFromService.getName().equals("jenkins"));
}
Example 7
Project: cointrader-master  File: PersistUtil.java View source code
public static boolean cached(EntityBase... entities) {
    EntityManager em = null;
    boolean cached = false;
    try {
        for (EntityBase entity : entities) {
            Cache cache = PersistUtilHelper.getEntityManagerFactory().getCache();
            cached = cache.contains(entity.getClass(), entity.getId());
        }
    } catch (ExceptionError |  e) {
        log.error("Threw a Execpton or Error, full stack trace follows:", e);
    }
    return cached;
}
Example 8
Project: guiceyfruit-master  File: InjectionTest.java View source code
@Override
protected void configure() {
    super.configure();
    // TODO this should be the hibernate implementation
    bind(EntityManagerFactory.class).toInstance(new EntityManagerFactory() {

        boolean open = true;

        public CriteriaBuilder getCriteriaBuilder() {
            return null;
        }

        public Metamodel getMetamodel() {
            return null;
        }

        public Map<String, Object> getProperties() {
            return null;
        }

        public Cache getCache() {
            return null;
        }

        public PersistenceUnitUtil getPersistenceUnitUtil() {
            return null;
        }

        public EntityManager createEntityManager() {
            return stubEntityManager;
        }

        public EntityManager createEntityManager(Map map) {
            return stubEntityManager;
        }

        public void close() {
            open = false;
        }

        public boolean isOpen() {
            return open;
        }
    });
}
Example 9
Project: cloud-odata-java-master  File: JPQLBuilderFactoryTest.java View source code
@Test
public void testJPAAccessFactory() {
    ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
    JPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getJPAAccessFactory();
    ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
    Class<?> clazz = oDataJPAContextImpl.getClass();
    try {
        Field field = clazz.getDeclaredField("em");
        field.setAccessible(true);
        field.set(oDataJPAContextImpl, new JPAProcessorImplTest().getLocalEntityManager());
    } catch (SecurityException e) {
        fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    } catch (NoSuchFieldException e) {
        fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    } catch (IllegalArgumentException e) {
        fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    } catch (IllegalAccessException e) {
        fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    }
    EntityManagerFactory emf = new EntityManagerFactory() {

        @Override
        public boolean isOpen() {
            return false;
        }

        @Override
        public Map<String, Object> getProperties() {
            return null;
        }

        @Override
        public PersistenceUnitUtil getPersistenceUnitUtil() {
            return null;
        }

        @Override
        public Metamodel getMetamodel() {
            return null;
        }

        @Override
        public CriteriaBuilder getCriteriaBuilder() {
            return null;
        }

        @Override
        public Cache getCache() {
            return null;
        }

        @SuppressWarnings("rawtypes")
        @Override
        public EntityManager createEntityManager(final Map arg0) {
            return null;
        }

        @Override
        public EntityManager createEntityManager() {
            return null;
        }

        @Override
        public void close() {
        }
    };
    oDataJPAContextImpl.setEntityManagerFactory(emf);
    oDataJPAContextImpl.setPersistenceUnitName("pUnit");
    assertNotNull(jpaAccessFactory.getJPAProcessor(oDataJPAContextImpl));
    assertNotNull(jpaAccessFactory.getJPAEdmModelView(oDataJPAContextImpl));
}
Example 10
Project: eclipselink.runtime-master  File: CacheableModelJunitTest.java View source code
public void testEmbeddableProtectedCaching() {
    EntityManager em = createDSEntityManager();
    beginTransaction(em);
    try {
        ForceProtectedEntityWithComposite cte = em.find(ForceProtectedEntityWithComposite.class, m_forcedProtectedEntityCompositId);
        CacheableRelationshipsEntity cre = em.find(CacheableRelationshipsEntity.class, m_cacheableRelationshipsEntityId);
        ProtectedEmbeddable pe = cte.getProtectedEmbeddable();
        ServerSession session = em.unwrap(ServerSession.class);
        commitTransaction(em);
        closeEM(em);
        ForceProtectedEntityWithComposite cachedCPE = (ForceProtectedEntityWithComposite) session.getIdentityMapAccessor().getFromIdentityMap(cte);
        CacheableRelationshipsEntity cachedCRE = (CacheableRelationshipsEntity) session.getIdentityMapAccessor().getFromIdentityMap(cre);
        assertNotNull("ForceProtectedEntityWithComposite was not found in the cache", cachedCPE);
        assertNotNull("CacheableRelationshipsEntity was not found in the cache", cachedCRE);
        cachedCPE.getProtectedEmbeddable().setName("NewName" + System.currentTimeMillis());
        //following code is commented out due to bug 336651
        //cachedCRE.getProtectedEmbeddables().get(0).setName("NewName"+System.currentTimeMillis());
        em = createDSEntityManager();
        beginTransaction(em);
        ForceProtectedEntityWithComposite managedCPE = em.find(ForceProtectedEntityWithComposite.class, cte.getId());
        CacheableRelationshipsEntity managedCRE = em.find(CacheableRelationshipsEntity.class, cre.getId());
        assertEquals("Cache was not used for Protected Isolation", cachedCPE.getProtectedEmbeddable().getName(), managedCPE.getProtectedEmbeddable().getName());
    //follwoing code is commented out due to bug 336651
    //assertEquals("Cache was not used for Protected Isolation", cachedCRE.getProtectedEmbeddables().get(0).getName(),managedCRE.getProtectedEmbeddables().get(0).getName());
    } finally {
        rollbackTransaction(em);
        closeEM(em);
    }
}
Example 11
Project: ambari-master  File: UpgradeCatalog300Test.java View source code
/**
   * Tests pre-DML executions.
   *
   * @throws Exception
   */
@Test
public void testExecutePreDMLUpdates() throws Exception {
    Module module = new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(DBAccessor.class).toInstance(dbAccessor);
            binder.bind(OsFamily.class).toInstance(osFamily);
            binder.bind(EntityManager.class).toInstance(entityManager);
            binder.bind(Configuration.class).toInstance(configuration);
        }
    };
    EntityManagerFactory emFactory = EasyMock.createNiceMock(EntityManagerFactory.class);
    Cache emCache = EasyMock.createNiceMock(Cache.class);
    expect(entityManager.getEntityManagerFactory()).andReturn(emFactory).atLeastOnce();
    expect(emFactory.getCache()).andReturn(emCache).atLeastOnce();
    EntityTransaction mockTransaction = EasyMock.createNiceMock(EntityTransaction.class);
    Connection mockConnection = EasyMock.createNiceMock(Connection.class);
    Statement mockStatement = EasyMock.createNiceMock(Statement.class);
    expect(dbAccessor.getConnection()).andReturn(mockConnection).once();
    expect(mockConnection.createStatement()).andReturn(mockStatement).once();
    expect(mockStatement.executeQuery(EasyMock.anyString())).andReturn(EasyMock.createNiceMock(ResultSet.class));
    expect(entityManager.getTransaction()).andReturn(mockTransaction).atLeastOnce();
    dbAccessor.dropTable(UpgradeCatalog300.CLUSTER_CONFIG_MAPPING_TABLE);
    EasyMock.expectLastCall().once();
    replay(dbAccessor, entityManager, emFactory, emCache, mockConnection, mockTransaction, mockStatement, configuration);
    Injector injector = Guice.createInjector(module);
    UpgradeCatalog300 upgradeCatalog300 = injector.getInstance(UpgradeCatalog300.class);
    upgradeCatalog300.executePreDMLUpdates();
    verify(dbAccessor, entityManager, emFactory, emCache);
}
Example 12
Project: mct-master  File: PersistenceServiceImpl.java View source code
private void cleanCacheIfNecessary(String componentId, int latestVersion) {
    Cache c = entityManagerFactory.getCache();
    if (c.contains(ComponentSpec.class, componentId)) {
        EntityManager em = entityManagerFactory.createEntityManager();
        ComponentSpec cs = em.find(ComponentSpec.class, componentId);
        if (cs != null && cs.getObjVersion() < latestVersion) {
            c.evict(ComponentSpec.class, componentId);
        }
        em.close();
    }
}
Example 13
Project: openolat-master  File: DBImpl.java View source code
@Override
public EmbeddedCacheManager getCacheContainer() {
    EmbeddedCacheManager cm;
    try {
        Cache cache = emf.getCache();
        JpaInfinispanRegionFactory region = cache.unwrap(JpaInfinispanRegionFactory.class);
        cm = region.getCacheManager();
    } catch (Exception e) {
        log.error("", e);
        cm = null;
    }
    return cm;
}
Example 14
Project: raidenjpa-master  File: RaidenEntityManagerFactory.java View source code
public Cache getCache() {
    throw new NoPlansToImplementException();
}
Example 15
Project: arquillian-extension-persistence-master  File: FullCacheEvictionStrategy.java View source code
/**
     * @see org.jboss.arquillian.persistence.JpaCacheEvictionStrategy#evictCache(javax.persistence.EntityManagerFactory)
     */
@Override
public final void evictCache(EntityManager em) {
    final Cache cache = em.getEntityManagerFactory().getCache();
    if (cache != null) {
        cache.evictAll();
    }
}
Example 16
Project: hector-master  File: EntityManagerFactoryImpl.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 17
Project: strongbox-master  File: OJPAPartitionedEntityManagerPool.java View source code
@Override
public Cache getCache() {
    throw new UnsupportedOperationException("getCache");
}
Example 18
Project: tapestry-5-master  File: DummyEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 19
Project: beanlet-master  File: InternalEntityManagerFactory.java View source code
public Cache getCache() {
    return emf.getCache();
}
Example 20
Project: capedwarf-green-master  File: Lazy2EntityManagerFactory.java View source code
public Cache getCache() {
    return getDelegate().getCache();
}
Example 21
Project: cloudtm-data-platform-master  File: OgmEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return hibernateEmf.getCache();
}
Example 22
Project: droolsjbpm-integration-master  File: MockEntityManager.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 23
Project: fakereplace-master  File: WildflyEntityManagerFactoryProxy.java View source code
@Override
public Cache getCache() {
    return unwrap().getCache();
}
Example 24
Project: jboss-jpa-master  File: AbstractEntityManagerFactoryDelegator.java View source code
public Cache getCache() {
    return getDelegate().getCache();
}
Example 25
Project: orientdb-master  File: OJPAEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    throw new UnsupportedOperationException("getCache");
}
Example 26
Project: spearal-jpa2-master  File: EntityManagerFactoryWrapper.java View source code
public Cache getCache() {
    return entityManagerFactory.getCache();
}
Example 27
Project: deltaspike-master  File: TestPersistenceProviderResolver.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 28
Project: ef-orm-master  File: JefEntityManagerFactory.java View source code
public Cache getCache() {
    return CacheDummy.getInstance();
}
Example 29
Project: hibernate-ogm-master  File: OgmEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return hibernateEmf.getCache();
}
Example 30
Project: hibernate-ogm-old-master  File: OgmEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return hibernateEmf.getCache();
}
Example 31
Project: palava-jpa-master  File: DefaultPersistenceService.java View source code
@Override
public Cache getCache() {
    return factory.getCache();
}
Example 32
Project: resin-master  File: AmberEntityManagerFactory.java View source code
/**
   * Returns the entity manager cache
   *
   * @since JPA 2.0
   */
public Cache getCache() {
    throw new UnsupportedOperationException(getClass().getName());
}
Example 33
Project: hexa.tools-master  File: EntityManagerFactoryImpl.java View source code
@Override
public Cache getCache() {
    assert false;
    return null;
}
Example 34
Project: jboss-seam-2.3.0.Final-Hibernate.3-master  File: SeamManagedEntityManagerFactory.java View source code
public Cache getCache() {
    // TODO Auto-generated method stub
    return null;
}
Example 35
Project: seam2jsf2-master  File: SeamManagedEntityManagerFactory.java View source code
public Cache getCache() {
    return getEntityManagerFactory().getCache();
}
Example 36
Project: bundles-master  File: DelegatedEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return emf.getCache();
}
Example 37
Project: glassfish-main-master  File: EntityManagerFactoryWrapper.java View source code
@Override
public Cache getCache() {
    return getDelegate().getCache();
}
Example 38
Project: glassfish-master  File: EntityManagerFactoryWrapper.java View source code
@Override
public Cache getCache() {
    return getDelegate().getCache();
}
Example 39
Project: helium-master  File: EntityManagerFactoryImpl.java View source code
public Cache getCache() {
    // TODO : cache the cache reference?
    if (!isOpen()) {
        throw new IllegalStateException("EntityManagerFactory is closed");
    }
    return new JPACache(sessionFactory);
}
Example 40
Project: hibernate-core-ogm-master  File: EntityManagerFactoryImpl.java View source code
public Cache getCache() {
    // TODO : cache the cache reference?
    if (!isOpen()) {
        throw new IllegalStateException("EntityManagerFactory is closed");
    }
    return new JPACache(sessionFactory);
}
Example 41
Project: osgi.enroute-master  File: DelegatedEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return emf.getCache();
}
Example 42
Project: Payara-master  File: EntityManagerFactoryWrapper.java View source code
@Override
public Cache getCache() {
    return getDelegate().getCache();
}
Example 43
Project: clinic-softacad-master  File: EntityManagerFactoryImpl.java View source code
public Cache getCache() {
    // TODO : cache the cache reference?
    if (!isOpen()) {
        throw new IllegalStateException("EntityManagerFactory is closed");
    }
    return new JPACache(sessionFactory);
}
Example 44
Project: olingo-odata2-master  File: JPQLBuilderFactoryTest.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 45
Project: skalli-master  File: EntityManagerServiceImplTest.java View source code
@Override
public Cache getCache() {
    return null;
}
Example 46
Project: BatooJPA-master  File: EntityManagerFactoryImpl.java View source code
/**
	 * {@inheritDoc}
	 * 
	 */
@Override
public Cache getCache() {
    return null;
}
Example 47
Project: jipijapa-master  File: HibernateStatistics.java View source code
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}
Example 48
Project: tomee-master  File: ReloadableEntityManagerFactory.java View source code
@Override
public Cache getCache() {
    return delegate().getCache();
}
Example 49
Project: wildfly-master  File: HibernateStatistics.java View source code
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}