You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by st...@apache.org on 2019/02/14 14:26:21 UTC

[openjpa] 01/03: OPENJPA-2713 add java8 time api for SQLServer

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 c1ae373a0f55d3caa585717d43334b379a9b3bab
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Feb 7 12:52:40 2019 +0100

    OPENJPA-2713 add java8 time api for SQLServer
---
 .../jdbc/sql/AbstractSQLServerDictionary.java      |  1 +
 .../openjpa/jdbc/sql/SQLServerDictionary.java      | 53 +++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
index 583a28c..b4995d6 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
@@ -73,6 +73,7 @@ public abstract class AbstractSQLServerDictionary
         dateTypeName = "DATETIME";
         timeTypeName = "DATETIME";
         timestampTypeName = "DATETIME";
+        timestampWithZoneTypeName = "DATETIMEOFFSET";
         floatTypeName = "FLOAT(16)";
         doubleTypeName = "FLOAT(32)";
         integerTypeName = "INT";
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
index ab7e47c..c5e2eb3 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
@@ -22,9 +22,14 @@ import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
 import java.util.Locale;
 
 import org.apache.openjpa.jdbc.identifier.DBIdentifier;
@@ -63,6 +68,11 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         supportsNullTableForGetColumns = false;
         requiresAliasForSubselect = true;
         stringLengthFunction = "LEN({0})";
+
+        timeTypeName = "TIME";
+        timeWithZoneTypeName = "TIME";
+        timestampWithZoneTypeName = "DATETIMEOFFSET";
+
     }
 
     @Override
@@ -341,6 +351,47 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         return clob.getCharacterStream();
     }
 
+
+    @Override
+    public LocalDate getLocalDate(ResultSet rs, int column) throws SQLException {
+        return rs.getObject(column, LocalDate.class);
+    }
+
+    @Override
+    public void setLocalTime(PreparedStatement stmnt, int idx, LocalTime val, Column col) throws SQLException {
+        stmnt.setObject(idx, val);
+    }
+
+    @Override
+    public LocalTime getLocalTime(ResultSet rs, int column) throws SQLException {
+        return rs.getObject(column, LocalTime.class);
+    }
+
+    @Override
+    public void setLocalDateTime(PreparedStatement stmnt, int idx, LocalDateTime val, Column col) throws SQLException {
+        stmnt.setObject(idx, val);
+    }
+
+    @Override
+    public LocalDateTime getLocalDateTime(ResultSet rs, int column) throws SQLException {
+        return rs.getObject(column, LocalDateTime.class);
+    }
+
+    @Override
+    public void setOffsetDateTime(PreparedStatement stmnt, int idx, OffsetDateTime val, Column col) throws SQLException {
+        stmnt.setObject(idx, val);
+    }
+
+    /**
+     * h2 does intentionally not support {@code getTimestamp()} for 'TIME WITH TIME ZONE' columns.
+     * See h2 ticket #413.
+     */
+    @Override
+    public OffsetDateTime getOffsetDateTime(ResultSet rs, int column) throws SQLException {
+        return rs.getObject(column, OffsetDateTime.class);
+    }
+
+
     @Override
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
         FilterValue start) {
@@ -351,7 +402,7 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         if (start != null) {
             buf.append(", ");
             start.appendTo(buf);
-        }
+p        }
         buf.append(")");
     }