From fb0255a87a8928ed21748c4522cc176e4ecfaa2d Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 28 Nov 2011 15:35:48 +0000 Subject: [PATCH] HHH-6858 non-intrusive performance improvements --- .../internal/TransactionCoordinatorImpl.java | 1 - .../internal/AbstractFlushingEventListener.java | 14 +++++++------- .../java/org/hibernate/internal/SessionImpl.java | 5 ++--- .../internal/util/compare/EqualsHelper.java | 4 ++-- .../tuple/entity/AbstractEntityTuplizer.java | 3 ++- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java index d92138f1d3..e8d896b1fa 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java @@ -260,7 +260,6 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator { } public void pulse() { - LOG.trace( "Starting transaction coordinator pulse" ); if ( transactionFactory().compatibleWithJtaSynchronization() ) { // the configured transaction strategy says it supports callbacks via JTA synchronization, so attempt to // register JTA synchronization if possible diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java index db3a4a0f46..5d56bef640 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java @@ -45,7 +45,6 @@ import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; -import org.hibernate.event.service.spi.EventListenerGroup; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventType; @@ -213,6 +212,12 @@ public abstract class AbstractFlushingEventListener implements Serializable { // It is safe because of how IdentityMap implements entrySet() final EventSource source = event.getSession(); + final Iterable flushListeners = source + .getFactory() + .getServiceRegistry() + .getService( EventListenerRegistry.class ) + .getEventListenerGroup( EventType.FLUSH_ENTITY ) + .listeners(); final Map.Entry[] list = IdentityMap.concurrentEntries( source.getPersistenceContext().getEntityEntries() ); final int size = list.length; @@ -226,12 +231,7 @@ public abstract class AbstractFlushingEventListener implements Serializable { if ( status != Status.LOADING && status != Status.GONE ) { final FlushEntityEvent entityEvent = new FlushEntityEvent( source, me.getKey(), entry ); - final EventListenerGroup listenerGroup = source - .getFactory() - .getServiceRegistry() - .getService( EventListenerRegistry.class ) - .getEventListenerGroup( EventType.FLUSH_ENTITY ); - for ( FlushEntityEventListener listener : listenerGroup.listeners() ) { + for ( FlushEntityEventListener listener : flushListeners ) { listener.onFlushEntity( entityEvent ); } } 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 a0ae6315bb..a6f1783958 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -77,7 +77,6 @@ import org.hibernate.UnknownProfileException; import org.hibernate.UnresolvableObjectException; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.internal.StatefulPersistenceContext; -import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.query.spi.FilterQueryPlan; import org.hibernate.engine.query.spi.HQLQueryPlan; @@ -94,7 +93,6 @@ import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; -import org.hibernate.engine.transaction.spi.TransactionContext; import org.hibernate.engine.transaction.spi.TransactionCoordinator; import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.event.service.spi.EventListenerGroup; @@ -1078,8 +1076,9 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc if ( persistenceContext.getCascadeLevel() > 0 ) { throw new HibernateException("Flush during cascade is dangerous"); } + FlushEvent flushEvent = new FlushEvent( this ); for ( FlushEventListener listener : listeners( EventType.FLUSH ) ) { - listener.onFlush( new FlushEvent( this ) ); + listener.onFlush( flushEvent ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java index 9b88188da2..c937d94a9c 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java @@ -30,8 +30,8 @@ package org.hibernate.internal.util.compare; */ public final class EqualsHelper { - public static boolean equals(Object x, Object y) { - return x==y || ( x!=null && y!=null && x.equals(y) ); + public static boolean equals(final Object x, final Object y) { + return x == y || ( x != null && y != null && x.equals( y ) ); } private EqualsHelper() {} diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java index 58b0d335bd..911abb3f1d 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java @@ -459,6 +459,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer { final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); final Type[] subTypes = virtualIdComponent.getSubtypes(); final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); + final Iterable persistEventListeners = persistEventListeners( session ); final int length = subTypes.length; for ( int i = 0 ; i < length; i++ ) { if ( propertyValues[i] == null ) { @@ -484,7 +485,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer { else { LOG.debug( "Performing implicit derived identity cascade" ); final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session ); - for ( PersistEventListener listener : persistEventListeners( session ) ) { + for ( PersistEventListener listener : persistEventListeners ) { listener.onPersist( event ); } pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );