List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.appdynamicspilot.persistence.CartPersistence.java
/** * Get all the items from cart based on user * * @param userId//from ww w.j a v a 2 s .c o m * @return List of items */ public List<Item> getAllItemsByUser(Long userId) { Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.id = :userid"); q.setParameter("userid", userId); List<Cart> carts = q.getResultList(); if ((carts == null) || (carts.size() == 0)) { return Collections.EMPTY_LIST; } Cart cart = carts.get(0); return cart.getItems(); }
From source file:com.appdynamicspilot.persistence.CartPersistence.java
/** * Deletes Items from cart/*from w w w. java 2 s. c om*/ * * @param username * @param item id */ public void deleteItemInCart(String username, Long id) { Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.email = :userid"); q.setParameter("userid", username); Cart c = (Cart) q.getSingleResult(); Item i = getEntityManager().find(Item.class, id); c.removeItem(i); update(c); }
From source file:org.syncope.core.persistence.dao.impl.RoleDAOImpl.java
@Override public List<SyncopeRole> find(final String name) { Query query = entityManager.createQuery("SELECT e FROM SyncopeRole e WHERE e.name = :name"); query.setParameter("name", name); return query.getResultList(); }
From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java
@Override public <T extends Task> int count(final Class<T> reference) { Query countQuery = entityManager.createNativeQuery("SELECT COUNT(id) FROM Task WHERE DTYPE=?1"); countQuery.setParameter(1, reference.getSimpleName()); return ((Number) countQuery.getSingleResult()).intValue(); }
From source file:bc8.movies.dao.UserDaoImpl.java
public User getUser(User user) { Query query = em.createQuery( "select user from User user where user.username= :username and user.password=:password"); query.setParameter("username", user.getUsername()); query.setParameter("password", user.getPassword()); List<User> users = query.getResultList(); if (!users.isEmpty()) { return users.get(0); } else {//from w w w . java 2 s . co m return null; } }
From source file:es.ucm.fdi.dalgs.academicTerm.repository.AcademicTermRepository.java
public boolean modifyTerm(String term, String newTerm) { Query query = em.createQuery("UPDATE AcademicTerm SET term =?1 WHERE term=?2"); query.setParameter(1, newTerm); query.setParameter(2, term);/*from www .j a va 2 s . c om*/ query.executeUpdate(); if (query.executeUpdate() >= 0) return true; return false; }
From source file:org.lamop.riche.dao.DAOSourceImpl.java
@Transactional @Override//from w ww . ja v a 2 s . com public List<Source> getAllSourcesForAuthor(Person p) { org.hibernate.Query q = sessionFactory.getCurrentSession() .createQuery("SELECT DISTINCT s FROM Source s JOIN FETCH s.authors a WHERE a.id=:aid"); q.setParameter("aid", p.getId()); List result = q.list(); sessionFactory.getCurrentSession().clear(); return result; }
From source file:com.appdynamicspilot.persistence.CartPersistence.java
/** * Deletes Items from cart - v2//w w w.j ava 2 s. c o m * * @param username * @param item id */ public Integer deleteItemInCartV2(String username, Long id) { Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.email = :userid"); q.setParameter("userid", username); if (q.getResultList().size() > 0) { Cart c = (Cart) q.getSingleResult(); Item i = getEntityManager().find(Item.class, id); c.removeItem(i); update(c); return 0; } return 1; }
From source file:com.impetus.kwitter.service.TwitterService.java
@Override public List<Tweet> findTweetByBody(String tweetBody) { Query q = em.createQuery("select u.tweets.body from User u where u.tweets.body =:body"); q.setParameter("body", tweetBody); List<Tweet> tweets = q.getResultList(); return tweets; }
From source file:fi.vm.sade.organisaatio.dao.impl.YhteystietojenTyyppiDAOImpl.java
@Override public List<YhteystietojenTyyppi> findLisatietoMetadataForOrganisaatio(Collection<String> organisaatioTyyppis) { // TODO: vaihda kyttmn criteria apia JPA2 jlkeen Query query = getEntityManager().createQuery(QUERY1); // "SELECT ol FROM YhteystietojenTyyppi ol join fetch ol.sovellettavatOrganisaatios as so WHERE so in (:tyypit)"); query.setParameter("organisaatioTyyppis", organisaatioTyyppis); List<YhteystietojenTyyppi> matches = query.getResultList(); query = getEntityManager().createQuery(QUERY2); query.setParameter("organisaatioTyyppis", organisaatioTyyppis); matches.addAll(union(matches, query.getResultList())); return matches;//query.getResultList(); }