18 package org.turro.jpa.stream;
20 import java.util.function.Consumer;
21 import java.util.stream.Stream;
22 import org.hibernate.query.Query;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.jpa.Dao;
25 import org.turro.jpa.DaoManager;
26 import org.turro.jpa.query.AbstractJpaQuery;
27 import org.turro.sql.SqlClause;
28 import org.turro.util.AtomicCounter;
36 private final Dao dao;
38 private final SqlClause sc;
69 public <T>
void forEach(Consumer<T> action) {
79 public Stream<T>
stream(
int batchSize) {
83 q = (Query) manager.createQuery(query.
query());
84 }
else if(wc !=
null) {
85 q = (Query) manager.createQuery(wc.
getClause());
87 }
else if(sc !=
null) {
88 q = (Query) manager.createQuery(sc.clause());
95 openStreams.increment();
96 return (Stream<T>) q.<T>
stream().onClose(() -> {
98 openStreams.decrement();
134 private static final AtomicCounter openStreams =
new AtomicCounter();
void setNamedParameters(Query q)
void addClause(String clause)
void setNamedParameters(Query q, Map< String, Object > parameters)
DaoStream(Dao dao, WhereClause wc)
DaoStream(Dao dao, AbstractJpaQuery< T > query)
static AtomicCounter getCounter()
DaoStream(Dao dao, SqlClause sc)
Stream< T > stream(int batchSize)
DaoStream(Dao dao, String query)