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 all commits
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,30 @@ 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) {

if (ids instanceof Collection) {
return (Collection<ID>) ids;
}

final Collection<ID> idsList = new ArrayList<>();
for (final ID id : ids) {
idsList.add(id);
}
return idsList;
}

@Override
public void delete(ID id) {

Expand Down