HHH-11563 - Avoid calling multiple times org.hibernate.mapping.Component#getComponentClass() during the PojoComponentTuplizer creation

This commit is contained in:
Andrea Boriero 2017-03-09 11:52:25 +00:00
parent f120cd26df
commit 54cd8eb0a9
3 changed files with 24 additions and 15 deletions

View File

@ -50,7 +50,11 @@ public class PojoInstantiator implements Instantiator, Serializable {
}
public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) {
this.mappedClass = component.getComponentClass();
this( component.getComponentClass(), optimizer );
}
public PojoInstantiator(Class componentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) {
this.mappedClass = componentClass;
this.isAbstract = ReflectHelper.isAbstractClass( mappedClass );
this.optimizer = optimizer;

View File

@ -34,6 +34,7 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
protected abstract Setter buildSetter(Component component, Property prop);
protected AbstractComponentTuplizer(Component component) {
setComponentClass( component );
propertySpan = component.getPropertySpan();
getters = new Getter[propertySpan];
setters = new Setter[propertySpan];
@ -102,4 +103,8 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
public Getter getGetter(int i) {
return getters[i];
}
// It should be an abstract method but not sure if this can break any customer extension
protected void setComponentClass(Component component){
}
}

View File

@ -22,7 +22,6 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator;
@ -33,7 +32,7 @@ import org.hibernate.tuple.PojoInstantiator;
* @author Steve Ebersole
*/
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
private final Class componentClass;
private Class componentClass;
private ReflectionOptimizer optimizer;
private final Getter parentGetter;
private final Setter parentSetter;
@ -41,8 +40,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
public PojoComponentTuplizer(Component component) {
super( component );
this.componentClass = component.getComponentClass();
String[] getterNames = new String[propertySpan];
String[] setterNames = new String[propertySpan];
Class[] propTypes = new Class[propertySpan];
@ -58,8 +55,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
parentGetter = null;
}
else {
final ServiceRegistry serviceRegistry =
component.getMetadata().getMetadataBuildingOptions().getServiceRegistry();
final PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
componentClass,
parentPropertyName
@ -128,31 +123,36 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
}
protected Instantiator buildInstantiator(Component component) {
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) {
return new ProxiedInstantiator( component );
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( this.componentClass ) ) {
return new ProxiedInstantiator( this.componentClass );
}
if ( optimizer == null ) {
return new PojoInstantiator( component, null );
return new PojoInstantiator( this.componentClass, null );
}
else {
return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() );
return new PojoInstantiator( this.componentClass, optimizer.getInstantiationOptimizer() );
}
}
protected Getter buildGetter(Component component, Property prop) {
return prop.getGetter( component.getComponentClass() );
return prop.getGetter( this.componentClass );
}
protected Setter buildSetter(Component component, Property prop) {
return prop.getSetter( component.getComponentClass() );
return prop.getSetter( this.componentClass );
}
@Override
protected void setComponentClass(Component component) {
this.componentClass = component.getComponentClass();
}
private static class ProxiedInstantiator implements Instantiator {
private final Class proxiedClass;
private final BasicProxyFactory factory;
public ProxiedInstantiator(Component component) {
proxiedClass = component.getComponentClass();
public ProxiedInstantiator(Class componentClass) {
proxiedClass = componentClass;
if ( proxiedClass.isInterface() ) {
factory = Environment.getBytecodeProvider()
.getProxyFactoryFactory()