List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:fr.amapj.service.services.meslivraisons.MesLivraisonsService.java
/** * /* w w w . ja v a2 s . co m*/ */ private List<ContratCell> getAllQte(EntityManager em, Date dateDebut, Date dateFin, Utilisateur user) { Query q = em.createQuery("select c from ContratCell c WHERE " + "c.modeleContratDate.dateLiv>=:deb AND " + "c.modeleContratDate.dateLiv<=:fin and " + "c.contrat.utilisateur =:user " + "order by c.modeleContratDate.dateLiv, c.contrat.modeleContrat.producteur.id, c.contrat.modeleContrat.id , c.modeleContratProduit.indx"); q.setParameter("deb", dateDebut, TemporalType.DATE); q.setParameter("fin", dateFin, TemporalType.DATE); q.setParameter("user", user); List<ContratCell> prods = q.getResultList(); return prods; }
From source file:de.iai.ilcd.model.dao.UserDao.java
@SuppressWarnings("unchecked") public List<Long> getUserIds(List<Organization> orgs) { if (orgs == null || orgs.isEmpty()) { return null; }//from www.jav a 2 s .c o m EntityManager em = PersistenceUtil.getEntityManager(); List<Long> orgIds = new ArrayList<Long>(); for (Organization o : orgs) { orgIds.add(o.getId()); } try { return (List<Long>) em.createQuery("SELECT DISTINCT u.id FROM User u WHERE u.organization.id IN(" + StringUtils.join(orgIds, ',') + ")").getResultList(); } catch (Exception e) { return null; } }
From source file:fr.amapj.service.services.meslivraisons.MesLivraisonsService.java
/** * //from w w w.j av a 2 s.c o m */ private List<ContratCell> getAllQte(EntityManager em, Date dateDebut, Date dateFin, Producteur producteur) { Query q = em.createQuery("select c from ContratCell c " + "WHERE c.modeleContratDate.dateLiv>=:deb AND " + "c.modeleContratDate.dateLiv<=:fin and " + "c.contrat.modeleContrat.producteur =:prod " + "order by c.modeleContratDate.dateLiv, c.contrat.modeleContrat.producteur.id, c.contrat.modeleContrat.id , c.modeleContratProduit.indx"); q.setParameter("deb", dateDebut, TemporalType.DATE); q.setParameter("fin", dateFin, TemporalType.DATE); q.setParameter("prod", producteur); List<ContratCell> prods = q.getResultList(); return prods; }
From source file:fr.amapj.service.services.saisiepermanence.PermanenceService.java
private List<Utilisateur> getUtilisateursPermanenceFuture(EntityManager em) { // On recherche tous les utilisateurs qui ont une permanence dans le futur Query q = em.createQuery("select distinct(dpu.utilisateur) from DatePermanenceUtilisateur dpu " + "where dpu.datePermanence.datePermanence>=:d1 "); q.setParameter("d1", new Date()); List<Utilisateur> us = q.getResultList(); return us;//from w w w .j a v a 2 s.co m }
From source file:fr.amapj.service.services.saisiepermanence.PermanenceService.java
/** * Permet de charger la liste de tous les distributions * dans une transaction en lecture//from w w w . ja v a 2s .co m */ @DbRead public List<PermanenceDTO> getAllDistributions() { EntityManager em = TransactionHelper.getEm(); List<PermanenceDTO> res = new ArrayList<>(); Query q = em.createQuery("select d from DatePermanence d order by d.datePermanence"); List<DatePermanence> ds = q.getResultList(); for (DatePermanence d : ds) { PermanenceDTO dto = createDistributionDTO(em, d); res.add(dto); } return res; }
From source file:fr.amapj.service.services.meslivraisons.MesLivraisonsService.java
private List<DatePermanence> getAllDistributionsForUtilisateur(EntityManager em, Date dateDebut, Date dateFin, Utilisateur utilisateur) {//ww w. j a v a 2s.c om Query q = em.createQuery("select distinct(du.datePermanence) from DatePermanenceUtilisateur du WHERE " + "du.datePermanence.datePermanence>=:deb and " + "du.datePermanence.datePermanence<=:fin and " + "du.utilisateur=:user " + "order by du.datePermanence.datePermanence"); q.setParameter("deb", dateDebut, TemporalType.DATE); q.setParameter("fin", dateFin, TemporalType.DATE); q.setParameter("user", utilisateur); List<DatePermanence> dds = q.getResultList(); return dds; }
From source file:com.haulmont.cuba.core.jmx.PersistenceManager.java
@Authenticated @Override// ww w. ja va 2 s . c om public String jpqlLoadList(String queryString) { try { Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); Query query = em.createQuery(queryString); QueryParser parser = QueryTransformerFactory.createParser(queryString); Set<String> paramNames = parser.getParamNames(); for (String paramName : paramNames) { security.setQueryParam(query, paramName); } List resultList = query.getResultList(); tx.commit(); StrBuilder sb = new StrBuilder(); for (Object element : resultList) { if (element instanceof Object[]) { sb.appendWithSeparators((Object[]) element, " | "); } else { sb.append(element); } sb.append("\n"); } return sb.toString(); } finally { tx.end(); } } catch (Throwable e) { log.error("jpqlLoadList error", e); return ExceptionUtils.getStackTrace(e); } }
From source file:de.ks.idnadrev.information.view.InformationOverviewDS.java
protected List<Tag> getTags(List<String> tagNames, EntityManager em) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Tag> query = builder.createQuery(Tag.class); Root<Tag> root = query.from(Tag.class); Path<String> namePath = root.get(KEY_NAME); query.select(root);//from w w w .j av a2 s .c o m query.where(namePath.in(tagNames)); return em.createQuery(query).getResultList(); }
From source file:fr.amapj.service.services.saisiepermanence.PermanenceService.java
/** * /*from w w w. ja va 2 s.com*/ */ private List<PermanenceDTO> getDistributionsFutures(EntityManager em, Utilisateur user) { Date dateDebut = fr.amapj.common.DateUtils.firstMonday(new Date()); Query q = em.createQuery("select distinct(du.datePermanence) from DatePermanenceUtilisateur du WHERE " + "du.datePermanence.datePermanence>=:deb and " + "du.utilisateur=:user " + "order by du.datePermanence.datePermanence"); q.setParameter("deb", dateDebut, TemporalType.DATE); q.setParameter("user", user); List<DatePermanence> dds = q.getResultList(); List<PermanenceDTO> res = new ArrayList<PermanenceDTO>(); for (DatePermanence dd : dds) { PermanenceDTO dto = createDistributionDTO(em, dd); res.add(dto); } return res; }
From source file:de.egore911.opengate.services.PilotService.java
@GET @Path("/register") @Produces("text/html") @Documentation("Generates a login form to be used to test the registration service.") public String getRegisterForm() { StringBuilder buffer = new StringBuilder(); buffer.append(/*w w w . j ava2 s.co m*/ "<html><head></head><body><form method=\"post\"><table><tr><th>Login:</th><td><input type=\"login\" name=\"login\"></td></tr><tr><th>E-Mail:</th><td><input type=\"email\" name=\"email\"></td></tr><tr><th>Faction:</th><td><select name=\"faction_id\">"); EntityManager em = EntityManagerFilter.getEntityManager(); List<Faction> factions = em.createQuery("select faction from Faction faction order by name") .getResultList(); for (Faction faction : factions) { buffer.append("<option value=\""); buffer.append(faction.getKey().getId()); buffer.append("\">"); buffer.append(faction.getName()); buffer.append("</option>"); } buffer.append( "</select></td></tr><tr><td></td><td><input type=\"submit\"></td></tr></table></form></body></html>"); return buffer.toString(); }