List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:net.chrissearle.flickrvote.dao.JpaPhotographyDao.java
/** * Method findByUsername finds the photographer with the given username. Null if none found. * * @param username of type String// ww w .j ava 2 s . c o m * @return Photographer */ public Photographer findByUsername(String username) { if (log.isLoggable(Level.FINE)) { log.fine("findByUsername : " + username); } Query query = entityManager.createQuery("select p from Photographer p where p.username = :username"); query.setParameter("username", username); try { return (Photographer) query.getSingleResult(); } catch (NoResultException e) { if (log.isLoggable(Level.FINE)) { log.fine("No matching user found"); } // Just means that there is no photographer yet present return null; } }
From source file:CiudadesApp.Modelo.Actions.Ciudad_Actions.java
public Ciudad getCiudad(Ciudad_Parameter ciudadParameter) { if (ciudadParameter.getIdCiudad() == 0) { int newIdCiudad = 0; Query q = em.createQuery("select max(c.idCiudad) from Ciudad c", Ciudad.class); newIdCiudad = (int) q.getSingleResult(); return ciudadFacade.find(newIdCiudad); } else {// w w w. j a v a2 s . c o m return ciudadFacade.find(ciudadParameter.getIdCiudad()); } }
From source file:com.appdynamicspilot.persistence.CartPersistence.java
/** * Deletes Items from cart/*w w w .j a v a 2s . c o m*/ * * @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.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 . com*/ try { result = (PushMessage) query.getSingleResult(); } catch (Exception e) { result = null; } return result; }
From source file:CiudadesApp.Modelo.Actions.Ciudad_Actions.java
public Ciudad getCiudad(int idCiudad) { if (idCiudad == 0) { int newIdCiudad = 0; Query q = em.createQuery("select max(c.idCiudad) from Ciudad c", Ciudad.class); newIdCiudad = (int) q.getSingleResult(); //System.out.println(newIdCiudad); return ciudadFacade.find(newIdCiudad); } else {//from w w w.ja v a2s . c o m return ciudadFacade.find(idCiudad); } }
From source file:es.ucm.fdi.dalgs.mailbox.respository.MailBoxRepository.java
public MessageBox getMessageBox(String code) { Query query = null; query = em.createQuery("select m FROM MessageBox m where m.code=?1"); query.setParameter(1, code);// w w w .j a va 2 s . com if (query.getResultList().isEmpty()) return null; else return (MessageBox) query.getSingleResult(); }
From source file:net.anthonychaves.bookmarks.service.UserService.java
public User findUser(String emailAddress) { EntityManager em = emf.createEntityManager(); User user = null;//from ww w.j a v a 2 s .c om try { Query query = em.createQuery("select u from User u where u.emailAddress = ?1").setParameter(1, emailAddress); em.getTransaction().begin(); user = (User) query.getSingleResult(); em.getTransaction().rollback(); } catch (NoResultException e) { user = null; } return user; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAUser.java
@Override @Transactional/*from ww w .j a v a 2s. c o m*/ public long countAllowedDLNAUsers() { Query query = entityManager.createQuery("SELECT COUNT(sid) FROM MDOUser as p where p.allowDLNA=true"); Long usersCount = (Long) query.getSingleResult(); if (usersCount != null) { return usersCount; } else { return 0; } }
From source file:org.verinice.persistence.VeriniceAccountDaoImpl.java
private int getScopeIdForLoginName(String loginName) { String fileName = SCOPEID_FOR_ACCOUNT_JPQL; String jpql = null;/* www .ja v a 2 s . c o m*/ try { jpql = Resources.toString(Resources.getResource(fileName), Charsets.UTF_8); } catch (IOException ex) { LOG.error("Error reading JPQL query from file: " + fileName, ex); } Query query = entityManager.createQuery(jpql).setParameter("loginName", loginName); int scopeId = -1; try { scopeId = (Integer) query.getSingleResult(); } catch (Exception ex) { LOG.error("Could not retrieve scope id for user: '" + loginName + "'", ex); } return scopeId; }
From source file:nc.noumea.mairie.appock.dao.impl.ArticleCatalogueDaoImpl.java
@Override public ArticleCatalogue findByReferenceAndCatalogue(String reference, Catalogue catalogue) { // @formatter:off String jpaQuery = " SELECT articleCatalogue FROM ArticleCatalogue articleCatalogue " + " left join articleCatalogue.sousFamille sousFamille " + " left join sousFamille.famille famille " + " left join famille.catalogue catalogue " + " WHERE articleCatalogue.reference = :reference " + " AND catalogue = :catalogue"; // @formatter:on Query query = persistentManager.getEntityManager().createQuery(jpaQuery); AppockUtil.setParameter(query, "reference", reference); AppockUtil.setParameter(query, "catalogue", catalogue); try {//from ww w .j a va 2 s . c om return (ArticleCatalogue) query.getSingleResult(); } catch (NoResultException e) { return null; } }