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:20 UTC

[openjpa] branch master updated (0e4ec5b -> 1690076)

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

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


    from 0e4ec5b  OPENJPA-2733 fix param index.
     new c1ae373  OPENJPA-2713 add java8 time api for SQLServer
     new 87422c8  OPENJPA-2753 add info about how to debug SQLServer
     new 1690076  fix formatting and readability

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jdbc/sql/AbstractSQLServerDictionary.java      |  1 +
 .../openjpa/jdbc/sql/SQLServerDictionary.java      | 68 +++++++++++++++++++++-
 .../persistence/criteria/CriteriaQueryImpl.java    | 34 +++++++----
 openjpa-project/BUILDING.txt                       |  3 +
 pom.xml                                            |  2 +-
 5 files changed, 92 insertions(+), 16 deletions(-)


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

Posted by st...@apache.org.
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(")");
     }
 


[openjpa] 03/03: fix formatting and readability

Posted by st...@apache.org.
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 1690076b37e70fb45d302b1af7a6c78256183a3b
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Feb 14 15:25:50 2019 +0100

    fix formatting and readability
---
 .../openjpa/jdbc/sql/SQLServerDictionary.java      | 23 +++++++++++----
 .../persistence/criteria/CriteriaQueryImpl.java    | 34 ++++++++++++++--------
 pom.xml                                            |  2 +-
 3 files changed, 40 insertions(+), 19 deletions(-)

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 c5e2eb3..8d397b6 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
@@ -60,6 +60,15 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
      */
     public boolean uniqueIdentifierAsVarbinary = true;
 
+    /**
+     * Whether to send Time values as DateTime or as Time.
+     * This affects how the Database actually looks like.
+     * sendTimeAsDatetime is supported as of SQLServer2008 and
+     * is only to be used with TIME columns.
+     * Previous to that a DATETIME column had to be used with a fixed 1970-01-01 date.
+     */
+    public Boolean sendTimeAsDatetime = null;
+
     public SQLServerDictionary() {
         platform = "Microsoft SQL Server";
         // SQLServer locks on a table-by-table basis
@@ -69,10 +78,8 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         requiresAliasForSubselect = true;
         stringLengthFunction = "LEN({0})";
 
-        timeTypeName = "TIME";
         timeWithZoneTypeName = "TIME";
         timestampWithZoneTypeName = "DATETIMEOFFSET";
-
     }
 
     @Override
@@ -84,13 +91,17 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         String url = meta.getURL();
         if (driverVendor == null) {
             // serverMajorVersion of 8==2000, 9==2005, 10==2008,  11==2012
-            if (meta.getDatabaseMajorVersion() >= 9)
+            if (meta.getDatabaseMajorVersion() >= 9) {
                 setSupportsXMLColumn(true);
+                if (sendTimeAsDatetime == null) {
+                    sendTimeAsDatetime = Boolean.TRUE;
+                }
+            }
             if (meta.getDatabaseMajorVersion() >= 10) {
                 // MSSQL 2008 supports new date, time and datetime2 types
                 // Use DATETIME2 which has 100ns vs. 3.333msec precision
-                dateTypeName = "DATETIME2";
-                timeTypeName = "DATETIME2";
+                dateTypeName = "DATE";
+                timeTypeName = "TIME";
                 timestampTypeName = "DATETIME2";
                 datePrecision = MICRO / 10;
             }
@@ -402,7 +413,7 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         if (start != null) {
             buf.append(", ");
             start.appendTo(buf);
-p        }
+        }
         buf.append(")");
     }
 
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
index 778ca72..bd36acd 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
@@ -246,13 +246,14 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
 
     @Override
     public CriteriaQuery<T> groupBy(Expression<?>... grouping) {
-    	if (grouping == null) {
-    	    _groups = null;
-    	    return this;
-    	}
+        if (grouping == null) {
+            _groups = null;
+            return this;
+        }
         _groups = new ArrayList<>();
-    	for (Expression<?> e : grouping)
-    		_groups.add(e);
+        for (Expression<?> e : grouping) {
+            _groups.add(e);
+        }
         return this;
     }
 
