Package org.hibernate.stat

Examples of org.hibernate.stat.SecondLevelCacheStatistics


  @Test
  public void testQueryCacheInvalidation() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();

    SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics( Item.class.getName() );
    sessionFactory().getCache().evictEntityRegion( Item.class.getName() );

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

    Session s = null;
    Transaction t = null;
    Item i = null;

    beginTx();
    try {
      s = openSession();
      t = s.beginTransaction();
      i = new Item();
      i.setName( "widget" );
      i.setDescription( "A really top-quality, full-featured widget." );
      s.persist( i );
      t.commit();
      s.close();
    }
    catch (Exception e) {
      setRollbackOnlyTx( e );
    }
    finally {
      commitOrRollbackTx();
    }


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

    beginTx();
    try {
      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();
    }
    catch (Exception e) {
      setRollbackOnlyTx( e );
    }
    finally {
      commitOrRollbackTx();
    }

    assertEquals( slcs.getPutCount(), 2 );

    CacheEntry entry = (CacheEntry) slcs.getEntries().get( i.getId() );
    Serializable[] ser = entry.getDisassembledState();
    assertTrue( ser[0].equals( "widget" ) );
    assertTrue( ser[1].equals( "A bog standard item" ) );

    beginTx();
View Full Code Here


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

      List<Integer> rhContacts = getContactsByCustomer( "Red Hat" );
      assertNotNull( "Red Hat contacts exist", rhContacts );
      assertEquals( "Created expected number of Red Hat contacts", 10, rhContacts.size() );

      SecondLevelCacheStatistics contactSlcs = sessionFactory()
          .getStatistics()
          .getSecondLevelCacheStatistics( Contact.class.getName() );
      assertEquals( 20, contactSlcs.getElementCountInMemory() );

      assertEquals( "Deleted all Red Hat contacts", 10, deleteContacts() );
      assertEquals( 0, contactSlcs.getElementCountInMemory() );

      List<Integer> jbContacts = getContactsByCustomer( "JBoss" );
      assertNotNull( "JBoss contacts exist", jbContacts );
      assertEquals( "JBoss contacts remain", 10, jbContacts.size() );

      for ( Integer id : rhContacts ) {
        assertNull( "Red Hat contact " + id + " cannot be retrieved", getContact( id ) );
      }
      rhContacts = getContactsByCustomer( "Red Hat" );
      if ( rhContacts != null ) {
        assertEquals( "No Red Hat contacts remain", 0, rhContacts.size() );
      }

      updateContacts( "Kabir", "Updated" );
      assertEquals( 0, contactSlcs.getElementCountInMemory() );
      for ( Integer id : jbContacts ) {
        Contact contact = getContact( id );
        assertNotNull( "JBoss contact " + id + " exists", contact );
        String expected = ("Kabir".equals( contact.getName() )) ? "Updated" : "2222";
        assertEquals( "JBoss contact " + id + " has correct TLF", expected, contact.getTlf() );
      }

      List<Integer> updated = getContactsByTLF( "Updated" );
      assertNotNull( "Got updated contacts", updated );
      assertEquals( "Updated contacts", 5, updated.size() );

      updateContactsWithOneManual( "Kabir", "UpdatedAgain" );
      assertEquals( contactSlcs.getElementCountInMemory(), 0 );
      for ( Integer id : jbContacts ) {
        Contact contact = getContact( id );
        assertNotNull( "JBoss contact " + id + " exists", contact );
        String expected = ("Kabir".equals( contact.getName() )) ? "UpdatedAgain" : "2222";
        assertEquals( "JBoss contact " + id + " has correct TLF", expected, contact.getTlf() );
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 = getMapFromCachedEntry(entry);
    assertTrue( map.get("description").equals("A bog standard item") );
    assertTrue( map.get("name").equals("widget") );

    // cleanup
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() );
    } else if(entry.getClass().getName().equals("net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy$Lock")) {
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 = new HashMap();
      map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
    }
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

    @Test
    public void secondLevelCacheAccessInSameTx() throws Exception {
        EntityManager em = super.newEntityManagerInstance();
        SessionStatistics sessionStats = getSessionStatistics(em);
        SecondLevelCacheStatistics cacheStats =
                getSecondLevelCacheStatistics(em, HPerson.class.getName());

        HPerson p = em.find(HPerson.class, 3L);
        assertThat(p.getName(), is("Bob Translator"));
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.