@Override public Object invoke(Object... args) { org.hibernate.stat.Statistics statistics = getStatistics( getEntityManagerFactory( args ) ); if ( statistics != null ) { if ( args.length > 0 && args[0] instanceof Boolean ) { Boolean newValue = (Boolean) args[0]; statistics.setStatisticsEnabled( newValue.booleanValue() ); } return Boolean.valueOf( statistics.isStatisticsEnabled() ); } return null; } };
@Override public Object invoke(Object... args) { org.hibernate.stat.Statistics statistics = getStatistics(getEntityManagerFactory(args)); if (statistics != null) { if (args.length > 0 && args[0] instanceof Boolean) { Boolean newValue = (Boolean) args[0]; statistics.setStatisticsEnabled(newValue.booleanValue()); } return Boolean.valueOf(statistics.isStatisticsEnabled()); } return null; } };
@Override public Object invoke(Object... args) { org.hibernate.stat.Statistics statistics = getStatistics(getEntityManagerFactory(args)); if (statistics != null) { if (args.length > 0 && args[0] instanceof Boolean) { Boolean newValue = (Boolean) args[0]; statistics.setStatisticsEnabled(newValue.booleanValue()); } return Boolean.valueOf(statistics.isStatisticsEnabled()); } return null; } };
@Override public Object invoke(Object... args) { org.hibernate.stat.Statistics statistics = getStatistics(getEntityManagerFactory(args)); if (statistics != null) { if (args.length > 0 && args[0] instanceof Boolean) { Boolean newValue = (Boolean) args[0]; statistics.setStatisticsEnabled(newValue.booleanValue()); } return Boolean.valueOf(statistics.isStatisticsEnabled()); } return null; } };
@Override public Object invoke(Object... args) { org.hibernate.stat.Statistics statistics = getStatistics(getEntityManagerFactory(args)); if (statistics != null) { if (args.length > 0 && args[0] instanceof Boolean) { Boolean newValue = (Boolean) args[0]; statistics.setStatisticsEnabled(newValue.booleanValue()); } return Boolean.valueOf(statistics.isStatisticsEnabled()); } return null; } };
assertEquals( 0, q.list().size() ); Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); q = s.getNamedQuery( "night.duration" );
tx = s.beginTransaction(); Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); Query q = s.getNamedQuery( "night&areaCached" );
stats.setStatisticsEnabled( true ); stats.clear(); assertEquals(
stats.setStatisticsEnabled( true ); stats.clear(); assertEquals( "Cache hits should be empty", 0, stats.getNaturalIdCacheHitCount() );
stats.setStatisticsEnabled( true ); stats.clear(); assertEquals( "NaturalId cache puts should be zero", 0, stats.getNaturalIdCachePutCount() );
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.HibernateStats#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean flag) { getStatistics().setStatisticsEnabled(flag); sendNotification(CACHE_STATISTICS_ENABLED, flag); }
@Test public void testNaturalIdLoaderCached() { Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); stats.setStatisticsEnabled( true ); stats.clear(); stats.setStatisticsEnabled( true ); stats.clear();
@Test public void testNaturalIdLoaderNotCached() { saveSomeCitizens(); Session s = openSession(); Transaction tx = s.beginTransaction(); State france = this.getState( s, "Ile de France" ); final NaturalIdLoadAccess naturalIdLoader = s.byNaturalId( Citizen.class ); naturalIdLoader.using( "ssn", "1234" ).using( "state", france ); //NaturalId cache gets populated during entity loading, need to clear it out this.cleanupCache(); Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); assertEquals( "NaturalId Cache Hits", 0, stats.getNaturalIdCacheHitCount() ); assertEquals( "NaturalId Cache Misses", 0, stats.getNaturalIdCacheMissCount() ); assertEquals( "NaturalId Cache Puts", 0, stats.getNaturalIdCachePutCount() ); assertEquals( "NaturalId Cache Queries", 0, stats.getNaturalIdQueryExecutionCount() ); // first query Citizen citizen = (Citizen)naturalIdLoader.load(); assertNotNull( citizen ); assertEquals( "NaturalId Cache Hits", 0, stats.getNaturalIdCacheHitCount() ); assertEquals( "NaturalId Cache Misses", 1, stats.getNaturalIdCacheMissCount() ); assertEquals( "NaturalId Cache Puts", 1, stats.getNaturalIdCachePutCount() ); assertEquals( "NaturalId Cache Queries", 1, stats.getNaturalIdQueryExecutionCount() ); // cleanup tx.rollback(); s.close(); }
/** * @see StatisticsServiceMBean#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean enable) { stats.setStatisticsEnabled(enable); }
/** * @see StatisticsServiceMBean#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean enable) { stats.setStatisticsEnabled(enable); }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.HibernateStats#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean flag) { getStatistics().setStatisticsEnabled(flag); sendNotification(CACHE_STATISTICS_ENABLED, flag); }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.HibernateStats#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean flag) { getStatistics().setStatisticsEnabled(flag); sendNotification(CACHE_STATISTICS_ENABLED, flag); }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.HibernateStats#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean flag) { getStatistics().setStatisticsEnabled(flag); sendNotification(CACHE_STATISTICS_ENABLED, flag); }
private static void configureSessions() { try { Configuration annotationConfiguration = new AnnotationConfiguration(); Configuration cfg = annotationConfiguration.configure("hibernate.cfg.xml"); sessionFactory = cfg.buildSessionFactory(); sessionFactory.getStatistics().setStatisticsEnabled(true); } catch (Exception e) { logger.error("configure session error", e); throw new ARRuntimeException(e); } }
public void beginCacheTest() { SessionFactory sessionFactory = environment.get(SessionFactory.class); if (sessionFactory != null) { log.debug("================================================================="); log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test"); log.debug("================================================================="); sessionFactory.getStatistics().clear(); sessionFactory.getStatistics().setStatisticsEnabled(true); } }