Refine search
@Override public Object invoke(Object... args) { getStatistics( getEntityManagerFactory( args ) ).clear(); 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 Map<String, Object> asJson() { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); Statistics statistics = sessionFactory.getStatistics(); if (!statistics.isStatisticsEnabled()){ return json; json.put("EntityDeleteCount", statistics.getEntityDeleteCount()); json.put("EntityInsertCount", statistics.getEntityInsertCount()); json.put("EntityLoadCount", statistics.getEntityLoadCount()); json.put("EntityFetchCount", statistics.getEntityFetchCount()); json.put("EntityUpdateCount", statistics.getEntityUpdateCount()); json.put("QueryExecutionCount", statistics.getQueryExecutionCount()); json.put("QueryExecutionMaxTime", statistics.getQueryExecutionMaxTime()); json.put("QueryExecutionMaxTimeQueryString", statistics.getQueryExecutionMaxTimeQueryString()); json.put("QueryCacheHitCount", statistics.getQueryCacheHitCount()); json.put("QueryCacheMissCount", statistics.getQueryCacheMissCount()); json.put("QueryCachePutCount", statistics.getQueryCachePutCount()); json.put("FlushCount", statistics.getFlushCount()); json.put("ConnectCount", statistics.getConnectCount()); json.put("SecondLevelCacheHitCount", statistics.getSecondLevelCacheHitCount()); json.put("SecondLevelCacheMissCount", statistics.getSecondLevelCacheMissCount()); json.put("SecondLevelCachePutCount", statistics.getSecondLevelCachePutCount()); json.put("SessionCloseCount", statistics.getSessionCloseCount()); json.put("SessionOpenCount", statistics.getSessionOpenCount()); json.put("CollectionLoadCount", statistics.getCollectionLoadCount()); json.put("CollectionFetchCount", statistics.getCollectionFetchCount()); json.put("CollectionUpdateCount", statistics.getCollectionUpdateCount()); json.put("CollectionRemoveCount", statistics.getCollectionRemoveCount()); json.put("CollectionRecreateCount", statistics.getCollectionRecreateCount());
private org.hibernate.stat.QueryStatistics getStatistics( EntityManagerFactory entityManagerFactory, String displayQueryName) { if ( entityManagerFactory == null ) { return null; } SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class ); // convert displayed (transformed by QueryNames) query name to original query name to look up query statistics if ( sessionFactory != null ) { String[] originalQueryNames = sessionFactory.getStatistics().getQueries(); if ( originalQueryNames != null ) { for ( String originalQueryName : originalQueryNames ) { if ( QueryName.queryName( originalQueryName ).getDisplayName().equals( displayQueryName ) ) { return sessionFactory.getStatistics().getQueryStatistics( originalQueryName ); } } } } return null; }
s = sf.openSession(); tx = s.beginTransaction(); final String continents = "from Continent"; int results = s.createQuery( continents ).list().size(); QueryStatistics continentStats = sf.getStatistics().getQueryStatistics( continents ); assertNotNull( "stats were null", continentStats ); assertEquals( "unexpected execution count", 1, continentStats.getExecutionCount() ); assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() ); long maxTime = continentStats.getExecutionMaxTime(); assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() ); sf.getStatistics().clear(); final String localities = "from Locality"; results = s.createQuery( localities ).list().size(); QueryStatistics localityStats = sf.getStatistics().getQueryStatistics( localities ); assertNotNull( "stats were null", localityStats ); assertEquals( "unexpected row count", results, localityStats.getExecutionRowCount() ); maxTime = localityStats.getExecutionMaxTime(); assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() ); sf.getStatistics().clear(); final String sql = "select id, name from Country"; results = s.createSQLQuery( sql ).addEntity( Country.class ).list().size(); QueryStatistics sqlStats = sf.getStatistics().getQueryStatistics( sql ); assertNotNull( "sql stats were null", sqlStats ); assertEquals( "unexpected execution count", 1, sqlStats.getExecutionCount() );
private org.hibernate.stat.EntityStatistics getStatistics( EntityManagerFactory entityManagerFactory, String entityName) { if ( entityManagerFactory == null ) { return null; } SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class ); if ( sessionFactory != null ) { return sessionFactory.getStatistics().getEntityStatistics( entityName ); } return null; }
private CollectionStatistics getStatistics(final EntityManagerFactory entityManagerFactory, String collectionName) { if ( entityManagerFactory == null ) { return null; } SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class ); if ( sessionFactory != null ) { return sessionFactory.getStatistics().getCollectionStatistics( collectionName ); } return null; }
stats.setStatisticsEnabled( true ); stats.clear(); assertEquals( "Cache hits should be empty", 0, stats.getNaturalIdCacheHitCount() ); assertEquals( "Cache puts should be empty", 0, stats.getNaturalIdCachePutCount() ); 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() ); 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() );
@TestForIssue(jiraKey = "HHH-4838") @Test public void testNaturalKeyLookupWithConstraint() { Session s = openSession(); Transaction newTx = s.getTransaction(); newTx.begin(); A a1 = new A(); a1.setName( "name1" ); s.persist( a1 ); newTx.commit(); newTx = s.beginTransaction(); getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult(); // put query-result into cache A a2 = new A(); a2.setName( "xxxxxx" ); s.persist( a2 ); newTx.commit(); // Invalidates space A in UpdateTimeStamps region newTx = s.beginTransaction(); Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); s.getSessionFactory().getStatistics().clear(); // should not produce a hit in StandardQuery cache region because there is a constraint getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult(); Assert.assertEquals( 0, s.getSessionFactory().getStatistics().getQueryCacheHitCount() ); s.createQuery( "delete from A" ).executeUpdate(); newTx.commit(); // Shutting down the application s.close(); }
org.hibernate.stat.SecondLevelCacheStatistics getStatistics( EntityManagerFactoryAccess entityManagerFactoryaccess, PathAddress pathAddress) { String scopedPersistenceUnitName = pathAddress.getValue( HibernateStatistics.PROVIDER_LABEL ); SessionFactory sessionFactory = entityManagerFactoryaccess.entityManagerFactory( scopedPersistenceUnitName ) .unwrap( SessionFactory.class ); if ( sessionFactory != null ) { // The entity class name is prefixed by the application scoped persistence unit name return sessionFactory.getStatistics().getSecondLevelCacheStatistics( scopedPersistenceUnitName + "." + pathAddress.getValue( HibernateStatistics.ENTITYCACHE ) ); } return null; }
s.setCacheMode( CacheMode.IGNORE); sessionFactory = s.getSessionFactory(); sessionFactory.getCache().evictAllRegions(); statistics = sessionFactory.getStatistics(); statistics.clear(); t = s.beginTransaction(); s.close(); assertEquals(0L, statistics.getSecondLevelCacheHitCount()); assertEquals(0L, statistics.getSecondLevelCacheMissCount()); assertEquals(0L, statistics.getSecondLevelCachePutCount()); assertFalse(sessionFactory.getCache().containsEntity(PurchaseOrder.class, 1L)); sessionFactory.getCache().evictAllRegions(); statistics = sessionFactory.getStatistics(); statistics.clear(); t = s.beginTransaction(); s.close(); assertEquals(0, statistics.getSecondLevelCacheHitCount()); assertEquals(0, statistics.getSecondLevelCacheMissCount()); assertEquals(0, statistics.getSecondLevelCachePutCount()); assertEquals( 0, statistics.getSecondLevelCacheHitCount()); assertEquals( 1, statistics.getSecondLevelCacheMissCount() ); assertEquals( 0, statistics.getSecondLevelCachePutCount() );
@Override protected void populateStats(Statistics stats) throws Exception { org.hibernate.stat.Statistics hs = sessionFactory.getStatistics(); stats.add("Query cache hit count", hs.getQueryCacheHitCount()); stats.add("Query cache miss count", hs.getQueryCacheMissCount()); stats.add("Query cache put count", hs.getQueryCachePutCount()); stats.add("2nd level cache hit count" , hs.getSecondLevelCacheHitCount()); stats.add("2nd level cache miss count", hs.getSecondLevelCacheMissCount()); stats.add("2nd level cache put count", hs.getSecondLevelCachePutCount()); }
Statistics statistics = sessionFactory.getStatistics(); sessionFactory.getCache().evictAll(); statistics.clear(); sqlStatementInterceptor.clear(); assertEquals( 0, statistics.getQueryExecutionCount() ); } ); assertEquals( 0, statistics.getSecondLevelCacheHitCount() ); assertEquals( 3, statistics.getSecondLevelCachePutCount() ); assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); assertEquals( 3, statistics.getSecondLevelCacheHitCount() ); assertEquals( 0, sqlStatementInterceptor.getSqlQueries().size() );
@Test @TestForIssue( jiraKey = "HHH-7278" ) public void testInsertedNaturalIdCachedAfterTransactionSuccess() { Session session = openSession(); session.getSessionFactory().getStatistics().clear(); session.beginTransaction(); Another it = new Another( "it"); session.save( it ); session.flush(); session.getTransaction().commit(); session.close(); session = openSession(); session.beginTransaction(); it = (Another) session.bySimpleNaturalId(Another.class).load("it"); assertNotNull(it); session.delete(it); session.getTransaction().commit(); assertEquals(1, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount()); }
assertEquals( 0, q.list().size() ); Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); q = s.getNamedQuery( "night.duration" ); q.setParameter( "duration", 14l ); assertEquals( 1, q.list().size() ); assertEquals( 1, stats.getQueryCachePutCount() ); q = s.getNamedQuery( "night.duration" ); q.setParameter( "duration", 14l ); s.delete( q.list().get( 0 ) ); assertEquals( 1, stats.getQueryCacheHitCount() ); tx.commit(); s.close();
public void printStats() { System.out.println("2lc put count: " + sessionFactory.getStatistics().getSecondLevelCachePutCount()); System.out.println("2lc hit count: " + sessionFactory.getStatistics().getSecondLevelCacheHitCount()); System.out.println("2lc miss count: " + sessionFactory.getStatistics().getSecondLevelCacheMissCount()); }
public void printStats() { System.out.println("query cache put count: " + sessionFactory.getStatistics().getQueryCachePutCount()); System.out.println("query cache hit count: " + sessionFactory.getStatistics().getQueryCacheHitCount()); System.out.println("query cache miss count: " + sessionFactory.getStatistics().getQueryCacheMissCount()); }
private void addSecondLevelCacheStats(List<ApplicationStat> res, Statistics stats) { addCacheStat(res, "2Cache/total/", stats.getSecondLevelCacheHitCount(), stats.getSecondLevelCacheMissCount(), stats.getSecondLevelCachePutCount()); for (String cacheRegion : stats.getSecondLevelCacheRegionNames()) { SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(cacheRegion); addCacheStat(res, "2Cache/" + cacheRegion + "/", cStats.getHitCount(), cStats.getMissCount(), cStats.getPutCount()); addStat(res, "2Cache/" + cacheRegion + "/size", cStats.getElementCountInMemory(), "onDisk=" + cStats.getElementCountOnDisk() + ", memSize=" + cStats.getSizeInMemory()); } }
@Test public void testFiltersAreApplied() { doInHibernate( this::sessionFactory, session -> { session.enableFilter( "ID" ).setParameter( "id", 3L ); List result = session.createQuery( "from Customer order by id" ).list(); assertFalse( result.isEmpty() ); Customer customer = (Customer) result.get( 0 ); assertSame( customer.getCustomerId(), 3L ); assertSame( customer.getOrders().size(), 2 ); SessionStatistics statistics = session.getStatistics(); assertSame( statistics.getEntityCount(), 9 ); Statistics sfStatistics = session.getSessionFactory().getStatistics(); assertSame( sfStatistics.getCollectionFetchCount(), 1L ); assertSame( sfStatistics.getQueries().length, 1 ); } ); }
@Override public Object invoke(Object... args) { String displayQueryName = getQueryName( args ); EntityManagerFactory entityManagerFactory = getEntityManagerFactory( args ); if ( displayQueryName != null && entityManagerFactory != null ) { SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class ); // convert displayed (transformed by QueryNames) query name to original query name if ( sessionFactory != null ) { String[] originalQueryNames = sessionFactory.getStatistics().getQueries(); if ( originalQueryNames != null ) { for ( String originalQueryName : originalQueryNames ) { if ( QueryName.queryName( originalQueryName ) .getDisplayName() .equals( displayQueryName ) ) { return originalQueryName; } } } } } return null; } };