openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openjpa] 01/02: OPENJPA-2713 add support for java.time.LocalDate
Date Sun, 20 Jan 2019 13:50:08 GMT
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 89335fd48cb88a7acb53c9fc1c85942be5a1c3dd
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Sun Jan 20 14:49:20 2019 +0100

    OPENJPA-2713 add support for java.time.LocalDate
    
    plus some cleanup
---
 .../org/apache/openjpa/jdbc/meta/ClassMapping.java |  9 +--
 .../org/apache/openjpa/jdbc/meta/FieldMapping.java |  9 ++-
 .../openjpa/jdbc/meta/MappingDefaultsImpl.java     | 15 +++-
 .../org/apache/openjpa/jdbc/meta/MappingInfo.java  |  2 +-
 .../jdbc/meta/RuntimeStrategyInstaller.java        |  3 +-
 .../openjpa/jdbc/meta/strats/EnumValueHandler.java |  3 +-
 .../jdbc/meta/strats/HandlerStrategies.java        |  8 ++-
 .../jdbc/meta/strats/ImmutableValueHandler.java    |  3 +-
 .../jdbc/meta/strats/LocalDateValueHandler.java    | 81 +++++++++++++++++++++
 .../apache/openjpa/jdbc/sql/DerbyDictionary.java   | 84 +++++++++++-----------
 .../persistence/jdbc/common/apps/RawField.java     | 16 -----
 .../persistence/jdbc/meta/TestRawField.java        |  9 ++-
 .../persistence/jdbc/schema/TestSchema.java        |  8 +--
 .../openjpa/persistence/simple/AllFieldTypes.java  | 56 ++++++++++++++-
 .../persistence/simple/TestBasicAnnotation.java    | 16 ++---
 15 files changed, 227 insertions(+), 95 deletions(-)

diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
index 686c8e3..a1a387f 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
@@ -920,12 +920,13 @@ public class ClassMapping
         // also being resolved.  don't use getDefinedFields b/c it relies on
         // whether fields are mapped, which isn't known yet
         fms = getFieldMappings();
-        for (int i = 0; i < fms.length; i++)
+        for (int i = 0; i < fms.length; i++) {
             if (fms[i].getDefiningMetaData() == this
-                && !fms[i].isTypePC() && !fms[i].getKey().isTypePC()
-                && !fms[i].getElement().isTypePC())
+                    && !fms[i].isTypePC() && !fms[i].getKey().isTypePC()
+                    && !fms[i].getElement().isTypePC()) {
                 fms[i].resolve(MODE_MAPPING);
-
+            }
+        }
         _discrim.resolve(MODE_MAPPING);
         _version.resolve(MODE_MAPPING);
     }
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
index 63372b2..3d76b5e 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
@@ -462,12 +462,15 @@ public class FieldMapping
     @Override
     public boolean resolve(int mode) {
         int cur = getResolve();
-        if (super.resolve(mode))
+        if (super.resolve(mode)) {
             return true;
-        if ((mode & MODE_MAPPING) != 0 && (cur & MODE_MAPPING) == 0)
+        }
+        if ((mode & MODE_MAPPING) != 0 && (cur & MODE_MAPPING) == 0) {
             resolveMapping();
-        if ((mode & MODE_MAPPING_INIT) != 0 && (cur & MODE_MAPPING_INIT)
== 0)
+        }
+        if ((mode & MODE_MAPPING_INIT) != 0 && (cur & MODE_MAPPING_INIT)
== 0) {
             initializeMapping();
+        }
         return false;
     }
 
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
index e783f2f..fe4f5bc 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
@@ -27,6 +27,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.identifier.Normalizer;
 import org.apache.openjpa.jdbc.meta.strats.EnumValueHandler;
