From 9a7300b2a8f713a0f17d4a72c512d23f1998487e Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 14 Nov 2012 21:24:31 +0100 Subject: [PATCH 08/25] Fix a bug with a query returning a Collection, when one of the value in the ResultSet returned was NULL (the query used to throw NoSuchElementException). --- .../eodsql/spi/util/CollectionWrapperFactory.java | 7 +++++-- eodsql/test/net/lemnik/eodsql/CollectionQuery.java | 3 +++ eodsql/test/net/lemnik/eodsql/CollectionTest.java | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/eodsql/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java b/eodsql/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java index 6e096f4..219a6dd 100644 --- a/eodsql/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java +++ b/eodsql/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java @@ -419,11 +419,14 @@ class CollectionWrapperFactory implements ResultSetWrapper.Factory { boolean finished = false; + boolean resultAvailable = false; + public boolean hasNext() { - if(!finished && next == null) { + if(!finished && !resultAvailable) { try { if(results.next()) { next = binding.unmarshall(results); + resultAvailable = true; } else { finished = true; } @@ -438,7 +441,7 @@ class CollectionWrapperFactory implements ResultSetWrapper.Factory { public E next() { if(hasNext()) { final E object = next; - next = null; + resultAvailable = false; return object; } diff --git a/eodsql/test/net/lemnik/eodsql/CollectionQuery.java b/eodsql/test/net/lemnik/eodsql/CollectionQuery.java index ba2c1f5..8ef9cec 100644 --- a/eodsql/test/net/lemnik/eodsql/CollectionQuery.java +++ b/eodsql/test/net/lemnik/eodsql/CollectionQuery.java @@ -32,6 +32,9 @@ public interface CollectionQuery extends BaseQuery { @Select("SELECT * FROM birthdays") List selectList(); + @Select("SELECT birthdate FROM birthdays") + List selectListDates(); + @Select("SELECT * FROM birthdays") SortedSet selectSortedSet(); diff --git a/eodsql/test/net/lemnik/eodsql/CollectionTest.java b/eodsql/test/net/lemnik/eodsql/CollectionTest.java index d141ff1..ed60e3d 100644 --- a/eodsql/test/net/lemnik/eodsql/CollectionTest.java +++ b/eodsql/test/net/lemnik/eodsql/CollectionTest.java @@ -41,6 +41,11 @@ public class CollectionTest extends EoDTestCase { query.insert(date(1973, 8, 9), "John"); query.insert(date(1967, 4, 1), "Earl"); } + + private void insertDataWithNull() throws Exception { + insertData(); + query.insert(null, "Nobody"); + } public void testList() throws Exception { insertData(); @@ -55,6 +60,20 @@ public class CollectionTest extends EoDTestCase { assertTrue(birthdays.contains(new Birthday(date(1967, 4, 1), "Earl"))); } + public void testListWithNull() throws Exception { + insertDataWithNull(); + + final List birthdays = query.selectListDates(); + + assertNotNull(birthdays); + assertEquals(birthdays.size(), 4); + + assertTrue(birthdays.contains(date(1984, 4, 26))); + assertTrue(birthdays.contains(date(1973, 8, 9))); + assertTrue(birthdays.contains(date(1967, 4, 1))); + assertTrue(birthdays.contains(null)); + } + public void testSet() throws Exception { // we expect only one of each out, so we insert 2 insertData(); -- 1.8.0