List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.sun.socialsite.business.impl.JPAThemeSettingsManagerImpl.java
public ThemeSettings getThemeSettingsByDestination(String id) throws SocialSiteException { if (id == null) { throw new SocialSiteException("id is null"); }//from ww w . ja va 2 s . c o m Query query = strategy.getNamedQuery("ThemeSettings.getByDestination"); query.setParameter(1, id); try { return (ThemeSettings) query.getSingleResult(); } catch (NonUniqueResultException ne) { throw new SocialSiteException("ERROR: more than one destination with id: " + id, ne); } catch (NoResultException ex) { return null; } }
From source file:com.brienwheeler.svc.usergroups.impl.UserGroupMemberDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public UserGroupMember findForGroupAndUser(UserGroup userGroup, User user) { Query query = entityManager .createQuery("from UserGroupMember where userGroup = :userGroup and user = :user"); query.setParameter("userGroup", userGroup); query.setParameter("user", user); return getSingleResultOrNull(query); }
From source file:cz.muni.fi.pa165.airport.dao.dao.PlaneDAO.java
@Override public Plane find(Long id) { if (id == null) { throw new IllegalArgumentException("ID is null"); }//www .j a v a 2 s . c om Query query = em.createQuery("SELECT p FROM Plane p WHERE p.archived = :archived AND p.id = :id"); query.setParameter("archived", false); query.setParameter("id", id); List resultList = query.getResultList(); return resultList.isEmpty() ? null : (Plane) resultList.get(0); }
From source file:org.kuali.mobility.push.dao.PushMessageDaoImpl.java
@SuppressWarnings("unchecked") public List<PushMessage> findAllPushMessagesByLanguage(String language) { Query query = entityManager.createNamedQuery("PushMessage.findByLanguage"); query.setParameter("language", language); return query.getResultList(); }
From source file:org.kuali.mobility.push.dao.PushMessageDaoImpl.java
@Override public PushMessage findPushMessageById(Long id) { Query query = entityManager.createNamedQuery("PushMessage.findById"); query.setParameter("id", id); PushMessage result;//from w w w . j a va 2 s . c o m try { result = (PushMessage) query.getSingleResult(); } catch (Exception e) { result = null; } return result; }
From source file:org.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java
public Page<ServiceEntity> getServiceListByUser(String userName, Pagination pagination) { // Query//from ww w.j av a 2s. c o m String queryString = String.format(USERNAME_SERVICE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, ServiceEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<ServiceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_SERVICE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<ServiceEntity>(results, null, count); }
From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.SeatDaoImpl.java
@Override public List<Seat> getByPlane(Long plane) { try {// w w w.j av a2 s . c om Query q = em.createQuery("FROM Seat WHERE plane_id=:plane"); q.setParameter("plane", plane); List<Seat> planes = q.getResultList(); return Collections.unmodifiableList(planes); } catch (PersistenceException | IllegalArgumentException ex) { throw new DataAccessException(ex.getMessage(), ex) { }; } }
From source file:bc8.movies.dao.UserDaoImpl.java
public boolean checkUsername(User user) { Query query = em.createQuery("select user from User user where user.username = :username"); query.setParameter("username", user.getUsername()); if (query.getResultList().isEmpty()) { return false; } else {//from ww w . java 2 s . c o m return true; } }
From source file:hr.diskobolos.persistence.impl.ADaoPersistenceImpl.java
@Override public void delete(List<T> entities) { if (!entities.isEmpty()) { Query query = entityManager.createNamedQuery(getType().getSimpleName() + ".deleteItems"); query.setParameter("forDeletion", entities); query.executeUpdate();//ww w . j a v a2 s .co m } }
From source file:org.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java
public Page<ServiceEntity> getServiceListByKeyword(String keyword, Pagination pagination) { // Query// w w w. j a v a 2s . c o m String queryString = String.format(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, pagination.getSortBy()); query.setParameter(4, pagination.getPerPage()); query.setParameter(5, pagination.getPage() * pagination.getPerPage()); List<ServiceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(KEYWORD_SERVICE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<ServiceEntity>(results, null, count); }