List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:com.cimpoint.mes.server.repositories.StepRepository.java
public EStep findStepByName(String routingName, String stepName) { try {//from w w w. j a v a 2 s .c om Query qry = getEntityManager() .createQuery("select o from EStep o where o.routing.name = ?1 and o.name = ?2") .setParameter(1, routingName).setParameter(2, stepName).setMaxResults(1); EStep step = (EStep) qry.getSingleResult(); return step; } catch (NoResultException ex) { return null; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.apache.syncope.core.persistence.dao.impl.UserDAOImpl.java
@Override public final int count(final Set<Long> adminRoles) { StringBuilder queryString = getFindAllQuery(adminRoles); queryString.insert(0, "SELECT COUNT(id) FROM ("); queryString.append(") count_user_id"); Query countQuery = entityManager.createNativeQuery(queryString.toString()); return ((Number) countQuery.getSingleResult()).intValue(); }
From source file:org.venice.piazza.common.hibernate.dao.dataresource.DataResourceDaoImpl.java
public Page<DataResourceEntity> getDataResourceList(Pagination pagination) { // Query//from w w w.ja v a 2s. c o m String queryString = String.format(DATARESOURCE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, DataResourceEntity.class); query.setParameter(1, pagination.getSortBy()); query.setParameter(2, pagination.getPerPage()); query.setParameter(3, pagination.getPage() * pagination.getPerPage()); List<DataResourceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(DATARESOURCE_QUERY_COUNT); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<DataResourceEntity>(results, null, count); }
From source file:DAO.PersonnesDAOImpl.java
@Transactional(readOnly = true) @Override/*from www . j a v a 2 s .co m*/ public PersonnesEntity find(String login, String password) { Query q = em.createQuery( "SELECT p FROM PersonnesEntity p " + "WHERE p.login = :login AND p.password = :password"); q.setParameter("login", login); q.setParameter("password", password); PersonnesEntity p = null; if (q.getResultList().size() == 1) { p = (PersonnesEntity) q.getSingleResult(); } return p; }
From source file:org.jrecruiter.dao.jpa.UserDaoJpa.java
@Override public User getUserByUsernameOrEmail(final String usernameOrEmail) { User user;/*from w w w.j ava2 s .c om*/ final Query query = entityManager.createQuery("select user from User user " + "left join fetch user.userToRoles utr " + "left join fetch utr.role " + "where user.username = :usernameOrEmail or user.email = :usernameOrEmail "); query.setParameter("usernameOrEmail", usernameOrEmail); query.getResultList(); try { user = (User) query.getSingleResult(); } catch (NoResultException e) { user = null; } return user; }
From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImpl.java
private UserEntity findUserById(long id) { Query query = em.createQuery("from UserEntity a where a.id= :id"); query.setParameter("id", id); try {//from www . j ava 2 s . c om return (UserEntity) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java
@Override public <T extends IdentifiedObject> Long findIdByXPath(Long id1, Long id2, Class<T> clazz) { try {//from w w w . j av a2 s . c om String findIdByXPath = (String) clazz.getDeclaredField("QUERY_FIND_ID_BY_XPATH").get(String.class); Query query = em.createNamedQuery(findIdByXPath).setParameter("o1Id", id1).setParameter("o2Id", id2); return (Long) query.getSingleResult(); } catch (NoSuchFieldException | IllegalAccessException e) { System.out.printf("**** findIdByXPath(Long id1, Long id2) Exception: %s - %s\n", clazz.toString(), e.toString()); throw new RuntimeException(e); } }
From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImpl.java
private AuthorityEntity findAuthorityByName(String name) { Query query = em.createQuery("from AuthorityEntity a where a.name= :name"); query.setParameter("name", name); try {/*www . ja v a2 s . co m*/ return (AuthorityEntity) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.kuali.mobility.push.dao.DeviceDaoImpl.java
public Long countDevicesBefore(Timestamp ts) { Query query = this.getEntityManager().createNamedQuery("Device.countDevicesBefore"); query.setParameter("timeStamp", ts); return (Long) query.getSingleResult(); }
From source file:org.opencastproject.userdirectory.jpa.JpaUserAndRoleProvider.java
public User loadUser(String userName, String organizationId) { EntityManager em = null;// ww w . jav a 2 s.co m try { em = emf.createEntityManager(); Query q = em.createNamedQuery("user"); q.setParameter("u", userName); q.setParameter("o", organizationId); JpaUser user = null; try { user = (JpaUser) q.getSingleResult(); } catch (NoResultException e) { return null; } Set<String> roles = user.getRoles(); return new User(userName, user.getPassword(), user.getOrganization(), roles.toArray(new String[roles.size()])); } finally { if (em != null) em.close(); } }