openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1133605 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/ openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/
Date Wed, 08 Jun 2011 23:50:30 GMT
Author: ppoddar
Date: Wed Jun  8 23:50:30 2011
New Revision: 1133605

URL: http://svn.apache.org/viewvc?rev=1133605&view=rev
Log:
OPENJPA-2012: Support in-memory MIN()/MAX() on non-numeric types

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
    openjpa/trunk/openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java?rev=1133605&r1=1133604&r2=1133605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java Wed
Jun  8 23:50:30 2011
@@ -364,6 +364,8 @@ public class Filters {
             return Short.valueOf(((Number) o).shortValue());
         } else if (type == Byte.class && allowNumericConversion(o.getClass(), type,
strictNumericConversion)) {
             return Byte.valueOf(((Number) o).byteValue());
+        } else if (type == Character.class) {
+        	return (char) ((Number) o).intValue();
         } else if (!strictNumericConversion) {
             return ((Number) o).intValue();
         } else {

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java?rev=1133605&r1=1133604&r2=1133605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
Wed Jun  8 23:50:30 2011
@@ -18,6 +18,10 @@
  */
 package org.apache.openjpa.slice.jdbc;
 
+import java.util.Date;
+
+import org.apache.openjpa.jdbc.kernel.exps.Val;
+import org.apache.openjpa.kernel.Filters;
 import org.apache.openjpa.kernel.StoreQuery;
 import org.apache.openjpa.kernel.exps.QueryExpressions;
 import org.apache.openjpa.kernel.exps.Value;
@@ -86,6 +90,7 @@ public class UniqueResultObjectProvider 
         for (int i=0; i<values.length; i++) {
             Value v = values[i];
             boolean isAggregate = v.isAggregate();
+            
             String op = v.getClass().getSimpleName();
             for (ResultObjectProvider rop:_rops) {
                 if (i == 0) 
@@ -107,6 +112,7 @@ public class UniqueResultObjectProvider 
                 } else {
                     single[i] = row[i];
                 }
+                single[i] = Filters.convert(single[i], v.getType());
             }
         }
         _single = single;
@@ -126,8 +132,21 @@ public class UniqueResultObjectProvider 
             return other;
         if (other == null)
         	return current;
-        return Math.max(((Number)current).doubleValue(), 
+        if (current instanceof Number) {
+        	return Math.max(((Number)current).doubleValue(), 
                 ((Number)other).doubleValue());
+        }
+        if (current instanceof String) {
+        	return  ((String)current).compareTo((String)other) > 0 ? current : other; 
+        }
+        if (current instanceof Date) {
+        	return ((Date)current).compareTo((Date)other) > 0 ? current : other;
+        }
+        if (current instanceof Character) {
+        	return ((Character)current).compareTo((Character)other) > 0 ? current : other;
+        }
+        throw new UnsupportedOperationException(_loc.get("aggregate-unsupported-on-type",

+        		"MAX()", (current == null ? other : current).getClass().getName()).toString());
     }
     
     Object min(Object current, Object other) {
@@ -135,8 +154,21 @@ public class UniqueResultObjectProvider 
             return other;
         if (other == null)
         	return current;
-        return Math.min(((Number)current).doubleValue(), 
-                ((Number)other).doubleValue());
+        if (current instanceof Number) {
+	        return Math.min(((Number)current).doubleValue(), 
+	                ((Number)other).doubleValue());
+        }
+        if (current instanceof String) {
+        	return ((String)current).compareTo((String)other) < 0 ? current : other; 
+        }
+        if (current instanceof Date) {
+        	return ((Date)current).compareTo((Date)other) < 0 ? current : other;
+        }
+        if (current instanceof Character) {
+        	return ((Character)current).compareTo((Character)other) < 0 ? current : other;
+        }
+        throw new UnsupportedOperationException(_loc.get("aggregate-unsupported-on-type",

+        		"MIN()", (current == null ? other : current).getClass().getName()).toString());
     }
     
     Object sum(Object current, Object other) {
@@ -144,12 +176,14 @@ public class UniqueResultObjectProvider 
             return other;
         if (other == null)
         	return current;
-        return (((Number)current).doubleValue() +
+        if (current instanceof Number) {
+        	return (((Number)current).doubleValue() +
                 ((Number)other).doubleValue());
+        }
+        throw new UnsupportedOperationException(_loc.get("aggregate-unsupported-on-type",

+        		"SUM()", (current == null ? other : current).getClass().getName()).toString());
     }
-
-
-
+    
     public void open() throws Exception {
         for (ResultObjectProvider rop:_rops)
             rop.open();

Modified: openjpa/trunk/openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties?rev=1133605&r1=1133604&r2=1133605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties
(original)
+++ openjpa/trunk/openjpa-slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties
Wed Jun  8 23:50:30 2011
@@ -64,4 +64,5 @@ resource-not-xa-tm-2pc: One or more slic
 	but the configured "{0}" transaction manager can only enlist XA-aware \
 	resource. 
 not-open: The underlying result sets are not open.
-aggregate-unsupported: The query uses unsupported aggregate operation "{0}".  
+aggregate-unsupported: The query uses unsupported aggregate operation {0}.  
+aggregate-unsupported-on-type: Aggregate operation {0} not supported on {1}  



Mime
View raw message