HHH-7586 Re-architect SimpleValue's reflection for dynamic descriptors
This commit is contained in:
parent
95047afc63
commit
b9aeb998a7
|
@ -41,7 +41,6 @@ import org.hibernate.engine.spi.SessionImplementor;
|
|||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.metamodel.relational.Size;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.MutabilityPlan;
|
||||
|
@ -58,8 +57,10 @@ public abstract class AbstractStandardBasicType<T>
|
|||
private static final Size DEFAULT_SIZE = new Size( 19, 2, 255, Size.LobMultiplier.NONE ); // to match legacy behavior
|
||||
private final Size dictatedSize = new Size();
|
||||
|
||||
private final SqlTypeDescriptor sqlTypeDescriptor;
|
||||
private final JavaTypeDescriptor<T> javaTypeDescriptor;
|
||||
// Don't use final here. Need to initialize after-the-fact
|
||||
// by DynamicParameterizedTypes.
|
||||
private SqlTypeDescriptor sqlTypeDescriptor;
|
||||
private JavaTypeDescriptor<T> javaTypeDescriptor;
|
||||
|
||||
public AbstractStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
|
||||
this.sqlTypeDescriptor = sqlTypeDescriptor;
|
||||
|
@ -124,28 +125,23 @@ public abstract class AbstractStandardBasicType<T>
|
|||
return dictatedSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is necessary due to legacy SimpleValue and DynamicParameterizedType
|
||||
* usage. Entity types come in *after* the descriptors have been
|
||||
* intialized, so this is used to over-ride as necessary.
|
||||
*
|
||||
* @return ValueExtractor
|
||||
*/
|
||||
// TODO: Remove (or make private) after HHH-7586.
|
||||
protected ValueExtractor<T> getExtractor(WrapperOptions options) {
|
||||
return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor );
|
||||
}
|
||||
|
||||
|
||||
// final implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public final JavaTypeDescriptor<T> getJavaTypeDescriptor() {
|
||||
return javaTypeDescriptor;
|
||||
}
|
||||
|
||||
public final void setJavaTypeDescriptor( JavaTypeDescriptor<T> javaTypeDescriptor ) {
|
||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||
}
|
||||
|
||||
public final SqlTypeDescriptor getSqlTypeDescriptor() {
|
||||
return sqlTypeDescriptor;
|
||||
}
|
||||
|
||||
public final void setSqlTypeDescriptor( SqlTypeDescriptor sqlTypeDescriptor ) {
|
||||
this.sqlTypeDescriptor = sqlTypeDescriptor;
|
||||
}
|
||||
|
||||
public final Class getReturnedClass() {
|
||||
return javaTypeDescriptor.getJavaTypeClass();
|
||||
|
@ -278,7 +274,7 @@ public abstract class AbstractStandardBasicType<T>
|
|||
}
|
||||
|
||||
protected final T nullSafeGet(ResultSet rs, String name, WrapperOptions options) throws SQLException {
|
||||
return getExtractor(options).extract( rs, name, options );
|
||||
return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor ).extract( rs, name, options );
|
||||
}
|
||||
|
||||
public Object get(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException {
|
||||
|
|
|
@ -28,9 +28,6 @@ import java.util.Properties;
|
|||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.SerializableTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.BlobTypeDescriptor;
|
||||
import org.hibernate.usertype.DynamicParameterizedType;
|
||||
|
@ -44,14 +41,10 @@ public class SerializableToBlobType<T extends Serializable> extends AbstractSing
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JavaTypeDescriptor<T> javaTypeDescriptor = new SerializableTypeDescriptor( Serializable.class );
|
||||
|
||||
/**
|
||||
* @param sqlTypeDescriptor
|
||||
* @param javaTypeDescriptor
|
||||
*/
|
||||
// TODO: After HHH-7586, this should eventually use the actual T class.
|
||||
// But, for now, just use Serializable.
|
||||
public SerializableToBlobType() {
|
||||
super( BlobTypeDescriptor.DEFAULT, new SerializableTypeDescriptor( Serializable.class ) );
|
||||
}
|
||||
|
@ -60,39 +53,27 @@ public class SerializableToBlobType<T extends Serializable> extends AbstractSing
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
public String getName() {
|
||||
return null;
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// TODO: This method (and DynamicParameterizedType) should go away after HHH-7586.
|
||||
public void setParameterValues(Properties parameters) {
|
||||
ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE );
|
||||
if ( reader != null ) {
|
||||
javaTypeDescriptor = new SerializableTypeDescriptor<T>( reader.getReturnedClass() );
|
||||
setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( reader.getReturnedClass() ) );
|
||||
} else {
|
||||
String className = parameters.getProperty( CLASS_NAME );
|
||||
if ( className == null ) {
|
||||
throw new MappingException( "No class name defined for type: " + SerializableToBlobType.class.getName() );
|
||||
}
|
||||
try {
|
||||
javaTypeDescriptor = new SerializableTypeDescriptor<T>( ReflectHelper.classForName( className ) );
|
||||
setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( ReflectHelper.classForName( className ) ) );
|
||||
} catch ( ClassNotFoundException e ) {
|
||||
throw new MappingException( "Unable to load class from " + CLASS_NAME + " parameter", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
// TODO: Remove after HHH-7586.
|
||||
protected ValueExtractor<T> getExtractor(WrapperOptions options) {
|
||||
return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue