Example usage for org.hibernate.stat NaturalIdCacheStatistics getMissCount

List of usage examples for org.hibernate.stat NaturalIdCacheStatistics getMissCount

Introduction

In this page you can find the example usage for org.hibernate.stat NaturalIdCacheStatistics getMissCount.

Prototype

long getMissCount();

Source Link

Usage

From source file:org.apache.ignite.cache.hibernate.GridHibernateL2CacheSelfTest.java

License:Apache License

/**
 * @param sesFactory Session factory.//from w  w  w  .  ja v  a  2  s  .c o  m
 * @param nameToId Name-ID mapping.
 * @param absentNames Absent entities' names.
 */
private void assertNaturalIdCache(SessionFactory sesFactory, Map<String, Integer> nameToId,
        String... absentNames) {
    sesFactory.getStatistics().clear();

    NaturalIdCacheStatistics stats = sesFactory.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);

    long hitBefore = stats.getHitCount();

    long missBefore = stats.getMissCount();

    final Session ses = sesFactory.openSession();

    try {
        for (Map.Entry<String, Integer> e : nameToId.entrySet())
            assertEquals((int) e.getValue(),
                    ((Entity) ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId());

        for (String name : absentNames)
            assertNull((ses.bySimpleNaturalId(Entity.class).load(name)));

        assertEquals(nameToId.size() + hitBefore, stats.getHitCount());

        assertEquals(absentNames.length + missBefore, stats.getMissCount());
    } finally {
        ses.close();
    }
}