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 2021/04/08 12:57:00 UTC
[openjpa] 01/02: OPENJPA-2864 use Timestamp precision from Column
if set
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 a68835381e0975aa1c75cd381e5e37d63b1d0db1
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Apr 8 14:54:22 2021 +0200
OPENJPA-2864 use Timestamp precision from Column if set
---
.../org/apache/openjpa/jdbc/sql/DBDictionary.java | 27 +++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
index e638d8e..a9a1030 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
@@ -313,6 +313,11 @@ public class DBDictionary
public int maxEmbeddedBlobSize = -1;
public int maxEmbeddedClobSize = -1;
public int inClauseLimit = -1;
+
+ /**
+ * Attention, while this is named datePrecision it actually only get used for Timestamp handling!
+ * @see StateManagerImpl#roundTimestamp(Timestamp, int)
+ */
public int datePrecision = MILLI;
/**
@@ -1441,7 +1446,27 @@ public class DBDictionary
public void setTimestamp(PreparedStatement stmnt, int idx, Timestamp val, Calendar cal, Column col)
throws SQLException {
- val = StateManagerImpl.roundTimestamp(val, datePrecision);
+ int usePrecision = datePrecision;
+ if (col != null) {
+ int columnPrecision = col.getPrecision();
+ if (columnPrecision >= 0) { // negative value means we don't know
+ if (columnPrecision == 0) {
+ usePrecision = SEC;
+ }
+ else if (columnPrecision == 3) {
+ usePrecision = MILLI;
+ }
+ else if (columnPrecision == 6) {
+ usePrecision = MICRO;
+ }
+ else if (columnPrecision == 9) {
+ usePrecision = NANO;
+ }
+ // rest defaults to datePrecision
+ }
+ }
+
+ val = StateManagerImpl.roundTimestamp(val, usePrecision);
if (cal == null)
stmnt.setTimestamp(idx, val);