@@ -38,10 +38,9 @@ public Class<StatisticsImplementor> getServiceInitiated() {
3838
3939 @ Override
4040 public StatisticsImplementor initiateService (SessionFactoryServiceInitiatorContext context ) {
41- final Object configValue = context .getServiceRegistry ()
42- .requireService ( ConfigurationService .class )
43- .getSettings ()
44- .get ( STATS_BUILDER );
41+ final Object configValue =
42+ context .getServiceRegistry ().requireService ( ConfigurationService .class )
43+ .getSettings ().get ( STATS_BUILDER );
4544 return initiateServiceInternal ( context .getSessionFactory (), configValue , context .getServiceRegistry () );
4645 }
4746
@@ -50,18 +49,30 @@ private StatisticsImplementor initiateServiceInternal(
5049 @ Nullable Object configValue ,
5150 ServiceRegistryImplementor registry ) {
5251
53- final StatisticsFactory statisticsFactory ;
52+ final StatisticsFactory statisticsFactory = statisticsFactory ( configValue , registry );
53+ final StatisticsImplementor statistics =
54+ statisticsFactory == null
55+ ? new StatisticsImpl ( sessionFactory ) // default impl
56+ : statisticsFactory .buildStatistics ( sessionFactory );
57+ final boolean enabled = sessionFactory .getSessionFactoryOptions ().isStatisticsEnabled ();
58+ statistics .setStatisticsEnabled ( enabled );
59+ LOG .debugf ( "Statistics initialized [enabled=%s]" , enabled );
60+ return statistics ;
61+ }
62+
63+ private static @ Nullable StatisticsFactory statisticsFactory (
64+ @ Nullable Object configValue , ServiceRegistryImplementor registry ) {
5465 if ( configValue == null ) {
55- statisticsFactory = null ; //We'll use the default
66+ return null ; //We'll use the default
5667 }
57- else if ( configValue instanceof StatisticsFactory ) {
58- statisticsFactory = ( StatisticsFactory ) configValue ;
68+ else if ( configValue instanceof StatisticsFactory factory ) {
69+ return factory ;
5970 }
6071 else {
6172 // assume it names the factory class
6273 final ClassLoaderService classLoaderService = registry .requireService ( ClassLoaderService .class );
6374 try {
64- statisticsFactory = (StatisticsFactory ) classLoaderService .classForName ( configValue .toString () ).newInstance ();
75+ return (StatisticsFactory ) classLoaderService .classForName ( configValue .toString () ).newInstance ();
6576 }
6677 catch (HibernateException e ) {
6778 throw e ;
@@ -73,18 +84,5 @@ else if ( configValue instanceof StatisticsFactory ) {
7384 );
7485 }
7586 }
76- final StatisticsImplementor statistics ;
77- if ( statisticsFactory == null ) {
78- // Default:
79- statistics = new StatisticsImpl ( sessionFactory );
80- }
81- else {
82- statistics = statisticsFactory .buildStatistics ( sessionFactory );
83- }
84- final boolean enabled = sessionFactory .getSessionFactoryOptions ().isStatisticsEnabled ();
85- statistics .setStatisticsEnabled ( enabled );
86- LOG .debugf ( "Statistics initialized [enabled=%s]" , enabled );
87- return statistics ;
8887 }
89-
9088}
0 commit comments