List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.SecurityGroupDaoJpaImpl.java
public SecurityGroup updateSecurityGroupId(String idSecurityGroup, SecurityGroup securityGroup) throws InvalidEntityException { Query query = getEntityManager().createQuery("UPDATE SecurityGroup sg " + "SET sg.idSecurityGroup= :idSecurityGroup" + " where sg.name = :name"); query.setParameter("idSecurityGroup", idSecurityGroup); query.setParameter("name", securityGroup.getName()); SecurityGroup secGroup = null;/* w ww. j ava 2 s. co m*/ try { query.executeUpdate(); secGroup = load(securityGroup.getName()); } catch (NoResultException e) { throw new InvalidEntityException(securityGroup); } catch (EntityNotFoundException e) { throw new InvalidEntityException(securityGroup); } return secGroup; }
From source file:gov.nih.nci.integration.dao.DefaultIHubMessageDao.java
/** * getAllByReferenceMessageId/* w w w . j av a 2s .c om*/ * * @param refMsgId - messageId * @return List<IHubMessage> - list of IHubMessae entities */ @SuppressWarnings("unchecked") public List<IHubMessage> getAllByReferenceMessageId(Long refMsgId) { final Query msgsQuery = this.getEm().createQuery("from " + getDomainClass().getSimpleName() + " iHubMsg where iHubMsg.referenceMessageId = :referenceMessageId "); msgsQuery.setParameter("referenceMessageId", refMsgId); return msgsQuery.getResultList(); }
From source file:org.kuali.mobility.push.dao.PreferenceDaoImpl.java
public Preference findPreference(Long id) { Query query = entityManager.createQuery("select p from Preference p where p.id = :id"); query.setParameter("id", id); Preference result;/*from w w w . ja va2s .c o m*/ try { result = (Preference) query.getSingleResult(); } catch (Exception e) { LOG.info("Exception: " + e.getMessage()); result = null; } return result; }
From source file:org.syncope.core.persistence.dao.impl.RoleDAOImpl.java
@Override public List<SyncopeRole> findChildren(final Long roleId) { Query query = entityManager.createQuery("SELECT r FROM SyncopeRole r WHERE " + "r.parent.id=:roleId"); query.setParameter("roleId", roleId); return query.getResultList(); }
From source file:es.ucm.fdi.dalgs.academicTerm.repository.AcademicTermRepository.java
public boolean deleteAcademicTerm(Collection<AcademicTerm> academicList) { Query query = em.createQuery("UPDATE AcademicTerm a SET isDeleted = true WHERE a in ?1"); query.setParameter(1, academicList); int n = query.executeUpdate(); if (n > 0) return true; return false; }
From source file:com.mothsoft.alexis.dao.ModelDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s . c o m public DataRange<Model> listByOwner(Long userId, int first, int count) { final Query query = this.em .createQuery("SELECT m FROM Model m JOIN m.topic t WHERE t.userId = :userId ORDER BY m.name ASC"); query.setParameter("userId", userId); query.setFirstResult(first); query.setMaxResults(count); final Query query2 = this.em .createQuery("SELECT COUNT(m.id) FROM Model m JOIN m.topic t WHERE t.userId = :userId"); query2.setParameter("userId", userId); int total = ((Number) query2.getSingleResult()).intValue(); final List<Model> list = query.getResultList(); final DataRange<Model> range = new DataRange<Model>(list, first, total); return range; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAAuthor.java
@Override @Transactional//www . ja va 2 s . co m public List<MDOAuthor> getRandomAuthors(String username, int number) { Query query = entityManager .createQuery("from MDOAuthor as a where (1=1 AND a.owner.login= :userName) order by rand()"); query.setParameter("userName", username); query.setMaxResults(5); @SuppressWarnings("unchecked") List<MDOAuthor> results = query.getResultList(); return results; }
From source file:ea.ejb.PostFacade.java
public List<Post> findPostIdUsuarioOrder(BigDecimal id_usuario) { Query q; List<Post> listaPost;/*from ww w . j a va2s . com*/ q = em.createQuery("SELECT p FROM Post p WHERE p.idUsuario.idUsuario=:ID ORDER BY p.idPost DESC"); q.setParameter("ID", id_usuario); listaPost = q.getResultList(); return listaPost; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAAuthor.java
@Override @Transactional/*from ww w. j a va 2s .c o m*/ public List<MDOAuthor> getAll(String username) { Query query = entityManager .createQuery("from MDOAuthor as a where (a.owner.login = :userName) ORDER BY UPPER(a.name)"); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOAuthor> results = query.getResultList(); return results; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAGenre.java
@Override @Transactional/*from w w w . java2 s . c o m*/ public MDOGenre getGenre(String username, Long genreSid) { Query query = entityManager .createQuery("from MDOGenre as a where (a.owner.login = :userName) AND (a.sid= :genreSid)"); query.setParameter("genreSid", genreSid); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOGenre> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } else { return null; } }