diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ac4fb21f48a..cc3f6dd62b2 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -221,6 +221,10 @@ Other Changes * SOLR-9358: [AngularUI] In Cloud->Tree file view area, collapse metadata by default (janhoy) +* SOLR-9256: asserting hasNext() contract in JdbcDataSource in DataImportHandler (Kristine Jetzke via Mikhai Khludnev) + +* SOLR-9209: extracting JdbcDataSource.createResultSetIterator() for extension (Kristine Jetzke via Mikhai Khludnev) + ================== 6.1.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java index 09ad775a4ec..ce8671a0f51 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java @@ -280,10 +280,14 @@ public class JdbcDataSource extends resultSetIterator.close(); resultSetIterator = null; } - resultSetIterator = new ResultSetIterator(query); + resultSetIterator = createResultSetIterator(query); return resultSetIterator.getIterator(); } + protected ResultSetIterator createResultSetIterator(String query) { + return new ResultSetIterator(query); + } + private void logError(String msg, Exception e) { LOG.warn(msg, e); } diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java index b6d05c441f1..7853ad154f6 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java @@ -510,6 +510,45 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase { DriverManager.deregisterDriver(driver); } } + + + @Test + public void testEmptyResultSet() throws Exception { + MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource); + + props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB"); + EasyMock.expect(dataSource.getConnection()).andReturn(connection); + + jdbcDataSource.init(context, props); + + connection.setAutoCommit(false); + + Statement statement = mockControl.createMock(Statement.class); + EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) + .andReturn(statement); + statement.setFetchSize(500); + statement.setMaxRows(0); + EasyMock.expect(statement.execute("query")).andReturn(true); + ResultSet resultSet = mockControl.createMock(ResultSet.class); + EasyMock.expect(statement.getResultSet()).andReturn(resultSet); + ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class); + EasyMock.expect(resultSet.getMetaData()).andReturn(metaData); + EasyMock.expect(metaData.getColumnCount()).andReturn(0); + EasyMock.expect(resultSet.next()).andReturn(false); + resultSet.close(); + EasyMock.expect(statement.getMoreResults()).andReturn(false); + EasyMock.expect(statement.getUpdateCount()).andReturn(-1); + statement.close(); + + mockControl.replay(); + + Iterator> resultSetIterator = jdbcDataSource.getData("query"); + resultSetIterator.hasNext(); + resultSetIterator.hasNext(); + + mockControl.verify(); + } + @Test @Ignore("Needs a Mock database server to work") public void testBasic() throws Exception {