This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 1a8bcfb6b1bd08d3f0158c023307c3cea2512d98
Author: Mark Struberg <[email protected]>
AuthorDate: Tue Mar 30 14:38:14 2021 +0200

    OPENJPA-2849 fix UnaryOp to use DBDictionary
    
    UnaryOps should use the DBDictionary to resolve the requested data whenever 
possible.
    Previously we always have been requesting JDBC native types when doing 
max(), min(), etc.
    But this returns values of types which we potentially cannot handle.
---
 .../org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java     |  4 +++-
 .../java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java  | 16 ++++++++++++++++
 .../openjpa/jdbc/meta/strats/HandlerStrategies.java      |  3 +--
 .../openjpa/persistence/simple/TestJava8TimeTypes.java   |  7 +++++++
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
index 3c8eadf..0f22630 100644
--- 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
+++ 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
@@ -27,6 +27,7 @@ import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.Filters;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
 import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.meta.JavaTypes;
 
 /**
  * Value produced by a unary operation on a value.
@@ -129,8 +130,9 @@ abstract class UnaryOp
     @Override
     public Object load(ExpContext ctx, ExpState state, Result res)
         throws SQLException {
-        Object value = res.getObject(this, JavaSQLTypes.JDBC_DEFAULT, null);
         Class<?> type = getType();
+        int typeCode = type != null ? JavaTypes.getTypeCode(type) : 
JavaSQLTypes.JDBC_DEFAULT;
+        Object value = res.getObject(this, typeCode, null);
         if (value == null) {
             if (nullableValue(ctx, state)) {  // OPENJPA-1794
                 return null;
diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java
index 60296a2..8108f10 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JavaSQLTypes.java
@@ -22,6 +22,11 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
 
 import org.apache.openjpa.meta.JavaTypes;
 
@@ -76,6 +81,17 @@ public class JavaSQLTypes
             return TIMESTAMP;
         if (dtype == Time.class)
             return TIME;
+        if (dtype == LocalDate.class)
+            return LOCAL_DATE;
+        if (dtype == LocalDateTime.class)
+            return LOCAL_DATETIME;
+        if (dtype == LocalTime.class)
+            return LOCAL_TIME;
+        if (dtype == OffsetTime.class)
+            return OFFSET_TIME;
+        if (dtype == OffsetDateTime.class)
+            return OFFSET_DATETIME;
+
         return OBJECT;
     }
 
diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerStrategies.java
 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerStrategies.java
index 053bafe..6c80a11 100644
--- 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerStrategies.java
+++ 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerStrategies.java
@@ -221,8 +221,7 @@ public class HandlerStrategies {
         if (cols.length == 0)
             return null;
         if (cols.length == 1)
-            return res.getObject(cols[0], vm.getHandler().
-                getResultArgument(vm), joins);
+            return res.getObject(cols[0], 
vm.getHandler().getResultArgument(vm), joins);
 
         Object[] vals = new Object[cols.length];
         Object[] args = (Object[]) vm.getHandler().getResultArgument(vm);
diff --git 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestJava8TimeTypes.java
 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestJava8TimeTypes.java
index 17b76ca..6b56aba 100644
--- 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestJava8TimeTypes.java
+++ 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestJava8TimeTypes.java
@@ -32,6 +32,7 @@ import java.time.OffsetTime;
 import java.time.ZoneId;
 import java.time.ZoneOffset;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Test for JPA-2.2 java.time.* functionality
@@ -82,6 +83,12 @@ public class TestJava8TimeTypes extends SingleEMFTestCase {
 
         // we've got reports from various functions not properly working with 
Java8 Dates.
 
+        {
+            final TypedQuery<LocalDate> qry = em.createQuery("select 
t.localDateField from Java8TimeTypes AS t", LocalDate.class);
+            final LocalDate date = qry.getSingleResult();
+            assertNotNull(date);
+        }
+
         // max function
         {
             final TypedQuery<LocalDate> qry = em.createQuery("select 
max(t.localDateField) from Java8TimeTypes AS t", LocalDate.class);

Reply via email to