HHH-11563 - Avoid calling multiple times org.hibernate.mapping.Component#getComponentClass() during the PojoComponentTuplizer creation
This commit is contained in:
parent
f120cd26df
commit
54cd8eb0a9
|
@ -50,7 +50,11 @@ public class PojoInstantiator implements Instantiator, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) {
|
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.isAbstract = ReflectHelper.isAbstractClass( mappedClass );
|
||||||
this.optimizer = optimizer;
|
this.optimizer = optimizer;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
|
||||||
protected abstract Setter buildSetter(Component component, Property prop);
|
protected abstract Setter buildSetter(Component component, Property prop);
|
||||||
|
|
||||||
protected AbstractComponentTuplizer(Component component) {
|
protected AbstractComponentTuplizer(Component component) {
|
||||||
|
setComponentClass( component );
|
||||||
propertySpan = component.getPropertySpan();
|
propertySpan = component.getPropertySpan();
|
||||||
getters = new Getter[propertySpan];
|
getters = new Getter[propertySpan];
|
||||||
setters = new Setter[propertySpan];
|
setters = new Setter[propertySpan];
|
||||||
|
@ -102,4 +103,8 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
|
||||||
public Getter getGetter(int i) {
|
public Getter getGetter(int i) {
|
||||||
return getters[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){
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
|
||||||
import org.hibernate.property.access.spi.Getter;
|
import org.hibernate.property.access.spi.Getter;
|
||||||
import org.hibernate.property.access.spi.PropertyAccess;
|
import org.hibernate.property.access.spi.PropertyAccess;
|
||||||
import org.hibernate.property.access.spi.Setter;
|
import org.hibernate.property.access.spi.Setter;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.tuple.Instantiator;
|
import org.hibernate.tuple.Instantiator;
|
||||||
import org.hibernate.tuple.PojoInstantiator;
|
import org.hibernate.tuple.PojoInstantiator;
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ import org.hibernate.tuple.PojoInstantiator;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||||
private final Class componentClass;
|
private Class componentClass;
|
||||||
private ReflectionOptimizer optimizer;
|
private ReflectionOptimizer optimizer;
|
||||||
private final Getter parentGetter;
|
private final Getter parentGetter;
|
||||||
private final Setter parentSetter;
|
private final Setter parentSetter;
|
||||||
|
@ -41,8 +40,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||||
public PojoComponentTuplizer(Component component) {
|
public PojoComponentTuplizer(Component component) {
|
||||||
super( component );
|
super( component );
|
||||||
|
|
||||||
this.componentClass = component.getComponentClass();
|
|
||||||
|
|
||||||
String[] getterNames = new String[propertySpan];
|
String[] getterNames = new String[propertySpan];
|
||||||
String[] setterNames = new String[propertySpan];
|
String[] setterNames = new String[propertySpan];
|
||||||
Class[] propTypes = new Class[propertySpan];
|
Class[] propTypes = new Class[propertySpan];
|
||||||
|
@ -58,8 +55,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||||
parentGetter = null;
|
parentGetter = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final ServiceRegistry serviceRegistry =
|
|
||||||
component.getMetadata().getMetadataBuildingOptions().getServiceRegistry();
|
|
||||||
final PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
|
final PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
|
||||||
componentClass,
|
componentClass,
|
||||||
parentPropertyName
|
parentPropertyName
|
||||||
|
@ -128,31 +123,36 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Instantiator buildInstantiator(Component component) {
|
protected Instantiator buildInstantiator(Component component) {
|
||||||
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) {
|
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( this.componentClass ) ) {
|
||||||
return new ProxiedInstantiator( component );
|
return new ProxiedInstantiator( this.componentClass );
|
||||||
}
|
}
|
||||||
if ( optimizer == null ) {
|
if ( optimizer == null ) {
|
||||||
return new PojoInstantiator( component, null );
|
return new PojoInstantiator( this.componentClass, null );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() );
|
return new PojoInstantiator( this.componentClass, optimizer.getInstantiationOptimizer() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Getter buildGetter(Component component, Property prop) {
|
protected Getter buildGetter(Component component, Property prop) {
|
||||||
return prop.getGetter( component.getComponentClass() );
|
return prop.getGetter( this.componentClass );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Setter buildSetter(Component component, Property prop) {
|
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 static class ProxiedInstantiator implements Instantiator {
|
||||||
private final Class proxiedClass;
|
private final Class proxiedClass;
|
||||||
private final BasicProxyFactory factory;
|
private final BasicProxyFactory factory;
|
||||||
|
|
||||||
public ProxiedInstantiator(Component component) {
|
public ProxiedInstantiator(Class componentClass) {
|
||||||
proxiedClass = component.getComponentClass();
|
proxiedClass = componentClass;
|
||||||
if ( proxiedClass.isInterface() ) {
|
if ( proxiedClass.isInterface() ) {
|
||||||
factory = Environment.getBytecodeProvider()
|
factory = Environment.getBytecodeProvider()
|
||||||
.getProxyFactoryFactory()
|
.getProxyFactoryFactory()
|
||||||
|
|
Loading…
Reference in New Issue