Commit eb975429 authored by Thomas Huster's avatar Thomas Huster

[21097] execute stream named query impl and use for invoices

parent 56e77416
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
......@@ -66,6 +67,26 @@ public class NamedQuery<R, T> implements INamedQuery<R> {
}
}
@SuppressWarnings("unchecked")
@Override
public Stream<R> executeAsStreamWithParameters(Map<String, Object> parameters){
parameters.forEach((k, v) -> {
v = resolveValue(v);
query.setParameter(k, v);
});
query.setHint(QueryHints.MAINTAIN_CACHE, HintValues.FALSE);
if (returnValueClazz.equals(interfaceClazz)) {
Stream<R> ret = (Stream<R>) query
.getResultStream().map(e -> adapterFactory
.getModelAdapter((EntityWithId) e, interfaceClazz, true).orElse(null))
.filter(o -> o != null);
return ret;
} else {
// query result list can contain null values, we do not want to see them
return (Stream<R>) query.getResultStream().filter(r -> r != null);
}
}
@Override
public Optional<R> executeWithParametersSingleResult(Map<String, Object> parameters) {
List<R> result = executeWithParameters(parameters);
......
......@@ -41,8 +41,8 @@ public class EntityChangeEventListener implements EventHandler {
listeners.add(new WeakReference<AbstractIdModelAdapter<?>>(adapter));
listenerMap.put(entity, listeners);
if (addCount++ > 10000) {
if(listenerMap.size() > 10000) {
if (addCount++ > 25000) {
if (listenerMap.size() > 25000) {
cleanup();
}
addCount = 0;
......
......@@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.component.annotations.Component;
......@@ -309,8 +310,8 @@ public class InvoiceService implements IInvoiceService {
public List<IInvoice> getInvoices(IEncounter encounter){
INamedQuery<IInvoiceBilled> query =
CoreModelServiceHolder.get().getNamedQuery(IInvoiceBilled.class, "encounter");
List<IInvoiceBilled> invoicebilled =
query.executeWithParameters(query.getParameterMap("encounter", encounter));
Stream<IInvoiceBilled> invoicebilled =
query.executeAsStreamWithParameters(query.getParameterMap("encounter", encounter));
HashSet<IInvoice> uniqueInvoices = new HashSet<IInvoice>();
invoicebilled.forEach(ib -> uniqueInvoices.add(ib.getInvoice()));
return new ArrayList<IInvoice>(uniqueInvoices);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment