Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,97 +5,14 @@
package org.hibernate;

/**
* A no-op implementation of SessionEventListener. Intended as a convenient base class for developing
* SessionEventListener implementations.
* A noop implementation of {@link SessionEventListener}.
* Intended as a convenient base class for developing
* {@code SessionEventListener} implementations.
*
* @author Steve Ebersole
*
* @deprecated Just implement {@link SessionEventListener} directly.
*/
@Deprecated(since = "7", forRemoval = true)
public class BaseSessionEventListener implements SessionEventListener {
@Override
public void transactionCompletion(boolean successful) {
}

@Override
public void jdbcConnectionAcquisitionStart() {
}

@Override
public void jdbcConnectionAcquisitionEnd() {
}

@Override
public void jdbcConnectionReleaseStart() {
}

@Override
public void jdbcConnectionReleaseEnd() {
}

@Override
public void jdbcPrepareStatementStart() {
}

@Override
public void jdbcPrepareStatementEnd() {
}

@Override
public void jdbcExecuteStatementStart() {
}

@Override
public void jdbcExecuteStatementEnd() {
}

@Override
public void jdbcExecuteBatchStart() {
}

@Override
public void jdbcExecuteBatchEnd() {
}

@Override
public void cachePutStart() {
}

@Override
public void cachePutEnd() {
}

@Override
public void cacheGetStart() {
}

@Override
public void cacheGetEnd(boolean hit) {
}

@Override
public void flushStart() {
}

@Override
public void flushEnd(int numberOfEntities, int numberOfCollections) {
}

@Override
public void partialFlushStart() {
}

@Override
public void partialFlushEnd(int numberOfEntities, int numberOfCollections) {
}

@Override
public void dirtyCalculationStart() {
}

@Override
public void dirtyCalculationEnd(boolean dirty) {
}

@Override
public void end() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* sessions may be registered using the configuration property
* {@value org.hibernate.cfg.AvailableSettings#AUTO_SESSION_EVENTS_LISTENER}.
* A new instance of the class will be created for each new session.
* <p>
* <em>This an incubating API, subject to change.</em>
*
* @apiNote This an incubating API, subject to change.
*
* @see org.hibernate.cfg.AvailableSettings#AUTO_SESSION_EVENTS_LISTENER
* @see SessionBuilder#eventListeners(SessionEventListener...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
import static org.hibernate.cfg.AvailableSettings.JDBC_TIME_ZONE;
import static org.hibernate.cfg.AvailableSettings.JPA_CALLBACKS_ENABLED;
import static org.hibernate.cfg.AvailableSettings.JTA_TRACK_BY_THREAD;
import static org.hibernate.cfg.AvailableSettings.LOG_SESSION_METRICS;
import static org.hibernate.cfg.AvailableSettings.MAX_FETCH_DEPTH;
import static org.hibernate.cfg.AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER;
import static org.hibernate.cfg.AvailableSettings.ORDER_INSERTS;
Expand Down Expand Up @@ -357,8 +356,7 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
? null
: strategySelector.selectStrategyImplementor( SessionEventListener.class, autoSessionEventsListenerName );

final boolean logSessionMetrics = configurationService.getSetting( LOG_SESSION_METRICS, BOOLEAN, statisticsEnabled );
this.baselineSessionEventsListenerBuilder = new BaselineSessionEventsListenerBuilder( logSessionMetrics, autoSessionEventsListener );
this.baselineSessionEventsListenerBuilder = new BaselineSessionEventsListenerBuilder( autoSessionEventsListener );

this.customEntityDirtinessStrategy = strategySelector.resolveDefaultableStrategy(
CustomEntityDirtinessStrategy.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public interface SecondLevelCacheLogger extends BasicLogger {
" You can disable this warning by setting '%2$s' to '%3$s'.",
id = NAMESPACE + 6
)
@SuppressWarnings( "unused" ) // used by hibernate-jcache
void missingCacheCreated(String regionName, String configurationPropertyToDisableKey, String configurationPropertyToDisableValue);

@LogMessage(level = WARN)
Expand All @@ -92,6 +93,7 @@ public interface SecondLevelCacheLogger extends BasicLogger {
" Update your configuration to rename cache [%2$s] to [%1$s].",
id = NAMESPACE + 7
)
@SuppressWarnings( "unused" ) // used by hibernate-jcache
void usingLegacyCacheName(String currentName, String legacyName);

@LogMessage(level = WARN)
Expand All @@ -100,6 +102,7 @@ public interface SecondLevelCacheLogger extends BasicLogger {
" Make sure your cache implementation supports JTA transactions.",
id = NAMESPACE + 8
)
@SuppressWarnings( "unused" ) // used by hibernate-jcache
void nonStandardSupportForAccessType(String key, String accessType, String regionName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public interface PersistenceSettings {
*
* @see #SCANNER
* @see org.hibernate.boot.archive.scan.spi.Scanner
* @see org.hibernate.boot.archive.scan.spi.AbstractScannerImpl
* @see org.hibernate.boot.MetadataBuilder#applyArchiveDescriptorFactory
*/
String SCANNER_ARCHIVE_INTERPRETER = "hibernate.archive.interpreter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@
*/
public interface SessionEventSettings {

/**
* Controls whether {@linkplain org.hibernate.stat.SessionStatistics session metrics}
* should be {@linkplain org.hibernate.engine.internal.StatisticalLoggingSessionEventListener
* logged} for any session in which statistics are being collected.
* <p>
* By default, logging of session metrics is disabled unless {@link StatisticsSettings#GENERATE_STATISTICS}
* is enabled.
*
* @settingDefault Defined by {@link StatisticsSettings#GENERATE_STATISTICS}
*/
String LOG_SESSION_METRICS = "hibernate.session.events.log";

/**
* Defines a default {@link org.hibernate.SessionEventListener} to be applied to
* newly-opened {@link org.hibernate.Session}s.
Expand Down Expand Up @@ -75,4 +63,12 @@ public interface SessionEventSettings {
* @since 5.2
*/
String SESSION_SCOPED_INTERCEPTOR = "hibernate.session_factory.session_scoped_interceptor";

/**
* @deprecated This setting is now ignored. Enable the log category
* {@code org.hibernate.session.metrics} to automatically
* collect and log session-level metrics.
*/
@Deprecated(since = "7", forRemoval = true)
String LOG_SESSION_METRICS = "hibernate.session.events.log";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
*/
package org.hibernate.engine.internal;

import org.hibernate.BaseSessionEventListener;
import org.hibernate.SessionEventListener;
import org.hibernate.internal.CoreMessageLogger;

import org.jboss.logging.Logger;
import static org.hibernate.internal.CoreLogging.messageLogger;

/**
* @see org.hibernate.cfg.AvailableSettings#LOG_SESSION_METRICS
* Tracks and logs certain session-level metrics.
*
* @author Steve Ebersole
*/
public class StatisticalLoggingSessionEventListener extends BaseSessionEventListener {
private static final Logger log = Logger.getLogger( StatisticalLoggingSessionEventListener.class );
public class StatisticalLoggingSessionEventListener implements SessionEventListener {
private static final CoreMessageLogger log = messageLogger( "org.hibernate.session.metrics" );

/**
* Used by SettingsFactory (in conjunction with stats being enabled) to determine whether to apply this listener
*
* @return {@code true} if logging is enabled for this listener.
*/
public static boolean isLoggingEnabled() {
return log.isInfoEnabled();
return log.isDebugEnabled();
}

// cumulative state ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -274,21 +275,8 @@ public void partialFlushEnd(int numberOfEntities, int numberOfCollections) {

@Override
public void end() {
if ( log.isInfoEnabled() ) {
log.infof(
"Session Metrics {\n" +
" %s nanoseconds spent acquiring %s JDBC connections;\n" +
" %s nanoseconds spent releasing %s JDBC connections;\n" +
" %s nanoseconds spent preparing %s JDBC statements;\n" +
" %s nanoseconds spent executing %s JDBC statements;\n" +
" %s nanoseconds spent executing %s JDBC batches;\n" +
" %s nanoseconds spent performing %s L2C puts;\n" +
" %s nanoseconds spent performing %s L2C hits;\n" +
" %s nanoseconds spent performing %s L2C misses;\n" +
" %s nanoseconds spent executing %s flushes (flushing a total of %s entities and %s collections);\n" +
" %s nanoseconds spent executing %s pre-partial-flushes;\n" +
" %s nanoseconds spent executing %s partial-flushes (flushing a total of %s entities and %s collections)\n" +
"}",
if ( isLoggingEnabled() ) {
log.sessionMetrics(
jdbcConnectionAcquisitionTime,
jdbcConnectionAcquisitionCount,
jdbcConnectionReleaseTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@ public class BaselineSessionEventsListenerBuilder {

private static final SessionEventListener[] EMPTY = new SessionEventListener[0];

private final boolean logSessionMetrics;
private final Class<? extends SessionEventListener> autoListener;

public BaselineSessionEventsListenerBuilder(
boolean logSessionMetrics,
Class<? extends SessionEventListener> autoListener) {
this.logSessionMetrics = logSessionMetrics;
public BaselineSessionEventsListenerBuilder(Class<? extends SessionEventListener> autoListener) {
this.autoListener = autoListener;
}

@SuppressWarnings("unused")
public boolean isLogSessionMetrics() {
return logSessionMetrics;
}

@SuppressWarnings("unused")
public Class<? extends SessionEventListener> getAutoListener() {
return autoListener;
Expand All @@ -48,24 +39,26 @@ public List<SessionEventListener> buildBaselineList() {
}

public SessionEventListener[] buildBaseline() {
final boolean addStats = logSessionMetrics && StatisticalLoggingSessionEventListener.isLoggingEnabled();
final boolean addAutoListener = autoListener != null;
final SessionEventListener[] arr;
if ( addStats && addAutoListener ) {
arr = new SessionEventListener[2];
arr[0] = buildStatsListener();
arr[1] = buildAutoListener( autoListener );
}
else if ( !addStats && addAutoListener ) {
arr = new SessionEventListener[1];
arr[0] = buildAutoListener( autoListener );
}
else if ( addStats && !addAutoListener ) {
arr = new SessionEventListener[1];
arr[0] = buildStatsListener();
if ( autoListener != null ) {
if ( StatisticalLoggingSessionEventListener.isLoggingEnabled() ) {
arr = new SessionEventListener[2];
arr[0] = buildStatsListener();
arr[1] = buildAutoListener( autoListener );
}
else {
arr = new SessionEventListener[1];
arr[0] = buildAutoListener( autoListener );
}
}
else {//if ( !addStats && !addAutoListener )
arr = EMPTY;
else {
if ( StatisticalLoggingSessionEventListener.isLoggingEnabled() ) {
arr = new SessionEventListener[1];
arr[0] = buildStatsListener();
}
else {
arr = EMPTY;
}
}
return arr;
}
Expand All @@ -76,7 +69,7 @@ private static SessionEventListener buildAutoListener(final Class<? extends Sess
}
catch (Exception e) {
throw new HibernateException(
"Unable to instantiate specified auto SessionEventListener : " + autoListener.getName(),
"Unable to instantiate specified auto SessionEventListener: " + autoListener.getName(),
e
);
}
Expand Down
Loading
Loading