@@ -284,8 +285,9 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
             return this;
         }
         _having = new PredicateImpl.And();
-        for (Predicate p : restrictions)
-        	_having.add(p);
+        for (Predicate p : restrictions) {
+            _having.add(p);
+        }
         return this;
     }
 
@@ -718,8 +720,9 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
     }
 
     private void renderList(StringBuilder buffer, String clause, Collection<?> coll) {
-        if (coll == null || coll.isEmpty())
+        if (coll == null || coll.isEmpty()) {
             return;
+        }
 
         buffer.append(clause);
         for (Iterator<?> i = coll.iterator(); i.hasNext(); ) {
@@ -729,7 +732,10 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
     }
 
     private void renderJoins(StringBuilder buffer, Collection<Join<?,?>> joins) {
-        if (joins == null) return;
+        if (joins == null) {
+            return;
+        }
+
         for (Join j : joins) {
             buffer.append(((CriteriaExpression)j).asVariable(this)).append(" ");
             renderJoins(buffer, j.getJoins());
@@ -738,7 +744,9 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
     }
 
     private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
-        if (roots == null) return;
+        if (roots == null) {
+            return;
+        }
         int i = 0;
         for (Root r : roots) {
             buffer.append(((ExpressionImpl<?>)r).asVariable(this));
@@ -748,7 +756,9 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
         }
     }
     private void renderFetches(StringBuilder buffer, Set<Fetch> fetches) {
-        if (fetches == null) return;
+        if (fetches == null) {
+            return;
+        }
         for (Fetch j : fetches) {
             buffer.append(((ExpressionImpl<?>)j).asValue(this)).append(" ");
         }
diff --git a/pom.xml b/pom.xml
index 16c8d61..f4893c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,7 +80,7 @@
         <mysql.connector.version>5.1.47</mysql.connector.version>
         <mariadb.connector.version>2.2.0</mariadb.connector.version>
         <postgresql.connector.version>42.2.5</postgresql.connector.version>
-        <mssql.connector.version>7.2.0.jre8</mssql.connector.version>
+        <mssql.connector.version>7.2.1</mssql.connector.version>
 
         <!-- other common versions -->
         <slf4j.version>1.7.23</slf4j.version>


[openjpa] 02/03: OPENJPA-2753 add info about how to debug SQLServer

Posted by st...@apache.org.
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 87422c8323f92a584b281917e9342b1bb703b452
Author: Mark Struberg <st...@apache.org>
AuthorDate: Fri Feb 8 09:49:14 2019 +0100

    OPENJPA-2753 add info about how to debug SQLServer
---
 openjpa-project/BUILDING.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/openjpa-project/BUILDING.txt b/openjpa-project/BUILDING.txt
index 9e8bc15..07358e2 100644
--- a/openjpa-project/BUILDING.txt
+++ b/openjpa-project/BUILDING.txt
@@ -212,6 +212,9 @@ For running against a h2 based installation:
 For running against a hsqldb based installation:
  -ea -Dopenjpa.ConnectionDriverName=org.hsqldb.Driver -Dopenjpa.ConnectionURL=jdbc:hsqldb:mem:openjpa20-hsqldb-database -Dopenjpa.ConnectionUserName=sa -Dopenjpa.ConnectionPassword=
 
+For running tests against a SQLServer Docker based installation:
+ -ea -Dopenjpa.ConnectionDriverName=com.microsoft.sqlserver.jdbc.SQLServerDriver -Dopenjpa.ConnectionURL=jdbc:sqlserver://localhost:1433 -Dopenjpa.ConnectionUserName=SA -Dopenjpa.ConnectionPassword=OpenJP8tst
+
 TODO: finish!
 
 For starting tests in `openjpa-persistence-jdbc` inside a compiler you can also trigger all the enhancement manually via: