Completed Exercises 1 and 2.
Exercise #1 - Bug hunter
Grouped the films by title to avoid returning duplicate entries. Changed only the inline SQL query on PostgresRepository class. (Method - filmByActorSupplier)
Exercise #2 - Document and refactor
Documented the ResultSetIterator class using Doc comments. I made an improvement to this class and optimized its performance.
In this implementation, the class implements the AutoCloseable interface and adds a close() method that explicitly closes the ResultSet, PreparedStatement, and Connection objects used by the iterator.
class ResultSetIterator<T> implements Iterator<T>, AutoCloseable {
public void close(){
try {
resultSet.close();
statement.close();
connection.close();
} catch (SQLException ex) {
throw new RepositoryException(ex);
}
}
The hasNext() method calls the close() method when there are no more results in the ResultSet object.