Package javax.persistence

Examples of javax.persistence.Cache


        };

        OperationStepHandler evictAllHandler = new AbstractMetricsHandler() {
            @Override
            void handle(final ModelNode response, final String name, ManagementLookup stats, OperationContext context) {
                Cache secondLevelCache = stats.getEntityManagerFactory().getCache();
                if (secondLevelCache != null) {
                    secondLevelCache.evictAll();
                }
            }
        };
        jpaHibernateRegistration.registerOperationHandler(OPERATION_EVICTALL, evictAllHandler, evictAll);
View Full Code Here


        };

        OperationStepHandler evictAllHandler = new AbstractMetricsHandler() {
            @Override
            void handle(final ModelNode response, final String name, ManagementLookup stats, OperationContext context) {
                Cache secondLevelCache = stats.getEntityManagerFactory().getCache();
                if (secondLevelCache != null) {
                    secondLevelCache.evictAll();
                }
            }
        };
        jpaHibernateRegistration.registerOperationHandler(OPERATION_EVICTALL, evictAllHandler, evictAll);
View Full Code Here

    em.persist(address);
    tx.commit();

    assertNotNull(address.getId());

    Cache cache = emf.getCache();

    // Address should not be in the cache
    assertFalse(cache.contains(Address34.class, address.getId()));
  }
View Full Code Here

    em.persist(customer);
    tx.commit();

    assertNotNull(customer.getId());

    Cache cache = emf.getCache();

    // Customer should be in the cache
    assertTrue(cache.contains(Customer34.class, customer.getId()));

    cache.evict(Customer34.class);

    // After clearing the cache Customer should not be in the cache
    assertFalse(cache.contains(Customer34.class, customer.getId()));
  }
View Full Code Here

    em.persist(book);
    tx.commit();

    assertNotNull(book.getId());

    Cache cache = emf.getCache();

    // Customer should not be in the cache by default
    assertFalse(cache.contains(Customer34.class, book.getId()));
  }
View Full Code Here

     * This test ensures that after executing an update against the db, the updated type is purged from
     * the DataCache.
     */
    public void testUpdate() throws Exception {
        EntityManager em = emf.createEntityManager();
        Cache cache = emf.getCache();
        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();
            assertFalse(cache.contains(CachedEntityStatistics.class, e.getId()));

            CachedEntityStatistics postUpdate = em.find(CachedEntityStatistics.class, e.getId());
            assertEquals(name, postUpdate.getFirstName());

        } finally {
View Full Code Here

     * This test ensures that after executing a delete against the db, the deleted type is purged from
     * the DataCache.
     */
    public void testDelete() throws Exception {
        EntityManager em = emf.createEntityManager();
        Cache cache = emf.getCache();
        try {
            CachedEntityStatistics e = createEntity(em);
            assertTrue(cache.contains(CachedEntityStatistics.class, e.getId()));
            em.clear();

            String delete = "DELETE FROM CachedEntityStatistics s WHERE s.id = :id";
            // execute update, this should result in a cache eviction
            em.getTransaction().begin();
            assertEquals(1, em.createQuery(delete).setParameter("id", e.getId()).executeUpdate());
            em.getTransaction().commit();
            assertFalse(cache.contains(CachedEntityStatistics.class, e.getId()));

            CachedEntityStatistics postUpdate = em.find(CachedEntityStatistics.class, e.getId());
            assertNull(postUpdate);

        } finally {
View Full Code Here

        }
    }
   
    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

        }
    }

    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();

            String delete = "DELETE FROM CachedEntityStatistics s WHERE s.id = :id";
            // execute update, this should NOT result in a cache eviction
            em.getTransaction().begin();
            assertEquals(1, em.createQuery(delete).setParameter("id", e.getId()).executeUpdate());
            em.getTransaction().commit();
            assertTrue(cache.contains(CachedEntityStatistics.class, e.getId()));

            em.clear();
           
            CachedEntityStatistics postUpdate = em.find(CachedEntityStatistics.class, e.getId());
            assertNotNull(postUpdate);
View Full Code Here

    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();
    }
  }
View Full Code Here

TOP

Related Classes of javax.persistence.Cache

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.