Search in sources :

Example 1 with StatisticsFactory

use of org.hibernate.stat.spi.StatisticsFactory in project hibernate-orm by hibernate.

the class StatisticsInitiator method initiateServiceInternal.

private StatisticsImplementor initiateServiceInternal(SessionFactoryImplementor sessionFactory, Object configValue, ServiceRegistryImplementor registry) {
    StatisticsFactory statisticsFactory;
    if (configValue == null) {
        statisticsFactory = DEFAULT_STATS_BUILDER;
    } else if (StatisticsFactory.class.isInstance(configValue)) {
        statisticsFactory = (StatisticsFactory) configValue;
    } else {
        // assume it names the factory class
        final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
        try {
            statisticsFactory = (StatisticsFactory) classLoaderService.classForName(configValue.toString()).newInstance();
        } catch (HibernateException e) {
            throw e;
        } catch (Exception e) {
            throw new HibernateException("Unable to instantiate specified StatisticsFactory implementation [" + configValue.toString() + "]", e);
        }
    }
    StatisticsImplementor statistics = statisticsFactory.buildStatistics(sessionFactory);
    final boolean enabled = sessionFactory.getSettings().isStatisticsEnabled();
    statistics.setStatisticsEnabled(enabled);
    LOG.debugf("Statistics initialized [enabled=%s]", enabled);
    return statistics;
}
Also used : HibernateException(org.hibernate.HibernateException) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) StatisticsFactory(org.hibernate.stat.spi.StatisticsFactory) HibernateException(org.hibernate.HibernateException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

HibernateException (org.hibernate.HibernateException)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 StatisticsFactory (org.hibernate.stat.spi.StatisticsFactory)1 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)1