Permalink
Browse files

HHH-7586 Re-architect SimpleValue's reflection for dynamic descriptors

  • Loading branch information...
brmeyer
brmeyer committed Sep 11, 2012
1 parent 69bccca commit 7ce07642cbfa7d1849933da63c7707044988639d
@@ -42,7 +42,6 @@
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;
@@ -59,8 +58,10 @@
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;
@@ -125,28 +126,23 @@ protected Size getDictatedSize() {
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();
@@ -279,7 +275,7 @@ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescrip
}
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 {
@@ -425,7 +421,7 @@ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescrip
}
};
- return getExtractor(options).extract(
+ return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor ).extract(
statement,
startIndex,
options
@@ -452,6 +448,6 @@ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescrip
}
};
- return getExtractor(options).extract( statement, paramNames, options );
+ return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor ).extract( statement, paramNames, options );
}
}
@@ -28,9 +28,6 @@
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 @@
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 SerializableToBlobType() {
* {@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 );
}
}

0 comments on commit 7ce0764

Please sign in to comment.