changeset 139:9df089b0d69d

Improve performance of ResulSet methods getDate(), getTime() getTimestamp() in case the value is NULL.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 27 Jul 2017 19:14:52 +0200 (2017-07-27)
parents f97c111db06f
children c43c293f3d58
files src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -2782,6 +2782,16 @@ public class MonetResultSet extends Mone
 	public java.sql.Date getDate(int columnIndex, Calendar cal)
 		throws SQLException
 	{
+		// to avoid unnecessary work, check for NULL value and invalid columnIndex first
+		try {
+			if (tlp.values[columnIndex - 1] == null) {
+				lastReadWasNull = true;
+				return null;
+			}
+		} catch (IndexOutOfBoundsException e) {
+			throw newSQLInvalidColumnIndexException(columnIndex);
+		}
+
 		if (cal == null) {
 			cal = Calendar.getInstance();
 		}
@@ -2860,6 +2870,16 @@ public class MonetResultSet extends Mone
 	public Time getTime(int columnIndex, Calendar cal)
 		throws SQLException
 	{
+		// to avoid unnecessary work, check for NULL value and invalid columnIndex first
+		try {
+			if (tlp.values[columnIndex - 1] == null) {
+				lastReadWasNull = true;
+				return null;
+			}
+		} catch (IndexOutOfBoundsException e) {
+			throw newSQLInvalidColumnIndexException(columnIndex);
+		}
+
 		if (cal == null) {
 			cal = Calendar.getInstance();
 		}
@@ -2938,6 +2958,16 @@ public class MonetResultSet extends Mone
 	public Timestamp getTimestamp(int columnIndex, Calendar cal)
 		throws SQLException
 	{
+		// to avoid unnecessary work, check for NULL value and invalid columnIndex first
+		try {
+			if (tlp.values[columnIndex - 1] == null) {
+				lastReadWasNull = true;
+				return null;
+			}
+		} catch (IndexOutOfBoundsException e) {
+			throw newSQLInvalidColumnIndexException(columnIndex);
+		}
+
 		if (cal == null) {
 			cal = Calendar.getInstance();
 		}