
com.github.vincentrussell.query.mongodb.sql.converter.QueryResultIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql-to-mongo-db-query-converter Show documentation
Show all versions of sql-to-mongo-db-query-converter Show documentation
sql-to-mongo-db-query-converter helps you build quieres for
MongoDb based on Queries provided in SQL.
package com.github.vincentrussell.query.mongodb.sql.converter;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoIterable;
import org.calrissian.mango.collect.AbstractCloseableIterator;
import java.io.IOException;
/**
* Wrapper {@link java.util.Iterator} around the {@link MongoCursor}.
* @param the type of elements returned by this iterator
*/
public class QueryResultIterator extends AbstractCloseableIterator {
private final MongoCursor mongoCursor;
/**
* Default constructor.
* @param mongoIterable the wrapped {@link MongoIterable}
*/
public QueryResultIterator(final MongoIterable mongoIterable) {
this.mongoCursor = mongoIterable.iterator();
}
/**
* {@inheritDoc}
* @return the next element if there was one. If {@code endOfData} was called during execution,
* the return value will be ignored.
*/
@Override
protected T computeNext() {
if (mongoCursor.hasNext()) {
return mongoCursor.next();
} else {
mongoCursor.close();
}
return endOfData();
}
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
mongoCursor.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy