HHH-4698 - Better handling of JPA criteria expressions
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18312 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
24cbb2df3c
commit
a900ee8928
|
@ -39,6 +39,16 @@ public class ValueConverter {
|
||||||
public T apply(Object value);
|
public T apply(Object value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNumeric(Class type) {
|
||||||
|
return Number.class.isAssignableFrom( type )
|
||||||
|
|| Byte.TYPE.equals( type )
|
||||||
|
|| Short.TYPE.equals( type )
|
||||||
|
|| Integer.TYPE.equals( type )
|
||||||
|
|| Long.TYPE.isAssignableFrom( type )
|
||||||
|
|| Float.TYPE.equals( type )
|
||||||
|
|| Double.TYPE.isAssignableFrom( type );
|
||||||
|
}
|
||||||
|
|
||||||
public static class ByteConversion implements Conversion<Byte> {
|
public static class ByteConversion implements Conversion<Byte> {
|
||||||
public static final ByteConversion INSTANCE = new ByteConversion();
|
public static final ByteConversion INSTANCE = new ByteConversion();
|
||||||
@SuppressWarnings({ "UnnecessaryBoxing" })
|
@SuppressWarnings({ "UnnecessaryBoxing" })
|
||||||
|
@ -185,10 +195,14 @@ public class ValueConverter {
|
||||||
|
|
||||||
private static IllegalArgumentException unknownConversion(Object value, Class type) {
|
private static IllegalArgumentException unknownConversion(Object value, Class type) {
|
||||||
return new IllegalArgumentException(
|
return new IllegalArgumentException(
|
||||||
"Unaware how to convert value [" + value + "] to requested type [" + type.getName() + "]"
|
"Unaware how to convert value [" + value + " : " + typeName( value ) + "] to requested type [" + type.getName() + "]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String typeName(Object value) {
|
||||||
|
return value == null ? "???" : value.getClass().getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the given value into the specified target type.
|
* Convert the given value into the specified target type.
|
||||||
*
|
*
|
||||||
|
@ -226,22 +240,22 @@ public class ValueConverter {
|
||||||
if ( String.class.equals( targetType ) ) {
|
if ( String.class.equals( targetType ) ) {
|
||||||
return (Conversion<T>) StringConversion.INSTANCE;
|
return (Conversion<T>) StringConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Byte.class.equals( targetType ) ) {
|
if ( Byte.class.equals( targetType ) || Byte.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) ByteConversion.INSTANCE;
|
return (Conversion<T>) ByteConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Short.class.equals( targetType ) ) {
|
if ( Short.class.equals( targetType ) || Short.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) ShortConversion.INSTANCE;
|
return (Conversion<T>) ShortConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Integer.class.equals( targetType ) ) {
|
if ( Integer.class.equals( targetType ) || Integer.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) IntegerConversion.INSTANCE;
|
return (Conversion<T>) IntegerConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Long.class.equals( targetType ) ) {
|
if ( Long.class.equals( targetType ) || Long.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) LongConversion.INSTANCE;
|
return (Conversion<T>) LongConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Float.class.equals( targetType ) ) {
|
if ( Float.class.equals( targetType ) || Float.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) FloatConversion.INSTANCE;
|
return (Conversion<T>) FloatConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( Double.class.equals( targetType ) ) {
|
if ( Double.class.equals( targetType ) || Double.TYPE.equals( targetType ) ) {
|
||||||
return (Conversion<T>) DoubleConversion.INSTANCE;
|
return (Conversion<T>) DoubleConversion.INSTANCE;
|
||||||
}
|
}
|
||||||
if ( BigInteger.class.equals( targetType ) ) {
|
if ( BigInteger.class.equals( targetType ) ) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class ComparisonPredicate extends AbstractSimplePredicate implements Bina
|
||||||
super( criteriaBuilder );
|
super( criteriaBuilder );
|
||||||
this.comparisonOperator = comparisonOperator;
|
this.comparisonOperator = comparisonOperator;
|
||||||
this.leftHandSide = leftHandSide;
|
this.leftHandSide = leftHandSide;
|
||||||
if ( Number.class.isAssignableFrom( leftHandSide.getJavaType() ) ) {
|
if ( ValueConverter.isNumeric( leftHandSide.getJavaType() ) ) {
|
||||||
this.rightHandSide = new LiteralExpression(
|
this.rightHandSide = new LiteralExpression(
|
||||||
criteriaBuilder,
|
criteriaBuilder,
|
||||||
ValueConverter.convert( rightHandSide, (Class<Number>) leftHandSide.getJavaType() )
|
ValueConverter.convert( rightHandSide, (Class<Number>) leftHandSide.getJavaType() )
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class Info implements java.io.Serializable {
|
||||||
zip = v;
|
zip = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OneToOne(mappedBy = "info") @JoinTable
|
@OneToOne(mappedBy = "info") @JoinTable( name = "INFO_SPOUSE_TABLE" )
|
||||||
public Spouse getSpouse() {
|
public Spouse getSpouse() {
|
||||||
return spouse;
|
return spouse;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue