Package org.hibernate.stat

Examples of org.hibernate.stat.SecondLevelCacheStatistics


        }
      }
    }

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

    Object entry = slcs.getEntries().get( item.getId() );
    Long cachedVersionValue;
    cachedVersionValue = (Long) ((CacheEntry) entry).getVersion();
    assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());

    beginTx();
View Full Code Here


  @TestForIssue( jiraKey = "HHH-5690")
  public void testPersistEntityFlushRollbackNotInEntityCache() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();

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

    Item item = null;
    Transaction txn = null;
    Session s = null;

    beginTx();
    try {
      s = openSession();
      txn = s.beginTransaction();
      item = new Item();
      item.setName( "steve" );
      item.setDescription( "steve's item" );
      s.persist( item );
      s.flush();
      assertNotNull( slcs.getEntries().get( item.getId() ) );
      setRollbackOnlyTx();
    }
    catch (Exception e) {
      setRollbackOnlyTx( e );
    }
    finally {
      commitOrRollbackTx();
      if ( s != null && s.isOpen() ) {
        try {
          s.close();
        }
        catch (Throwable ignore) {
        }
      }
    }

    // item should not be in entity cache.
    assertTrue( slcs.getEntries().isEmpty() );

    beginTx();
    try {
      s = openSession();
      txn = s.beginTransaction();
View Full Code Here

  @Test
  @TestForIssue( jiraKey = "HHH-5690")
  public void testPersistEntityFlushEvictGetRollbackNotInEntityCache() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics( Item.class.getName() );

    Item item = null;
    Transaction txn = null;
    Session s = null;

    beginTx();
    try {
      s = openSession();
      txn = s.beginTransaction();
      item = new Item();
      item.setName( "steve" );
      item.setDescription( "steve's item" );
      s.persist( item );
      s.flush();
      // item is cached on insert.
      assertNotNull( slcs.getEntries().get( item.getId() ) );
      s.evict( item );
      assertEquals( slcs.getHitCount(), 0 );
      item = (Item) s.get( Item.class, item.getId() );
      assertNotNull( item );
      assertEquals( slcs.getHitCount(), 1 );
      assertNotNull( slcs.getEntries().get( item.getId() ) );
      setRollbackOnlyTx();
    }
    catch (Exception e) {
      setRollbackOnlyTx( e );
    }
    finally {
      commitOrRollbackTx();
      if ( s != null && s.isOpen() ) {
        try {
          s.close();
        }
        catch (Throwable ignore) {
        }
      }
    }

    // item should not be in entity cache.
    //slcs = stats.getSecondLevelCacheStatistics( Item.class.getName() );
    assertTrue( slcs.getEntries().isEmpty() );

    beginTx();
    try {
      s = openSession();
      txn = s.beginTransaction();
View Full Code Here

  @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

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

        SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
              getPrefixedRegionName(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 {
            map = (Map) entry;
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 = getEnvironment().getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
               getPrefixedRegionName(Contact.class.getName()));
         assertEquals(contactSlcs.getElementCountInMemory(), 20);
        
         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(contactSlcs.getElementCountInMemory(), 0);
         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";
View Full Code Here

    public void testEmptySecondLevelCacheEntry() throws Exception {
        getSessions().evictEntity(Item.class.getName());
        Statistics stats = getSessions().getStatistics();
        stats.clear();
        SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(getPrefixedRegionName(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(
              getPrefixedRegionName(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 {
View Full Code Here

    } else if(parent==queries) {
      return stats.getQueryStatistics(stats.getQueries()[index]);
    } else if(parent==secondlevelcache) {
      return stats.getSecondLevelCacheStatistics( stats.getSecondLevelCacheRegionNames()[index]);
    } else if(parent instanceof SecondLevelCacheStatistics) {
      SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) parent;     
      return slcs.getEntries();
    }
    return null;
  }
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 = getEnvironment().getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
               getPrefixedRegionName(Contact.class.getName()));
         assertEquals(contactSlcs.getElementCountInMemory(), 20);
        
         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(contactSlcs.getElementCountInMemory(), 0);
         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";
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.