+import org.apache.openjpa.jdbc.meta.strats.LocalDateValueHandler;
 import org.apache.openjpa.jdbc.meta.strats.UntypedPCValueHandler;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -521,16 +522,26 @@ public class MappingDefaultsImpl
     @Override
     public Object getStrategy(ValueMapping vm, Class<?> type, boolean adapt) {
         Object ret = _fieldMap.get(type.getName());
-        if (ret != null)
+        if (ret != null) {
             return ret;
+        }
+
         if (_stringifyUnmapped && vm.getTypeMapping() != null
-            && !vm.getTypeMapping().isMapped())
+            && !vm.getTypeMapping().isMapped()) {
             return UntypedPCValueHandler.getInstance();
+        }
+
         if (type.isEnum() && !vm.isSerialized()) {
             EnumValueHandler enumHandler = new EnumValueHandler();
             enumHandler.setStoreOrdinal(_ordinalEnum);
             return enumHandler;
         }
+
+        if (java.time.LocalDate.class == type) {
+            // we can compare with == since LocalDate is final
+            return new LocalDateValueHandler();
+        }
+
         return null;
     }
 
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
index 454e4a1..26d2876 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
@@ -757,7 +757,7 @@ public abstract class MappingInfo implements Serializable {
             if (given.isRelationId())
                 relationId = true;
             if (given.isImplicitRelation())
-            	implicitRelation = true;
+                implicitRelation = true;
         }
 
         // default char column size if original type is char (test original
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RuntimeStrategyInstaller.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RuntimeStrategyInstaller.java
index 13bc85d..04be49b 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RuntimeStrategyInstaller.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RuntimeStrategyInstaller.java
@@ -63,8 +63,9 @@ public class RuntimeStrategyInstaller
     public void installStrategy(FieldMapping field) {
         FieldStrategy strategy = null;
         ClassMapping owner = getOutermostDefiningMapping(field);
-        if (owner != null && !owner.isEmbeddable() && !owner.isAbstract())
+        if (owner != null && !owner.isEmbeddable() && !owner.isAbstract())
{
             strategy = repos.namedStrategy(field, true);
+        }
         if (strategy == null) {
             try {
                 strategy = repos.defaultStrategy(field, true, false);
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EnumValueHandler.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EnumValueHandler.java
index 8a4df24..0d0b15f 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EnumValueHandler.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EnumValueHandler.java
@@ -97,7 +97,8 @@ public class EnumValueHandler extends AbstractValueHandler {
         return new Column[]{ col };
     }
 
-    public boolean isVersionable() {
+    @Override
+    public boolean isVersionable(ValueMapping vm) {
         return true;
     }
 
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 7547db6..053bafe 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
@@ -64,9 +64,11 @@ public class HandlerStrategies {
         if (cols.length > 0 && cols[0].getTable() == null) {
             cols = vinfo.getColumns(vm, colName, cols,
                 vm.getFieldMapping().getTable(), adapt);
-            if (vinfo.isImplicitRelation())
-            	for (int i = 0; i < cols.length; i++)
-            		cols[i].setImplicitRelation(true);
+            if (vinfo.isImplicitRelation()) {
+                for (int i = 0; i < cols.length; i++) {
+                    cols[i].setImplicitRelation(true);
+                }
+            }
             ColumnIO mappedIO = vinfo.getColumnIO();
             vm.setColumns(cols);
             vm.setColumnIO(mappedIO);
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ImmutableValueHandler.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ImmutableValueHandler.java
index f5d97a6..e148963 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ImmutableValueHandler.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ImmutableValueHandler.java
@@ -33,8 +33,7 @@ import org.apache.openjpa.meta.JavaTypes;
  * Handler for simple type and string values.
  *
  */
-public class ImmutableValueHandler
-    extends AbstractValueHandler {
+public class ImmutableValueHandler extends AbstractValueHandler {
 
     
     private static final long serialVersionUID = 1L;
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LocalDateValueHandler.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LocalDateValueHandler.java
new file mode 100644
index 0000000..1701dbf
--- /dev/null
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LocalDateValueHandler.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.jdbc.meta.strats;
+
+import java.sql.Types;
+import java.time.LocalDate;
+
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.meta.ValueMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ColumnIO;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.lib.util.Localizer;
+
+/**
+ * Value handler for JDK8 java.time.LocalDate field types.
+ *
+ */
+public class LocalDateValueHandler extends AbstractValueHandler {
+    private static final long serialVersionUID = 1L;
+    private static final Localizer _loc = Localizer.forPackage(LocalDateValueHandler.class);
+
+    /**
+     * @deprecated
+     */
+    @Deprecated
+    @Override
+    public Column[] map(ValueMapping vm, String name, ColumnIO io,
+        boolean adapt) {
+        DBDictionary dict = vm.getMappingRepository().getDBDictionary();
+        DBIdentifier colName = DBIdentifier.newColumn(name, dict != null ? dict.delimitAll()
: false);
+
+        Column column = new Column();
+        column.setIdentifier(colName);
+        column.setJavaType(JavaSQLTypes.SQL_DATE);
+        column.setType(Types.DATE);
+
+        return new Column[]{column};
+    }
+
+    @Override
+    public boolean isVersionable(ValueMapping vm) {
+        return true;
+    }
+
+    @Override
+    public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore store) {
+        if (val == null) {
+            return null;
+        }
+
+        return java.sql.Date.valueOf((LocalDate) val);
+    }
+
+    @Override
+    public Object toObjectValue(ValueMapping vm, Object val) {
+        if (val == null) {
+            return null;
+        }
+
+        return ((java.sql.Date) val).toLocalDate();
+    }
+}
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
index c972992..5c139de 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
@@ -120,11 +120,11 @@ public class DerbyDictionary
 
     @Override
     public void connectedConfiguration(Connection conn) throws SQLException {
-    	super.connectedConfiguration(conn);
-    	if (versionEqualOrLaterThan(10, 5)) {
-    		supportsSelectStartIndex = true;
-    		supportsSelectEndIndex   = true;
-    	}
+        super.connectedConfiguration(conn);
+        if (versionEqualOrLaterThan(10, 5)) {
+            supportsSelectStartIndex = true;
+            supportsSelectEndIndex   = true;
+        }
     }
 
     /**
@@ -136,7 +136,7 @@ public class DerbyDictionary
      * and {@link DBDictionary#supportsSelectEndIndex limit} on queries then the
      * syntax is <pre>
      * [ OFFSET {start} ROWS ]
-	 * [ FETCH NEXT {end-start} ROWS ONLY ]
+     * [ FETCH NEXT {end-start} ROWS ONLY ]
      * </pre>
      * Otherwise, the offset is not used and the syntax is <pre>
      * [ FETCH FIRST {end} ROWS ONLY ]
@@ -149,18 +149,18 @@ public class DerbyDictionary
     @Override
     protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect)
{
         // do not generate FETCH FIRST clause for subselect
-    	if (subselect)
-    		return;
-    	if (supportsSelectStartIndex && supportsSelectEndIndex) {
-	    	if (isUsingOffset(start))
-	    		buf.append(" OFFSET ").append(Long.toString(start)).append(" ROWS ");
-	    	if (isUsingLimit(end)) {
-	    		long rowCount = end - start;
-	    		buf.append(" FETCH NEXT ").append(Long.toString(rowCount)).append(" ROWS ONLY");
-	    	}
-    	} else if (isUsingLimit(end)) {
-             buf.append(" FETCH FIRST ").append(Long.toString(end)).append(" ROWS ONLY");
-    	}
+        if (subselect)
+            return;
+        if (supportsSelectStartIndex && supportsSelectEndIndex) {
+            if (isUsingOffset(start))
+                buf.append(" OFFSET ").append(Long.toString(start)).append(" ROWS ");
+            if (isUsingLimit(end)) {
+                long rowCount = end - start;
+                buf.append(" FETCH NEXT ").append(Long.toString(rowCount)).append(" ROWS
ONLY");
+            }
+        } else if (isUsingLimit(end)) {
+            buf.append(" FETCH FIRST ").append(Long.toString(end)).append(" ROWS ONLY");
+        }
     }
 
     @Override
@@ -198,29 +198,29 @@ public class DerbyDictionary
         return super.isFatalException(subtype, ex);
     }
 
-	/**
-	 * Applies range calculation on the actual number of rows selected by a
-	 * {@code COUNT(*)} query. A range query may use either only the limit or
-	 * both offset and limit based on database dictionary support and
-	 * accordingly the number of rows in the result set needs to be modified.
-	 *
-	 * @param select
-	 * @param count
-	 * @return
-	 */
-
-	@Override
+    /**
+     * Applies range calculation on the actual number of rows selected by a
+     * {@code COUNT(*)} query. A range query may use either only the limit or
+     * both offset and limit based on database dictionary support and
+     * accordingly the number of rows in the result set needs to be modified.
+     *
+     * @param select
+     * @param count
+     * @return
+     */
+
+    @Override
     public int applyRange(Select select, int count) {
-		long start = select.getStartIndex();
-		long end = select.getEndIndex();
-		if (supportsSelectStartIndex) {
-			if (start > 0)
-				count -= start;
-			if (end != Long.MAX_VALUE) {
-				long size = end - start;
-				count = (int) Math.min(count, size);
-			}
-		}
-		return count;
-	}
+        long start = select.getStartIndex();
+        long end = select.getEndIndex();
+        if (supportsSelectStartIndex) {
+            if (start > 0)
+                count -= start;
+            if (end != Long.MAX_VALUE) {
+                long size = end - start;
+                count = (int) Math.min(count, size);
+            }
+        }
+        return count;
+    }
 }
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/RawField.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/RawField.java
index 5177f34..714d356 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/RawField.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/RawField.java
@@ -18,10 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.common.apps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.meta.ValueMapping;
-import org.apache.openjpa.jdbc.meta.strats.ImmutableValueHandler;
-import org.apache.openjpa.jdbc.sql.Raw;
 
 public class RawField {
 
@@ -35,16 +31,4 @@ public class RawField {
         return str;
     }
 
-    public static class RawMapping
-        extends ImmutableValueHandler {
-
-        
-        private static final long serialVersionUID = 1L;
-
-        @Override
-        public Object toDataStoreValue(ValueMapping vm, Object val,
-            JDBCStore store) {
-            return new Raw("'" + val + "FOO'");
-        }
-    }
 }
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java
index 5df13f4..c4b1b3e 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java
@@ -29,15 +29,14 @@ package org.apache.openjpa.persistence.jdbc.meta;
 
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.jdbc.common.apps.RawField;
+import org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest;
 
 
-public class TestRawField
-        extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
+public class TestRawField extends BaseJDBCTest {
 
     /** Creates a new instance of TestRawField */
-    public TestRawField(String name)
-    {
-    	super(name);
+    public TestRawField(String name) {
+        super(name);
     }
 
     @Override
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchema.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchema.java
index 8e8c8cc..4b617c5 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchema.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchema.java
@@ -34,10 +34,10 @@ import org.apache.openjpa.jdbc.schema.PrimaryKey;
 import org.apache.openjpa.jdbc.schema.Schema;
 import org.apache.openjpa.jdbc.schema.SchemaGroup;
 import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest;
 
 
-public class TestSchema
-        extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
+public class TestSchema extends BaseJDBCTest {
 
     private Schema _schema = new SchemaGroup().addSchema("schema");
 
@@ -314,8 +314,4 @@ public class TestSchema
         assertEquals(0, table.getForeignKeys().length);
     }
 
-    public static void main(String[] args) {
-        //main(TestSchema.class);
-	}
-
 }
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
index b9c3e47..18d5373 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
@@ -21,6 +21,11 @@ package org.apache.openjpa.persistence.simple;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -37,7 +42,7 @@ import org.apache.openjpa.persistence.PersistentCollection;
 @Entity
 public class AllFieldTypes {
 
-    public static enum EnumType {Value1, Value2};
+    public enum EnumType {Value1, Value2};
 
     // @Basic types
     private short shortField;
@@ -84,6 +89,14 @@ public class AllFieldTypes {
     @OneToMany
     private List<AllFieldTypes> selfOneMany = new ArrayList<>();
 
+    // Java8 DateTime types which are required by the JPA-2.2 spec
+    private LocalDate localDateField;
+    private LocalTime localTimeField;
+    private LocalDateTime localDateTimeField;
+    private OffsetTime offsetTimeField;
+    private OffsetDateTime offsetDateTimeField;
+
+
     public void setShortField(short shortField) {
         this.shortField = shortField;
     }
@@ -363,5 +376,46 @@ public class AllFieldTypes {
     public void setSelfOneMany(List<AllFieldTypes> selfOneMany) {
         this.selfOneMany = selfOneMany;
     }
+
+
+    public LocalDate getLocalDateField() {
+        return localDateField;
+    }
+
+    public void setLocalDateField(LocalDate localDateField) {
+        this.localDateField = localDateField;
+    }
+
+    public LocalTime getLocalTimeField() {
+        return localTimeField;
+    }
+
+    public void setLocalTimeField(LocalTime localTimeField) {
+        this.localTimeField = localTimeField;
+    }
+
+    public LocalDateTime getLocalDateTimeField() {
+        return localDateTimeField;
+    }
+
+    public void setLocalDateTimeField(LocalDateTime localDateTimeField) {
+        this.localDateTimeField = localDateTimeField;
+    }
+
+    public OffsetTime getOffsetTimeField() {
+        return offsetTimeField;
+    }
+
+    public void setOffsetTimeField(OffsetTime offsetTimeField) {
+        this.offsetTimeField = offsetTimeField;
+    }
+
+    public OffsetDateTime getOffsetDateTimeField() {
+        return offsetDateTimeField;
+    }
+
+    public void setOffsetDateTimeField(OffsetDateTime offsetDateTimeField) {
+        this.offsetDateTimeField = offsetDateTimeField;
+    }
 }
 
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
index 12114f3..754e30c 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
@@ -19,6 +19,7 @@
 package org.apache.openjpa.persistence.simple;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -26,16 +27,14 @@ import javax.persistence.EntityManager;
 
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
-import junit.textui.TestRunner;
-
 /**
  * Simple test case to test the default values associated with the @Basic
  * annotation.
  *
  * @author Kevin Sutter
  */
-public class TestBasicAnnotation
-    extends SingleEMFTestCase {
+public class TestBasicAnnotation extends SingleEMFTestCase {
+    private static String VAL_LOCAL_DATE = "2019-01-01";
 
     @Override
     public void setUp() {
@@ -61,6 +60,9 @@ public class TestBasicAnnotation
         aft.setWByteLob(new Byte[1]);
         aft.setWDoubleField(new Double(1));
 
+        aft.setLocalDateField(LocalDate.parse(VAL_LOCAL_DATE));
+
+
         em.persist(aft);
         em.getTransaction().commit();
         em.clear();
@@ -84,11 +86,9 @@ public class TestBasicAnnotation
         assertNotNull(aftQuery.getWByteLob());
         assertNotNull(aftQuery.getWDoubleField());
 
-        em.close();
-    }
+        assertEquals(LocalDate.parse(VAL_LOCAL_DATE), aftQuery.getLocalDateField());
 
-    public static void main(String[] args) {
-        TestRunner.run(TestBasicAnnotation.class);
+        em.close();
     }
 }
 


Mime
View raw message