Search in sources :

Example 96 with Statistics

use of org.hibernate.stat.Statistics in project redisson by redisson.

the class ReadWriteTest method testNaturalId.

@Test
public void testNaturalId() {
    Statistics stats = sessionFactory().getStatistics();
    Session s = openSession();
    s.beginTransaction();
    ItemReadWrite item = new ItemReadWrite("data");
    item.setNid("123");
    s.save(item);
    s.flush();
    s.getTransaction().commit();
    Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getPutCount());
    Assert.assertEquals(1, stats.getNaturalIdStatistics(ItemReadWrite.class.getName()).getCachePutCount());
    s = openSession();
    s.beginTransaction();
    item = (ItemReadWrite) s.bySimpleNaturalId(ItemReadWrite.class).load("123");
    assertThat(item).isNotNull();
    s.delete(item);
    s.getTransaction().commit();
    s.close();
    Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getHitCount());
    Assert.assertEquals(1, stats.getNaturalIdStatistics(ItemReadWrite.class.getName()).getCacheHitCount());
    sessionFactory().getStatistics().logSummary();
}
Also used : Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test)

Example 97 with Statistics

use of org.hibernate.stat.Statistics in project keycloak by keycloak.

the class HibernateStatsReporter method run.

@Override
public void run(KeycloakSession session) {
    SessionFactory sessionFactory = ((SessionFactoryImpl) emf);
    Statistics stats = sessionFactory.getStatistics();
    logStats(stats);
    // For now, clear stats after each iteration
    stats.clear();
}
Also used : SessionFactory(org.hibernate.SessionFactory) CollectionStatistics(org.hibernate.stat.CollectionStatistics) QueryStatistics(org.hibernate.stat.QueryStatistics) Statistics(org.hibernate.stat.Statistics) EntityStatistics(org.hibernate.stat.EntityStatistics)

Aggregations

Statistics (org.hibernate.stat.Statistics)97 Test (org.junit.Test)59 Session (org.hibernate.Session)27 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)26 EntityManager (javax.persistence.EntityManager)21 QueryStatistics (org.hibernate.stat.QueryStatistics)19 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)14 Transaction (org.hibernate.Transaction)12 ArrayList (java.util.ArrayList)11 VersionedItem (org.hibernate.test.cache.infinispan.functional.entities.VersionedItem)11 List (java.util.List)10 OtherItem (org.hibernate.test.cache.infinispan.functional.entities.OtherItem)10 SessionFactory (org.hibernate.SessionFactory)9 CacheRegionStatistics (org.hibernate.stat.CacheRegionStatistics)9 ByRef (org.infinispan.commons.util.ByRef)8 TestForIssue (org.hibernate.testing.TestForIssue)6 Date (java.util.Date)5 UserTransaction (javax.transaction.UserTransaction)5 NaturalIdCacheStatistics (org.hibernate.stat.NaturalIdCacheStatistics)5 Test (org.testng.annotations.Test)5