Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor(Raw)Result: shouldn't they implement the Iterator interface instead of the Iterable interface? #51

Closed
christian-lechner opened this issue Sep 21, 2016 · 4 comments
Assignees
Milestone

Comments

@christian-lechner
Copy link

christian-lechner commented Sep 21, 2016

Hello!

I'm currently working with CursorResult and CursorRawResult classes. Both of them implement the Iterable interface, enabling us to iterate more than once over the result.

However, the iterator method returns always the same iterator and thus the result can only be consumed once.

@Override
public Iterator<T> iterator() {
        if (iter == null) {
            iter = new CursorIterator();
        }
        return iter;
    }

It makes perfectly sense that the result can only be consumed once, because the cursor of the DB is also moved with continueQuery method. One could aggregate the results instead of overwriting it and always provide a new iterator. But the list can grow huge and there is also the asList method.

Wouldn't it be more clear for the user if CursorResult and CursorRawResult would implement the Iterator interface, indicating that it can only be consumed once?

And the asList method returns only a complete list if no object is already consumed from the iterator. Should the asList method be called asListRemaining just like the forEachRemaining of the Iterator interface? Or completely remove this method to avoid confusing?

@christian-lechner christian-lechner changed the title Cursor(Raw)Result: why do they implement the Iterable interface? Cursor(Raw)Result: why do they implement the Iterable interface and not the Iterator interface? Sep 21, 2016
@christian-lechner christian-lechner changed the title Cursor(Raw)Result: why do they implement the Iterable interface and not the Iterator interface? Cursor(Raw)Result: shouldn't they implement the Iterator interface instead of the Iterable interface? Sep 21, 2016
@mvollmary
Copy link

Thanks for your feedback. This is a really good point.

Currently we rewrite the Java Driver. It gets a new api, async and VelocyPack/VelocyStream under the hood.
I already changed the implementation of our new cursor with your input. (which your can find here)

The new driver version will probably be released by the end of the month, but you can already try it out. (Branch 4.0)
Your feedback is much appreciated.

@mvollmary mvollmary self-assigned this Sep 21, 2016
@mvollmary mvollmary added this to the 4.0 milestone Sep 21, 2016
@christian-lechner
Copy link
Author

christian-lechner commented Sep 21, 2016

Awesome! New driver looks great, looking forward to it. I will switch to the new version in my new project.

4.0 driver version needs ArangoDB 3.1. Can you tell me when ArangoDB 3.1 will be released?

@mvollmary
Copy link

We will release the first beta by the beginning of october, at this time we will release the driver in version 4.0.0 too.

@christian-lechner
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants