Commit f79f60fd authored by Matija Obreza's avatar Matija Obreza

Need to join accession.taxonomy for query

parent ac3c7d4e
......@@ -25,6 +25,7 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
......@@ -32,6 +33,7 @@ import javax.persistence.criteria.Root;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.beans.factory.InitializingBean;
......@@ -56,7 +58,11 @@ public class AccessionCustomRepositoryImpl implements AccessionCustomRepository,
Root<Accession> root = cq.from(Accession.class);
cq.select(root);
root.fetch("stoRage", JoinType.LEFT);
// Join<Accession, Taxonomy2> tax = root.join("taxonomy");
Join<Accession, Taxonomy2> tax = null;
if (!uniqueAcceNumbs) {
tax = root.join("taxonomy");
}
List<Predicate> restrictions = new ArrayList<Predicate>();
if (uniqueAcceNumbs) {
......@@ -67,13 +73,13 @@ public class AccessionCustomRepositoryImpl implements AccessionCustomRepository,
// A lot of .. (acceNumb=? and genus=?)
for (int i = 0; i < acceNumbs.size(); i++) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), acceNumbs.get(i)),
criteriaBuilder.equal(root.get("taxonomy.genus"), genera.get(i))));
criteriaBuilder.equal(tax.get("genus"), genera.get(i))));
}
}
cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(new Predicate[] {}))));
cq.distinct(true);
List<Accession> res = em.createQuery(cq).getResultList();
if (LOG.isDebugEnabled())
LOG.debug("*** Loaded accessions " + res.size() + " of " + acceNumbs.size());
......
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