Author: steve.ebersole(a)jboss.com
Date: 2009-12-22 01:12:34 -0500 (Tue, 22 Dec 2009)
New Revision: 18312
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueConverter.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Info.java
Log:
HHH-4698 - Better handling of JPA criteria expressions
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueConverter.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueConverter.java 2009-12-22
04:15:04 UTC (rev 18311)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueConverter.java 2009-12-22
06:12:34 UTC (rev 18312)
@@ -39,6 +39,16 @@
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 final ByteConversion INSTANCE = new ByteConversion();
@SuppressWarnings({ "UnnecessaryBoxing" })
@@ -185,10 +195,14 @@
private static IllegalArgumentException unknownConversion(Object value, Class type) {
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.
*
@@ -226,22 +240,22 @@
if ( String.class.equals( targetType ) ) {
return (Conversion<T>) StringConversion.INSTANCE;
}
- if ( Byte.class.equals( targetType ) ) {
+ if ( Byte.class.equals( targetType ) || Byte.TYPE.equals( targetType ) ) {
return (Conversion<T>) ByteConversion.INSTANCE;
}
- if ( Short.class.equals( targetType ) ) {
+ if ( Short.class.equals( targetType ) || Short.TYPE.equals( targetType ) ) {
return (Conversion<T>) ShortConversion.INSTANCE;
}
- if ( Integer.class.equals( targetType ) ) {
+ if ( Integer.class.equals( targetType ) || Integer.TYPE.equals( targetType ) ) {
return (Conversion<T>) IntegerConversion.INSTANCE;
}
- if ( Long.class.equals( targetType ) ) {
+ if ( Long.class.equals( targetType ) || Long.TYPE.equals( targetType ) ) {
return (Conversion<T>) LongConversion.INSTANCE;
}
- if ( Float.class.equals( targetType ) ) {
+ if ( Float.class.equals( targetType ) || Float.TYPE.equals( targetType ) ) {
return (Conversion<T>) FloatConversion.INSTANCE;
}
- if ( Double.class.equals( targetType ) ) {
+ if ( Double.class.equals( targetType ) || Double.TYPE.equals( targetType ) ) {
return (Conversion<T>) DoubleConversion.INSTANCE;
}
if ( BigInteger.class.equals( targetType ) ) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-12-22
04:15:04 UTC (rev 18311)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-12-22
06:12:34 UTC (rev 18312)
@@ -63,7 +63,7 @@
super( criteriaBuilder );
this.comparisonOperator = comparisonOperator;
this.leftHandSide = leftHandSide;
- if ( Number.class.isAssignableFrom( leftHandSide.getJavaType() ) ) {
+ if ( ValueConverter.isNumeric( leftHandSide.getJavaType() ) ) {
this.rightHandSide = new LiteralExpression(
criteriaBuilder,
ValueConverter.convert( rightHandSide, (Class<Number>)
leftHandSide.getJavaType() )
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Info.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Info.java 2009-12-22
04:15:04 UTC (rev 18311)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Info.java 2009-12-22
06:12:34 UTC (rev 18312)
@@ -113,7 +113,7 @@
zip = v;
}
- @OneToOne(mappedBy = "info") @JoinTable
+ @OneToOne(mappedBy = "info") @JoinTable( name = "INFO_SPOUSE_TABLE"
)
public Spouse getSpouse() {
return spouse;
}