# HG changeset patch # User Martin van Dinther <martin.van.dinther@monetdbsolutions.com> # Date 1501175692 -7200 # Node ID 9df089b0d69df01e4200a4b7c6535c2b26df37ad # Parent f97c111db06fe3515d410ae84cb4d2c1ef4192d2 Improve performance of ResulSet methods getDate(), getTime() getTimestamp() in case the value is NULL. diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java --- 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(); }