Package org.hibernate.stat

Examples of org.hibernate.stat.SecondLevelCacheStatistics


   public void testEmptySecondLevelCacheEntry() throws Exception {
      getSessions().getCache().evictEntityRegion(Item.class.getName());
      Statistics stats = getSessions().getStatistics();
      stats.clear();
      SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
      Map cacheEntries = statistics.getEntries();
      assertEquals(0, cacheEntries.size());
   }
View Full Code Here


      try {
         s = openSession();
         s.beginTransaction();
         Statistics stats = s.getSessionFactory().getStatistics();
         SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
         Item loadedWithCachedCollection = (Item) s.load(Item.class, item.getId());
         stats.logSummary();
         assertEquals(item.getName(), loadedWithCachedCollection.getName());
         assertEquals(item.getItems().size(), loadedWithCachedCollection.getItems().size());
         assertEquals(1, cStats.getHitCount());
         Map cacheEntries = cStats.getEntries();
         assertEquals(1, cacheEntries.size());
      } catch (Exception e) {
         log.error("Exception", e);
         s.getTransaction().rollback();
         throw e;
View Full Code Here

   public void testEmptySecondLevelCacheEntry() throws Exception {
      getSessions().getCache().evictEntityRegion(Item.class.getName());
      Statistics stats = getSessions().getStatistics();
      stats.clear();
      SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
      Map cacheEntries = statistics.getEntries();
      assertEquals(0, cacheEntries.size());
   }
View Full Code Here

    i.setDescription("A really top-quality, full-featured widget.");
    s.persist(i);
    t.commit();
    s.close();

    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
        .getSecondLevelCacheStatistics( Item.class.getName() );

    assertEquals( slcs.getPutCount(), 1 );
    assertEquals( slcs.getElementCountInMemory(), 1 );
    assertEquals( slcs.getEntries().size(), 1 );

    s = openSession();
    t = s.beginTransaction();
    i = (Item) s.get( Item.class, i.getId() );

    assertEquals( slcs.getHitCount(), 1 );
    assertEquals( slcs.getMissCount(), 0 );

    i.setDescription("A bog standard item");

    t.commit();
    s.close();

    assertEquals( slcs.getPutCount(), 2 );

    Object entry = slcs.getEntries().get( i.getId() );
    Map map;
    if ( entry instanceof ReadWriteCache.Item ) {
      map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
    }
    else {
View Full Code Here

  public void testEmptySecondLevelCacheEntry() throws Exception {
    getSessions().evictEntity( Item.class.getName() );
    Statistics stats = getSessions().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() );
        Map cacheEntries = statistics.getEntries();
    assertEquals( 0, cacheEntries.size() );
  }
View Full Code Here

        }
      }
    }

    // check the version value in the cache...
    SecondLevelCacheStatistics slcs = sfi().getStatistics()
        .getSecondLevelCacheStatistics( VersionedItem.class.getName() );

    Object entry = slcs.getEntries().get( item.getId() );
    Long cachedVersionValue;
    if ( entry instanceof ReadWriteCache.Lock ) {
      //FIXME don't know what to test here
      cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() );
    }
View Full Code Here

  public String sameSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entities and check if they are put in 2LC
      createEmployee(em, "Peter", "Ostrava", 2);
      createEmployee(em, "Tom", "Brno", 3);
      assertEquals("There are 2 puts in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
     
      // loading all Employee entities should put in 2LC all Employee
      List<?> empList = getAllEmployeesQuery(em);
      assertEquals("There are 2 entities.", empList.size(), 2);
      assertEquals("There are 2 entities in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getElementCountInMemory());
     
      // clear session
      em.clear();
     
      // entity should be loaded from 2L cache, we'are expecting hit in 2L cache
      Employee emp = getEmployee(em, 2);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 hit in cache"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getHitCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
View Full Code Here

  public String secondSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entity
      createEmployee(em, "David", "Praha", 10);
      assertEquals("There is 1 put in the 2LC"+generateEntityCacheStats(emp2LCStats), 1, emp2LCStats.getPutCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
    }
   
   
    EntityManager em2 = emf.createEntityManager();
    try
      // loading entity stored in previous session, we'are expecting hit in cache
      Employee emp = getEmployee(em2, 10);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 hit in 2LC"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getHitCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em2.close();
View Full Code Here

  public String addEntitiesAndEvictAll(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
   
    try{
      createEmployee(em, "Jan", "Ostrava", 20);
      createEmployee(em, "Martin", "Brno", 30);
      assertEquals("There are 2 puts in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
     
      assertTrue("Expected entities stored in the cache"+generateEntityCacheStats(emp2LCStats), emp2LCStats.getElementCountInMemory() > 0);
     
      // evict entity 2lc
      emf.getCache().evictAll();
     
    }catch (AssertionError e) {
View Full Code Here

  public String evictedEntityCacheCheck(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try
      assertEquals("Expected no entities stored in the cache"+emp2LCStats, 0, emp2LCStats.getElementCountInMemory());
     
      // loading entity stored in previous session, we are expecting miss in 2lc
      Employee emp = getEmployee(em, 20);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 miss in 2LC"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getMissCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
View Full Code Here

TOP

Related Classes of org.hibernate.stat.SecondLevelCacheStatistics

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.