List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:pdsanchez.mywebtools.model.dao.jpa.SubcategoryDAOJPAImpl.java
@Override public List<Subcategory> findAll(Category category) { Query q = getEntityManager().createQuery( "select distinct o.subcategory from Tool o where lower(o.category.categoryName) = :name and o.isvalid = 1"); q.setParameter("name", category.getCategoryName().toLowerCase()); return q.getResultList(); }
From source file:com.branded.holdings.qpc.repository.jpa.JpaOwnerRepositoryImpl.java
@Override public Owner findById(int id) { // using 'join fetch' because a single query should load both owners and pets // using 'left join fetch' because it might happen that an owner does not have pets yet Query query = this.em .createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id"); query.setParameter("id", id); return (Owner) query.getSingleResult(); }
From source file:com.linksinnovation.elearning.repository.QuizReportRepository.java
public List<QuizReport> findQuizReport(QuizConditionDTO conditionDTO) { if (null != conditionDTO.getCategory()) { String queryString = query + " WHERE category_id=:cat"; if (null != conditionDTO.getSubcategory()) { queryString = queryString + " AND sub_category_id=:subcat"; }//from www. java 2 s . c om if (null != conditionDTO.getCourse()) { queryString = queryString + " AND course_id=:course"; } if (!conditionDTO.getName().isEmpty()) { queryString = queryString + " AND name LIKE :name"; } if (conditionDTO.getStart() != null && conditionDTO.getEnd() != null) { queryString = queryString + " AND update_date BETWEEN :start AND :end"; } queryString = queryString + " ORDER BY course_id,name ASC"; Query q = em.createNativeQuery(queryString); q.setParameter("cat", conditionDTO.getCategory()); if (null != conditionDTO.getSubcategory()) { q.setParameter("subcat", conditionDTO.getSubcategory()); } if (null != conditionDTO.getCourse()) { q.setParameter("course", conditionDTO.getCourse()); } if (!conditionDTO.getName().isEmpty()) { q.setParameter("name", "%" + conditionDTO.getName() + "%"); } if (conditionDTO.getStart() != null && conditionDTO.getEnd() != null) { q.setParameter("start", conditionDTO.getStart()); q.setParameter("end", conditionDTO.getEnd()); } return mapObject(q.getResultList()); } else if (null == conditionDTO.getCategory()) { String queryString = query; if (!conditionDTO.getName().isEmpty()) { queryString = queryString + " WHERE name LIKE :name"; if (conditionDTO.getStart() != null && conditionDTO.getEnd() != null) { queryString = queryString + " AND update_date BETWEEN :start AND :end"; } } else { if (conditionDTO.getStart() != null && conditionDTO.getEnd() != null) { queryString = queryString + " WHERE update_date BETWEEN :start AND :end"; } } queryString = queryString + " ORDER BY course_id,name ASC"; Query q = em.createNativeQuery(queryString); if (!conditionDTO.getName().isEmpty()) { q.setParameter("name", "%" + conditionDTO.getName() + "%"); } if (conditionDTO.getStart() != null && conditionDTO.getEnd() != null) { q.setParameter("start", conditionDTO.getStart()); q.setParameter("end", conditionDTO.getEnd()); } return mapObject(q.getResultList()); } else { String queryString = query + " ORDER BY course_id,name ASC"; Query q = em.createNativeQuery(queryString); return mapObject(q.getResultList()); } }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPASongStatistics.java
@Override @Transactional/*from w ww. jav a 2 s. c o m*/ public MDOSongStatistics getStatistics(String username, long songSid) { Query query = entityManager.createQuery( "from MDOSongStatistics as a where (a.song.owner.login = :userName AND a.song.sid = :songSid)"); query.setParameter("userName", username); query.setParameter("songSid", songSid); @SuppressWarnings("unchecked") List<MDOSongStatistics> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } return null; }
From source file:com.solidmaps.webapp.dao.LicensePCDAO.java
public List<LicensePCEntity> findByCompany(Integer idCompany) { StringBuilder sb = new StringBuilder(); sb.append("from LicensePCEntity e where e.company.idCompany =:idCompany "); sb.append("and e.isActive =:active "); sb.append("order by dateInsert "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("idCompany", idCompany); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicensePCEntity> list = query.getResultList(); return list;//from w w w . ja va 2 s . com }
From source file:com.brienwheeler.lib.db.dao.PersistentAttributeDaoBase.java
@Override @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public AttrClass findByOwnerAndName(long ownerId, String name) { Query query = entityManager.createQuery( "from " + getEntityClass().getSimpleName() + " where owner_id = :ownerId and name = :name"); query.setParameter("ownerId", ownerId); query.setParameter("name", name); return getSingleResultOrNull(query); }
From source file:DAO.MessagesDAOImpl.java
/** * NOT YET IMPLEMENTED//from w ww.j a va 2s. c o m * * @param auteurId * @return */ @Transactional(readOnly = true) @Override public List<MessagesEntity> findByAuteur(int auteurId) { Query q = em.createQuery("SELECT m FROM MessagesEntity m where m.emetteur.id = ?"); q.setParameter(1, auteurId); return q.getResultList(); }
From source file:com.doculibre.constellio.services.SynonymServicesImpl.java
@SuppressWarnings("unchecked") @Override/* w ww. j a v a 2 s . c o m*/ public List<String> getSynonyms(String text, String collectionName) { EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); StringBuffer sql = new StringBuffer(); sql.append("SELECT SLS.synonym FROM SynonymList_Synonyms SLS, SynonymList SL, RecordCollection RC"); sql.append(" WHERE SLS.synonymList_id=SL.id AND SL.recordCollection_id=RC.id"); sql.append(" AND RC.id = ("); sql.append( " SELECT SL2.recordCollection_id FROM SynonymList_Synonyms SLS2, SynonymList SL2, RecordCollection RC2"); sql.append(" WHERE SLS2.synonymList_id=SL2.id AND SL2.recordCollection_id=RC2.id AND SL2.id = SL.id"); sql.append(" AND RC.name=? AND SLS2.synonym=?"); sql.append(" )"); Query sqlQuery = entityManager.createNativeQuery(sql.toString()); sqlQuery.setParameter(1, collectionName); // RecordCollection collection = ConstellioSpringUtils.getRecordCollectionServices().get(collectionName); // Locale locale = collection.getLocales(); sqlQuery.setParameter(2, text.toLowerCase()); List<String> synonyms = sqlQuery.getResultList(); return synonyms; }
From source file:com.solidmaps.webapp.dao.LicenseEXDAO.java
/** * Obtem a Ultima licena cadastrada/* www . j a va 2 s . c om*/ * * @param idCompany * @return */ public LicenseEXEntity findByLastProtocoled(Integer idCompany) { StringBuilder sb = new StringBuilder(); sb.append("from LicenseEXEntity e where e.company.idCompany =:idCompany "); sb.append("and e.isActive =:active "); sb.append("order by dateExpiration desc "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("idCompany", idCompany); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicenseEXEntity> list = query.getResultList(); if (list != null && !list.isEmpty()) { return list.get(0); } return null; }
From source file:com.solidmaps.webapp.dao.LicenseEXDAO.java
/** * A licensa atual a com Data de Expirao mais atual * //from w w w . j a v a2 s . c om * @param idCompany * @return */ public LicenseEXEntity findLastInvoice(Integer idCompany) { StringBuilder sb = new StringBuilder(); sb.append("from LicenseEXEntity e where e.company.idCompany =:idCompany "); sb.append("and e.isActive =:active "); sb.append("order by dateExpiration desc "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("idCompany", idCompany); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicenseEXEntity> list = query.getResultList(); if (list != null && !list.isEmpty()) { return list.get(0); } return null; }