From cc39f54717f9c6761a108dc7c14ab77533cf8766 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 20 Aug 2019 21:18:38 +0100 Subject: [PATCH] HHH-13565 Micro cleanup of Trace level checks --- .../org/hibernate/internal/SessionImpl.java | 13 +++++++---- .../internal/ResultSetProcessorImpl.java | 23 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 6743b4426c..19130390b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -814,7 +814,9 @@ public final class SessionImpl public void delete(String entityName, Object object, boolean isCascadeDeleteEnabled, Set transientEntities) throws HibernateException { checkOpenOrWaitingForAutoClose(); - if ( log.isTraceEnabled() && persistenceContext.isRemovingOrphanBeforeUpates() ) { + final boolean removingOrphanBeforeUpates = persistenceContext.isRemovingOrphanBeforeUpates(); + final boolean traceEnabled = log.isTraceEnabled(); + if ( traceEnabled && removingOrphanBeforeUpates ) { logRemoveOrphanBeforeUpdates( "before continuing", entityName, object ); } fireDelete( @@ -822,12 +824,12 @@ public final class SessionImpl entityName, object, isCascadeDeleteEnabled, - persistenceContext.isRemovingOrphanBeforeUpates(), + removingOrphanBeforeUpates, this ), transientEntities ); - if ( log.isTraceEnabled() && persistenceContext.isRemovingOrphanBeforeUpates() ) { + if ( traceEnabled && removingOrphanBeforeUpates ) { logRemoveOrphanBeforeUpdates( "after continuing", entityName, object ); } } @@ -836,7 +838,8 @@ public final class SessionImpl public void removeOrphanBeforeUpdates(String entityName, Object child) { // TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task // ordering is improved. - if ( log.isTraceEnabled() ) { + final boolean traceEnabled = log.isTraceEnabled(); + if ( traceEnabled ) { logRemoveOrphanBeforeUpdates( "begin", entityName, child ); } persistenceContext.beginRemoveOrphanBeforeUpdates(); @@ -846,7 +849,7 @@ public final class SessionImpl } finally { persistenceContext.endRemoveOrphanBeforeUpdates(); - if ( log.isTraceEnabled() ) { + if ( traceEnabled ) { logRemoveOrphanBeforeUpdates( "end", entityName, child ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java index c710b2e01c..81c32a0fae 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java @@ -82,13 +82,20 @@ public class ResultSetProcessorImpl implements ResultSetProcessor { handlePotentiallyEmptyCollectionRootReturns( loadPlan, queryParameters.getCollectionKeys(), resultSet, session ); + final boolean traceEnabled = LOG.isTraceEnabled(); final int maxRows; + final List loadResults; final RowSelection selection = queryParameters.getRowSelection(); if ( LimitHelper.hasMaxRows( selection ) ) { maxRows = selection.getMaxRows(); - LOG.tracef( "Limiting ResultSet processing to just %s rows", maxRows ); + if ( traceEnabled ) { + LOG.tracef( "Limiting ResultSet processing to just %s rows", maxRows ); + } + int sizeHint = maxRows < 50 ? maxRows : 50; + loadResults = new ArrayList( sizeHint ); } else { + loadResults = new ArrayList(); maxRows = Integer.MAX_VALUE; } @@ -109,12 +116,14 @@ public class ResultSetProcessorImpl implements ResultSetProcessor { hadSubselectFetches ); - final List loadResults = new ArrayList(); - - LOG.trace( "Processing result set" ); + if ( traceEnabled ) { + LOG.trace( "Processing result set" ); + } int count; for ( count = 0; count < maxRows && resultSet.next(); count++ ) { - LOG.debugf( "Starting ResultSet row #%s", count ); + if ( traceEnabled ) { + LOG.tracef( "Starting ResultSet row #%s", count ); + } Object logicalRow = rowReader.readRow( resultSet, context ); @@ -125,7 +134,9 @@ public class ResultSetProcessorImpl implements ResultSetProcessor { context.finishUpRow(); } - LOG.tracev( "Done processing result set ({0} rows)", count ); + if ( traceEnabled ) { + LOG.tracev( "Done processing result set ({0} rows)", count ); + } rowReader.finishUp( context, afterLoadActionList ); context.wrapUp();