OPENJPA-2864 use Timestamp precision from Column if set

This commit is contained in:
Mark Struberg 2021-04-08 14:54:22 +02:00
parent 0fc957a02b
commit a68835381e
1 changed files with 26 additions and 1 deletions

View File

@ -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);