You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by th...@apache.org on 2019/11/10 18:36:23 UTC
[commons-dbutils] 01/02: Always copy Date, Time,
Timestamp objects on get or set. Handle null byte[] on setter.
This is an automated email from the ASF dual-hosted git repository.
thecarlhall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git
commit b0971d443652a03090ae94ed0c01e21c408b8480
Author: Carl Hall <th...@apache.org>
AuthorDate: Sun Nov 3 13:52:02 2019 -0800
Always copy Date, Time, Timestamp objects on get or set.
Handle null byte[] on setter.
---
.../dbutils/wrappers/SqlNullCheckedResultSet.java | 29 ++++++++++++++++------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java b/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
index ea7617a..b617ca5 100644
--- a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
+++ b/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
@@ -343,7 +343,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @return the value
*/
public Time getNullTime() {
- return this.nullTime;
+ return this.nullTime != null ? new Time(this.nullTime.getTime()) : null;
}
/**
@@ -353,7 +353,13 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @return the value
*/
public Timestamp getNullTimestamp() {
- return this.nullTimestamp != null ? new Timestamp(this.nullTimestamp.getTime()) : null;
+ if (this.nullTimestamp == null) {
+ return null;
+ }
+
+ Timestamp ts = new Timestamp(this.nullTimestamp.getTime());
+ ts.setNanos(this.nullTimestamp.getNanos());
+ return ts;
}
/**
@@ -460,9 +466,13 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @param nullBytes the value
*/
public void setNullBytes(final byte[] nullBytes) {
- final byte[] copy = new byte[nullBytes.length];
- System.arraycopy(nullBytes, 0, copy, 0, nullBytes.length);
- this.nullBytes = copy;
+ if (nullBytes != null) {
+ final byte[] copy = new byte[nullBytes.length];
+ System.arraycopy(nullBytes, 0, copy, 0, nullBytes.length);
+ this.nullBytes = copy;
+ } else {
+ this.nullBytes = null;
+ }
}
/**
@@ -582,7 +592,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @param nullTime the value
*/
public void setNullTime(final Time nullTime) {
- this.nullTime = nullTime;
+ this.nullTime = nullTime != null ? new Time(nullTime.getTime()) : null;
}
/**
@@ -592,7 +602,12 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @param nullTimestamp the value
*/
public void setNullTimestamp(final Timestamp nullTimestamp) {
- this.nullTimestamp = nullTimestamp != null ? new Timestamp(nullTimestamp.getTime()) : null;
+ if (nullTimestamp != null) {
+ this.nullTimestamp = new Timestamp(nullTimestamp.getTime());
+ this.nullTimestamp.setNanos(nullTimestamp.getNanos());
+ } else {
+ this.nullTimestamp = null;
+ }
}
/**