List of usage examples for org.hibernate SessionFactory getStatistics
Statistics getStatistics();
From source file:org.jboss.as.jpa.hibernate4.management.ManagementLookup.java
License:Open Source License
public static ManagementLookup create(PersistenceUnitServiceRegistry registry, String persistenceUnitName) { Statistics stats = null;/* ww w . j a v a2s.c om*/ PersistenceUnitService persistenceUnitService = registry.getPersistenceUnitService(persistenceUnitName); if (persistenceUnitService != null) { final EntityManagerFactory entityManagerFactory = persistenceUnitService.getEntityManagerFactory(); // TODO: with JPA 2.1, if unwrap is added to EMF, change cast to "entityManagerFactory.unwrap(HibernateEntityManagerFactory.class)" HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory; SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory(); if (sessionFactory != null) { stats = sessionFactory.getStatistics(); return new ManagementLookup(stats, entityManagerFactory); } } return null; }
From source file:org.jboss.as.jpa.hibernate4.management.ManagementUtility.java
License:Open Source License
public static Statistics getStatistics(final OperationContext context, final String puname) { Statistics stats = null;/*from w w w .ja v a2 s . co m*/ final ServiceController<?> controller = context.getServiceRegistry(false) .getService(JPAServiceNames.getPUServiceName(puname)); if (controller != null) { // get the persistence unit service that represents the deployed persistence unit PersistenceUnitService persistenceUnitService = (PersistenceUnitService) controller.getValue(); EntityManagerFactory entityManagerFactory = persistenceUnitService.getEntityManagerFactory(); // TODO: with JPA 2.1, if unwrap is added to EMF, change cast to "entityManagerFactory.unwrap(HibernateEntityManagerFactory.class)" HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory; SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory(); if (sessionFactory != null) { stats = sessionFactory.getStatistics(); } } return stats; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateCollectionStatistics.java
License:Apache License
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) { if (entityManagerFactory == null) { return null; }/*from w ww . j a v a2 s .co m*/ SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); if (sessionFactory != null) { return sessionFactory.getStatistics(); } return null; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateCollectionStatistics.java
License:Apache License
private CollectionStatistics getStatistics(final EntityManagerFactory entityManagerFactory, String collectionName) {/*from w w w . j a v a 2 s . c o m*/ if (entityManagerFactory == null) { return null; } SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); if (sessionFactory != null) { return sessionFactory.getStatistics().getCollectionStatistics(collectionName); } return null; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateEntityCacheStatistics.java
License:Apache License
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)); }/*w w w . j ava 2 s .c o m*/ return null; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateEntityStatistics.java
License:Apache License
private org.hibernate.stat.EntityStatistics getStatistics(EntityManagerFactory entityManagerFactory, String entityName) {// w w w . j a v a 2 s . co m if (entityManagerFactory == null) { return null; } SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); if (sessionFactory != null) { return sessionFactory.getStatistics().getEntityStatistics(entityName); } return null; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateQueryCacheStatistics.java
License:Apache License
private org.hibernate.stat.QueryStatistics getStatistics(EntityManagerFactory entityManagerFactory, String displayQueryName) { if (entityManagerFactory == null) { return null; }//w w w. j av a 2s.co m 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; }
From source file:org.jboss.as.jpa.hibernate5.management.HibernateStatistics.java
License:Apache License
static final org.hibernate.stat.Statistics getStatistics(final EntityManagerFactory entityManagerFactory) { if (entityManagerFactory == null) { return null; }/*from ww w . j a va 2 s. co m*/ SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); if (sessionFactory != null) { return sessionFactory.getStatistics(); } return null; }
From source file:org.keycloak.connections.jpa.HibernateStatsReporter.java
License:Apache License
@Override public void run(KeycloakSession session) { SessionFactory sessionFactory = ((SessionFactoryImpl) emf); Statistics stats = sessionFactory.getStatistics(); logStats(stats);// w ww. jav a 2 s.c o m stats.clear(); // For now, clear stats after each iteration }
From source file:org.mzd.shap.spring.orm.Reporting.java
License:Open Source License
public static String reportQueryCacheStatistics(SessionFactory sessionFactory) { StringBuffer buffer = new StringBuffer(); Statistics stats = sessionFactory.getStatistics(); long queryHitCount = stats.getQueryCacheHitCount(); long queryMissCount = stats.getQueryCacheMissCount(); buffer.append("Query Cache Hits: " + queryHitCount + "\n"); buffer.append("Query Cache Misses: " + queryMissCount + "\n"); if (queryHitCount + queryMissCount > 0) { buffer.append("Query Cache Hit Ratio: " + (double) queryHitCount / (double) (queryHitCount + queryMissCount) + "\n"); }/* ww w . ja v a 2 s.c om*/ return buffer.toString(); }