List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.PlaneDaoImpl.java
@Override public List<Plane> getByAirline(Long airline) { try {/*from w w w . jav a 2 s .c o m*/ Query q = em.createQuery("FROM Plane WHERE airline_id=:airline"); q.setParameter("airline", airline); List<Plane> planes = q.getResultList(); return Collections.unmodifiableList(planes); } catch (PersistenceException | IllegalArgumentException ex) { throw new DataAccessException(ex.getMessage(), ex) { }; } }
From source file:org.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java
public Page<ServiceEntity> getServiceListForUserAndKeyword(String keyword, String userName, Pagination pagination) {// w w w .j a v a 2s . com // Query String queryString = String.format(USERNAME_AND_KEYWORD_SERVICE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, ServiceEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName)); query.setParameter(4, pagination.getSortBy()); query.setParameter(5, pagination.getPerPage()); query.setParameter(6, pagination.getPage() * pagination.getPerPage()); List<ServiceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_AND_KEYWORD_SERVICE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<ServiceEntity>(results, null, count); }
From source file:org.yestech.lib.jpa.YesJpaTemplate.java
public int bulkUpdateNamedQuery(final String queryName, final Object... values) throws DataAccessException { return (Integer) execute(new JpaCallback() { @Override//from ww w . ja v a 2 s . c om public Object doInJpa(EntityManager em) throws PersistenceException { Query queryObject = em.createNamedQuery(queryName); if (values != null) { for (int i = 0; i < values.length; i++) { queryObject.setParameter(i, values[i]); } } return queryObject.executeUpdate(); } }); }
From source file:com.solidmaps.webapp.dao.LicensePCDAO.java
public LicensePCEntity findByNumCertified(String numCertified) { StringBuilder sb = new StringBuilder(); sb.append("from LicensePCEntity e where e.numCertified =:numCertified "); sb.append("and e.isActive =:active "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("numCertified", numCertified); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicensePCEntity> list = query.getResultList(); if (list != null && !list.isEmpty()) { return list.get(0); }//w ww . j a va 2s .c o m return null; }
From source file:com.expressui.sample.dao.UserReferenceCleanupAdvice.java
@Before("(bean(genericDao) || bean(userDao)) && execution(* *.remove(Object)) && args(user)") @Transactional//from w ww . j av a 2s . com public void remove(User user) { Query query = entityManager .createQuery("UPDATE Account a SET a.assignedTo = null WHERE a.assignedTo = :user"); query.setParameter("user", user); query.executeUpdate(); query = entityManager.createQuery("UPDATE Contact c SET c.assignedTo = null WHERE c.assignedTo = :user"); query.setParameter("user", user); query.executeUpdate(); query = entityManager .createQuery("UPDATE Opportunity o SET o.assignedTo = null WHERE o.assignedTo = :user"); query.setParameter("user", user); query.executeUpdate(); }
From source file:com.ovalsearch.dao.impl.ApplicationsDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w w w .j ava 2 s.co m @Transactional public Applications getApplicationByApkId(String apkId) { Query query = entityDao.getEntityManager() .createQuery("Select applications from Applications applications where apkId =:apkId"); query.setParameter("apkId", apkId); List<Applications> applications = (List<Applications>) query.getResultList(); if (applications != null && applications.size() > 0) { return applications.get(0); } else { return null; } }
From source file:org.mifos.loan.repository.StandardLoanDao.java
@Override @Transactional(readOnly = true)/*from w ww . ja va 2s .com*/ public Boolean loansExistForLoanProduct(Integer loanProductId) { Query query = entityManager .createQuery("select count(*) from Loan loan where loan.loanProduct.id = :loanProductId"); query.setParameter("loanProductId", loanProductId); return Boolean.valueOf(((Long) query.getResultList().get(0)) > 0); }
From source file:com.solidmaps.webapp.dao.LicensePCDAO.java
/** * Obtem a Ultima licena cadastrada//from w w w. ja v a2 s.c o m * * @param idCompany * @return */ public LicensePCEntity findByLastProtocoled(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 dateExpiration desc "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("idCompany", idCompany); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicensePCEntity> list = query.getResultList(); if (list != null && !list.isEmpty()) { return list.get(0); } return null; }
From source file:com.solidmaps.webapp.dao.LicensePCDAO.java
/** * A licensa atual a com Data de Expirao mais atual * /* w ww. jav a2 s .c om*/ * @param idCompany * @return */ public LicensePCEntity findLastInvoice(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 dateExpiration desc "); Query query = super.getEm().createQuery(sb.toString()); query.setParameter("idCompany", idCompany); query.setParameter("active", Boolean.TRUE); @SuppressWarnings("unchecked") List<LicensePCEntity> list = query.getResultList(); if (list != null && !list.isEmpty()) { return list.get(0); } return null; }
From source file:eu.planets_project.tb.impl.persistency.ServiceRecordPersistencyImpl.java
@SuppressWarnings("unchecked") public List<ServiceRecordImpl> getAllServiceRecordsByServiceName(String name) { Query query = manager.createQuery("from ServiceRecordImpl where serviceName=:name"); query.setParameter("name", name); return (List<ServiceRecordImpl>) query.getResultList(); }