Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Issue/621 #624

Merged
merged 2 commits into from
Jan 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.oasp.module.jpa.dataaccess.base;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
Expand All @@ -10,6 +12,7 @@
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import net.sf.mmm.util.entity.api.PersistenceEntity;
Expand Down Expand Up @@ -171,13 +174,26 @@ public List<E> findAll(Iterable<ID> ids) {
CriteriaQuery<E> query = builder.createQuery(getEntityClass());
Root<E> root = query.from(getEntityClass());
query.select(root);
query.where(root.get("id").in(ids));
query.where(root.get("id").in(toCollection(ids)));
TypedQuery<E> typedQuery = getEntityManager().createQuery(query);
List<E> resultList = typedQuery.getResultList();
LOG.debug("Query for selection of {} objects returned {} hit(s).", getEntityName(), resultList.size());
return resultList;
}

/**
* @param ids sequence of id
* @return a collection of these ids to use {@link Predicate#in(Collection)} for instance
*/
protected Collection<ID> toCollection(Iterable<ID> ids) {

final Collection<ID> idsList = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will technically fix it but is a kind of waste if the Iterable already is a Collection. IMHO we should first check with instanceof and then only cast to avoid pointless conversion. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right. I'll change my PR.

for (final ID id : ids) {
idsList.add(id);
}
return idsList;
}

@Override
public void delete(ID id) {

Expand Down