HHH-13948 EnhancedSetterImpl should define writeReplace
This commit is contained in:
parent
2af37a788f
commit
d201b0b22d
|
@ -6,14 +6,16 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property.access.spi;
|
package org.hibernate.property.access.spi;
|
||||||
|
|
||||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||||
import org.hibernate.engine.spi.CompositeOwner;
|
import org.hibernate.engine.spi.CompositeOwner;
|
||||||
import org.hibernate.engine.spi.CompositeTracker;
|
import org.hibernate.engine.spi.CompositeTracker;
|
||||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.property.access.internal.AbstractFieldSerialForm;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized Setter implementation for handling setting values into
|
* A specialized Setter implementation for handling setting values into
|
||||||
|
@ -25,9 +27,9 @@ import java.lang.reflect.Field;
|
||||||
* @author Luis Barreiro
|
* @author Luis Barreiro
|
||||||
*/
|
*/
|
||||||
public class EnhancedSetterImpl extends SetterFieldImpl {
|
public class EnhancedSetterImpl extends SetterFieldImpl {
|
||||||
|
|
||||||
private final String propertyName;
|
private final String propertyName;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public EnhancedSetterImpl(Class containerClass, String propertyName, Field field) {
|
public EnhancedSetterImpl(Class containerClass, String propertyName, Field field) {
|
||||||
super( containerClass, propertyName, field );
|
super( containerClass, propertyName, field );
|
||||||
this.propertyName = propertyName;
|
this.propertyName = propertyName;
|
||||||
|
@ -46,9 +48,34 @@ public class EnhancedSetterImpl extends SetterFieldImpl {
|
||||||
// This marks the attribute as initialized, so it doesn't get lazy loaded afterwards
|
// This marks the attribute as initialized, so it doesn't get lazy loaded afterwards
|
||||||
if ( target instanceof PersistentAttributeInterceptable ) {
|
if ( target instanceof PersistentAttributeInterceptable ) {
|
||||||
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) target ).$$_hibernate_getInterceptor();
|
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) target ).$$_hibernate_getInterceptor();
|
||||||
if ( interceptor != null && interceptor instanceof LazyAttributeLoadingInterceptor ) {
|
if ( interceptor instanceof BytecodeLazyAttributeInterceptor ) {
|
||||||
interceptor.attributeInitialized( propertyName );
|
( (BytecodeLazyAttributeInterceptor) interceptor ).attributeInitialized( propertyName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// serialization
|
||||||
|
|
||||||
|
private Object writeReplace() {
|
||||||
|
return new SerialForm( getContainerClass(), propertyName, getField() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
private static class SerialForm extends AbstractFieldSerialForm implements Serializable {
|
||||||
|
private final Class containerClass;
|
||||||
|
private final String propertyName;
|
||||||
|
|
||||||
|
|
||||||
|
private SerialForm(Class containerClass, String propertyName, Field field) {
|
||||||
|
super( field );
|
||||||
|
this.containerClass = containerClass;
|
||||||
|
this.propertyName = propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object readResolve() {
|
||||||
|
return new EnhancedSetterImpl( containerClass, propertyName, resolveField() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property.access.spi;
|
package org.hibernate.property.access.spi;
|
||||||
|
|
||||||
import java.io.ObjectStreamException;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -35,6 +34,18 @@ public class SetterFieldImpl implements Setter {
|
||||||
this.setterMethod = ReflectHelper.setterMethodOrNull( containerClass, propertyName, field.getType() );
|
this.setterMethod = ReflectHelper.setterMethodOrNull( containerClass, propertyName, field.getType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class getContainerClass() {
|
||||||
|
return containerClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPropertyName() {
|
||||||
|
return propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Field getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(Object target, Object value, SessionFactoryImplementor factory) {
|
public void set(Object target, Object value, SessionFactoryImplementor factory) {
|
||||||
try {
|
try {
|
||||||
|
@ -83,7 +94,7 @@ public class SetterFieldImpl implements Setter {
|
||||||
return setterMethod;
|
return setterMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object writeReplace() throws ObjectStreamException {
|
private Object writeReplace() {
|
||||||
return new SerialForm( containerClass, propertyName, field );
|
return new SerialForm( containerClass, propertyName, field );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue