org.hibernate.tuple.component.PojoComponentTuplizer Maven / Gradle / Ivy
//$Id: PojoComponentTuplizer.java 9619 2006-03-15 00:12:47Z [email protected] $
package org.hibernate.tuple.component;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.BasicProxyFactory;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.property.Getter;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter;
import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.util.ReflectHelper;
/**
* A {@link ComponentTuplizer} specific to the pojo entity mode.
*
* @author Gavin King
* @author Steve Ebersole
*/
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
private final Class componentClass;
private ReflectionOptimizer optimizer;
private final Getter parentGetter;
private final Setter parentSetter;
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];
for ( int i = 0; i < propertySpan; i++ ) {
getterNames[i] = getters[i].getMethodName();
setterNames[i] = setters[i].getMethodName();
propTypes[i] = getters[i].getReturnType();
}
final String parentPropertyName = component.getParentProperty();
if ( parentPropertyName == null ) {
parentSetter = null;
parentGetter = null;
}
else {
PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( null );
parentSetter = pa.getSetter( componentClass, parentPropertyName );
parentGetter = pa.getGetter( componentClass, parentPropertyName );
}
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
optimizer = null;
}
else {
// TODO: here is why we need to make bytecode provider global :(
// TODO : again, fix this after HHH-1907 is complete
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
componentClass, getterNames, setterNames, propTypes
);
}
}
public Class getMappedClass() {
return componentClass;
}
public Object[] getPropertyValues(Object component) throws HibernateException {
if ( component == BackrefPropertyAccessor.UNKNOWN ) {
return new Object[ propertySpan ];
}
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
return optimizer.getAccessOptimizer().getPropertyValues( component );
}
else {
return super.getPropertyValues(component);
}
}
public void setPropertyValues(Object component, Object[] values) throws HibernateException {
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
optimizer.getAccessOptimizer().setPropertyValues( component, values );
}
else {
super.setPropertyValues(component, values);
}
}
public Object getParent(Object component) {
return parentGetter.get( component );
}
public boolean hasParentProperty() {
return parentGetter!=null;
}
public boolean isMethodOf(Method method) {
for ( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy