public class StreamableLazyForeignCollection<T,ID> extends LazyForeignCollection<T,ID>
Stream
s if running with JDK8+. Fortuitously this can
be compiled under JDK6 even with the unknown imports as long as the code doesn't use lambdas or any newer language
features. This allows ORMLite to stay compatible with older class files but still provide better stream support for
Java8+.
We are trying to fix the below code issue where Account.orders is a LazyForeignCollection
.
try (Streamstream = account.getOrders().stream();) { Order firstOrder = stream.findFirst().orElse(null); }
Without this class, the spliterator that is returned by spliterator()
has the Spliterator.SIZED
characteristic enabled which implies that the collection is in memory and it is cheap to estimate its size -- with a
lazy collection, this can be very expensive and it causes the collection to be iterated across an additional time
unnecessarily. Also, the Stream
returned from the stream()
method registers a
BaseStream.onClose(Runnable)
runnable to ensure that the iterator is properly closed once the
BaseStream.close()
method is called.
WARNING: because we are currently building with a JDK before 8, this class cannot be unit tested.
dao
Constructor and Description |
---|
StreamableLazyForeignCollection(Dao<T,ID> dao,
Object parent,
Object parentId,
FieldType foreignFieldType,
String orderColumn,
boolean orderAscending) |
Modifier and Type | Method and Description |
---|---|
CloseableSpliterator<T> |
spliterator() |
java.util.stream.Stream<T> |
stream() |
closeableIterator, closeableIterator, closeLastIterator, contains, containsAll, equals, getWrappedIterable, getWrappedIterable, hashCode, isEager, isEmpty, iterator, iterator, iteratorThrow, iteratorThrow, refreshAll, refreshCollection, remove, removeAll, size, toArray, toArray, toList, updateAll
add, addAll, clear, getDao, getPreparedQuery, refresh, retainAll, update
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
parallelStream, removeIf
public CloseableSpliterator<T> spliterator()
public java.util.stream.Stream<T> stream()
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.