Skip to content

Commit

Permalink
HHH-13546 Make the sessionFactory field in StatisticsImpl required
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Aug 7, 2019
1 parent 41cab3b commit 8460cd8
Showing 1 changed file with 5 additions and 50 deletions.
Expand Up @@ -6,6 +6,7 @@
*/
package org.hibernate.stat.internal;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

Expand All @@ -31,6 +32,7 @@
*/
@SuppressWarnings({ "unchecked" })
public class StatisticsImpl implements StatisticsImplementor, Service, Manageable {

private static final CoreMessageLogger LOG = messageLogger( StatisticsImpl.class );

private final SessionFactoryImplementor sessionFactory;
Expand Down Expand Up @@ -104,14 +106,8 @@ public class StatisticsImpl implements StatisticsImplementor, Service, Manageabl

private final StatsNamedContainer<DeprecatedNaturalIdCacheStatisticsImpl> deprecatedNaturalIdStatsMap = new StatsNamedContainer();


@SuppressWarnings({ "UnusedDeclaration" })
public StatisticsImpl() {
this( null );
}

public StatisticsImpl(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
this.sessionFactory = Objects.requireNonNull( sessionFactory );
this.queryStatsMap = new StatsNamedContainer(
sessionFactory != null ?
sessionFactory.getSessionFactoryOptions().getQueryStatisticsMaxSize() :
Expand Down Expand Up @@ -208,20 +204,11 @@ public void setStatisticsEnabled(boolean b) {

@Override
public String[] getEntityNames() {
if ( sessionFactory == null ) {
return entityStatsMap.keysAsArray();
}
else {
return sessionFactory.getMetamodel().getAllEntityNames();
}
return sessionFactory.getMetamodel().getAllEntityNames();
}

@Override
public EntityStatisticsImpl getEntityStatistics(String entityName) {
if ( sessionFactory == null ) {
return null;
}

return entityStatsMap.getOrCompute(
entityName,
s -> new EntityStatisticsImpl( sessionFactory.getMetamodel().entityPersister( s ) )
Expand Down Expand Up @@ -321,20 +308,11 @@ public void entityCacheMiss(NavigableRole entityName, String regionName) {

@Override
public String[] getCollectionRoleNames() {
if ( sessionFactory == null ) {
return collectionStatsMap.keysAsArray();
}
else {
return sessionFactory.getMetamodel().getAllCollectionRoles();
}
return sessionFactory.getMetamodel().getAllCollectionRoles();
}

@Override
public CollectionStatisticsImpl getCollectionStatistics(String role) {
if ( sessionFactory == null ) {
return null;
}

return collectionStatsMap.getOrCompute(
role,
s -> new CollectionStatisticsImpl( sessionFactory.getMetamodel().collectionPersister( s ) )
Expand Down Expand Up @@ -423,10 +401,6 @@ public void collectionCacheMiss(NavigableRole collectionRole, String regionName)

@Override
public NaturalIdStatisticsImpl getNaturalIdStatistics(String rootEntityName) {
if ( sessionFactory == null ) {
return null;
}

return naturalIdQueryStatsMap.getOrCompute(
rootEntityName,
s -> {
Expand Down Expand Up @@ -569,19 +543,11 @@ public void naturalIdQueryExecuted(String rootEntityName, long time) {

@Override
public String[] getSecondLevelCacheRegionNames() {
if ( sessionFactory == null ) {
throw new IllegalStateException( "Statistics no longer associated with SessionFactory - cannot get (legacy) region names" );
}

return sessionFactory.getCache().getSecondLevelCacheRegionNames();
}

@Override
public CacheRegionStatisticsImpl getDomainDataRegionStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}

return l2CacheStatsMap.getOrCompute(
regionName,
s -> {
Expand Down Expand Up @@ -609,10 +575,6 @@ public CacheRegionStatisticsImpl getQueryRegionStatistics(String regionName) {
return existing;
}

if ( sessionFactory == null ) {
return null;
}

final QueryResultsCache regionAccess = sessionFactory.getCache()
.getQueryResultsCacheStrictly( regionName );
if ( regionAccess == null ) {
Expand All @@ -627,10 +589,6 @@ public CacheRegionStatisticsImpl getQueryRegionStatistics(String regionName) {

@Override
public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}

if ( ! sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() ) {
return null;
}
Expand Down Expand Up @@ -658,9 +616,6 @@ public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) {

@Override
public CacheRegionStatisticsImpl getSecondLevelCacheStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}
return getCacheRegionStatistics( sessionFactory.getCache().unqualifyRegionName( regionName ) );
}

Expand Down

0 comments on commit 8460cd8

Please sign in to comment.