List of usage examples for javax.persistence EntityManager createNamedQuery
public Query createNamedQuery(String name);
Query
for executing a named query (in the Java Persistence query language or in native SQL). From source file:org.opencastproject.messages.MailService.java
public static Option<MessageTemplateDto> findMessageTemplate(Option<Long> id, String name, String orgId, EntityManager em) { Option<MessageTemplateDto> messageTemplateDto = Option.<MessageTemplateDto>none(); if (id.isSome()) messageTemplateDto = findMessageTemplateById(id.get(), orgId, em); if (messageTemplateDto.isSome()) return messageTemplateDto; Query q = em.createNamedQuery("MessageTemplate.findByName").setParameter("name", name).setParameter("org", orgId);/*from w ww. j ava2 s . com*/ try { return some((MessageTemplateDto) q.getSingleResult()); } catch (NoResultException e) { return none(); } }
From source file:dao.UsuarioDao.java
public List<Usuario> consultarTodosUsuarios() { EntityManagerFactory factory = Persistence.createEntityManagerFactory("LoginUsersPU"); EntityManager em = factory.createEntityManager(); em.getTransaction().begin();/*from www. j av a 2 s.c o m*/ Query q = em.createNamedQuery("Usuario.findAll"); List<Usuario> todosUsuarios = q.getResultList(); return todosUsuarios; }
From source file:com.sixsq.slipstream.persistence.Run.java
private static Query createNamedQuery(EntityManager em, String query) { Query q = em.createNamedQuery(query); q.setMaxResults(DEFAULT_LIMIT);// w w w . j a v a2 s.c o m return q; }
From source file:org.opencastproject.messages.MailService.java
public static Option<MessageSignatureDto> findMessageSignature(Option<Long> id, String name, String orgId, EntityManager em) { Option<MessageSignatureDto> messageSignatureDto = Option.<MessageSignatureDto>none(); if (id.isSome()) messageSignatureDto = findMessageSignatureById(id.get(), orgId, em); if (messageSignatureDto.isSome()) return messageSignatureDto; Query q = em.createNamedQuery("MessageSignature.findByName").setParameter("name", name).setParameter("org", orgId);// w w w . j av a2s . c o m try { return some((MessageSignatureDto) q.getSingleResult()); } catch (NoResultException e) { return none(); } }
From source file:de.berlios.jhelpdesk.dao.jpa.TicketEventDAOJpa.java
public List<TicketEvent> getLastEvents(final int howMuch) { return (List<TicketEvent>) this.jpaTemplate.execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = em.createNamedQuery("TicketEvent.getLastFewEventsOrderByEventDateDESC"); q.setMaxResults(howMuch);//from w w w.j a v a 2 s . com return q.getResultList(); } }); }
From source file:org.rhq.core.domain.server.PersistenceUtility.java
/** * Used to create queries to use with the {@link org.rhq.core.domain.util.PageControl} objects. The query will already have its sort column * and order appended as well as having its first result and max results set according to the page control data. * * @param entityManager your entity manager * @param queryName name of the query * @param pageControl the controls on the paging and sorting * * @return a preconfigured query for ordered pagination *///from www. j a v a 2 s .c o m public static Query createQueryWithOrderBy(EntityManager entityManager, String queryName, PageControl pageControl) { Query query; if (pageControl.getPrimarySortColumn() != null) { query = createQueryWithOrderBy(entityManager, queryName, pageControl.getOrderingFieldsAsArray()); } else { StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[1]; LOG.warn("Queries should really supply default sort columns. Caller did not: " + caller); // Use the standard named query if no sorting is specified query = entityManager.createNamedQuery(queryName); } setDataPage(query, pageControl); return query; }
From source file:sequrity.LoginService.java
public Korisnik loadUserByEmail(String email) throws Exception { Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); EntityManagerFactory emf = (EntityManagerFactory) envCtx.lookup("ime"); EntityManager em = emf.createEntityManager(); try {/*from w w w .j ava 2 s. c o m*/ return (Korisnik) em.createNamedQuery("Profesor.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException e) { try { return (Korisnik) em.createNamedQuery("Student.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException ex) { throw new Exception("Korisnik ne postoji u sistemu."); } } }
From source file:de.berlios.jhelpdesk.dao.jpa.AnnouncementDAOJpa.java
public List<Announcement> getLastAnnouncements(final int howMuch) { try {/*from w ww . ja va 2 s .c om*/ return (List<Announcement>) this.jpaTemplate.executeFind(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = em.createNamedQuery("Announcement.allOrderByCreateDateDesc"); q.setMaxResults(howMuch); return q.getResultList(); } }); } catch (Exception ex) { log.error("wystapil problem..", ex); } return Collections.<Announcement>emptyList(); }
From source file:de.berlios.jhelpdesk.dao.jpa.ArticleDAOJpa.java
public List<Article> getLastArticles(final int howMuch) { try {// ww w . j a va 2 s . com return (List<Article>) this.jpaTemplate.executeFind(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = em.createNamedQuery("Article.lastAdded"); q.setMaxResults(howMuch); return q.getResultList(); } }); } catch (Exception ex) { log.error("Nie mona pobra ostatnio dodanych artykuw.", ex); } return Collections.<Article>emptyList(); }
From source file:br.nom.abdon.gastoso.dal.FatosDao.java
@Override protected void prepararDelecao(EntityManager em, Fato fato) throws DalException { em.createNamedQuery("Lancamento.deletarPorFato").setParameter("fato", fato).executeUpdate(); }