HHH-9001 Unnecessary Stack object being allocated in org.hibernate.engine.internal.Cascade

This commit is contained in:
Sanne Grinovero 2014-02-26 00:01:31 +00:00 committed by Brett Meyer
parent 8f52c614c3
commit 7b3f1408f3
2 changed files with 6 additions and 10 deletions

View File

@ -27,7 +27,6 @@ import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Stack;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
@ -59,6 +58,8 @@ import org.jboss.logging.Logger;
*/ */
public final class Cascade { public final class Cascade {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Cascade.class.getName());
/** /**
* A cascade point that occurs just after the insertion of the parent entity and * A cascade point that occurs just after the insertion of the parent entity and
* just before deletion * just before deletion
@ -102,9 +103,7 @@ public final class Cascade {
*/ */
public static final int BEFORE_MERGE = 0; public static final int BEFORE_MERGE = 0;
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Cascade.class.getName()); private int componentPathStackDepth = 0;
private int cascadeTo; private int cascadeTo;
private EventSource eventSource; private EventSource eventSource;
private CascadingAction action; private CascadingAction action;
@ -230,7 +229,7 @@ public final class Cascade {
final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent ); final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
if ( entry != null && entry.getStatus() != Status.SAVING ) { if ( entry != null && entry.getStatus() != Status.SAVING ) {
final Object loadedValue; final Object loadedValue;
if ( componentPathStack.isEmpty() ) { if ( componentPathStackDepth == 0 ) {
// association defined on entity // association defined on entity
loadedValue = entry.getLoadedValue( propertyName ); loadedValue = entry.getLoadedValue( propertyName );
} }
@ -298,8 +297,6 @@ public final class Cascade {
return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne(); return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne();
} }
private Stack componentPathStack = new Stack();
private boolean cascadeAssociationNow(AssociationType associationType) { private boolean cascadeAssociationNow(AssociationType associationType) {
return associationType.getForeignKeyDirection().cascadeNow(cascadeTo); return associationType.getForeignKeyDirection().cascadeNow(cascadeTo);
} }
@ -310,7 +307,7 @@ public final class Cascade {
final CompositeType componentType, final CompositeType componentType,
final String componentPropertyName, final String componentPropertyName,
final Object anything) { final Object anything) {
componentPathStack.push( componentPropertyName ); componentPathStackDepth++;
Object[] children = componentType.getPropertyValues( child, eventSource ); Object[] children = componentType.getPropertyValues( child, eventSource );
Type[] types = componentType.getSubtypes(); Type[] types = componentType.getSubtypes();
for ( int i=0; i<types.length; i++ ) { for ( int i=0; i<types.length; i++ ) {
@ -328,7 +325,7 @@ public final class Cascade {
); );
} }
} }
componentPathStack.pop(); componentPathStackDepth--;
} }
private void cascadeAssociation( private void cascadeAssociation(

View File

@ -25,7 +25,6 @@
package org.hibernate.hql.internal.ast.util; package org.hibernate.hql.internal.ast.util;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
import java.util.Stack;
import antlr.collections.AST; import antlr.collections.AST;