List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:fr.univrouen.poste.provider.AuthenticationFailureListener.java
@Override @Transactional//from www. j a v a 2s.co m public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent ev) { try { String username = ev.getAuthentication().getName(); TypedQuery<User> query = User.findUsersByEmailAddress(username, null, null); User targetUser = (User) query.getSingleResult(); if (targetUser != null) { // only for existing users targetUser.reportLoginFailure(); targetUser.persist(); } } catch (Exception e) { } }
From source file:com.intera.roostrap.security.JpaUserDetailService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try {/* www . j a va 2s.c om*/ TypedQuery<User> userQuery = User.findUsersByEmailAddress(username); User targetUser = userQuery.getSingleResult(); List<GrantedAuthority> authorities = loadGrantedAuthorities(targetUser); return new org.springframework.security.core.userdetails.User(targetUser.getEmailAddress(), targetUser.getPassword(), targetUser.getEnabled(), true, true, !targetUser.getLocked(), authorities); } catch (EmptyResultDataAccessException e) { throw new UsernameNotFoundException("User " + username + " is not found"); } catch (NonUniqueResultException e) { throw new IllegalStateException("Non-unique user" + username + ", contact administrator"); } }
From source file:bq.jpa.demo.map.service.MapService.java
public Department findDepartment() { TypedQuery<Department> query = em.createQuery("from jpa_map_department", Department.class); return query.getSingleResult(); }
From source file:ispok.dao.TournamentHibernateJpaDao.java
@Override public Long getCount(Map<String, Object> filters) { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Tournament> t = cq.from(Tournament.class); cq.select(cb.count(t));/* www. j a v a 2 s . c o m*/ TypedQuery<Long> tq = em.createQuery(cq); return tq.getSingleResult(); }
From source file:com.sixsq.slipstream.persistence.Run.java
public static int viewListCount(User user, String moduleResourceUri, String cloudServiceName) throws ConfigurationException, ValidationException { int count = 0; EntityManager em = PersistenceUtil.createEntityManager(); try {//from w w w . ja va 2s.c o m CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Long> critQuery = builder.createQuery(Long.class); Root<Run> rootQuery = critQuery.from(Run.class); critQuery.select(builder.count(rootQuery)); Predicate where = viewListCommonQueryOptions(builder, rootQuery, user, moduleResourceUri, cloudServiceName); if (where != null) { critQuery.where(where); } TypedQuery<Long> query = em.createQuery(critQuery); count = (int) (long) query.getSingleResult(); } finally { em.close(); } return count; }
From source file:eu.domibus.common.dao.ConfigurationDAO.java
public Configuration read() { TypedQuery<Configuration> query = this.em.createNamedQuery("Configuration.getConfiguration", Configuration.class); return query.getSingleResult(); }
From source file:de.egore911.persistence.selector.AbstractSelector.java
public long count() { EntityManager em = EntityManagerUtil.getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = builder.createQuery(Long.class); Root<T> from = cq.from(getEntityClass()); List<Predicate> predicates = generatePredicateList(builder, from, cq); cq.where(predicates.toArray(new Predicate[predicates.size()])); cq.select(builder.count(from));//from w w w . jav a2 s. co m TypedQuery<Long> q = em.createQuery(cq); return q.getSingleResult(); }
From source file:com.beto.test.securityinterceptor.model.dao.impl.UserDaoImpl.java
@Override public SecUserDef getUser(String login) { logger.debug("getUser method called..." + login); SecUserDef user;/* w ww .ja va2s . co m*/ TypedQuery<SecUserDef> query = em.createNamedQuery("SecUserDef.findByUsername", SecUserDef.class); query.setParameter("username", login); user = query.getSingleResult(); logger.debug(user.toString()); return user; }
From source file:de.egore911.persistence.selector.AbstractSelector.java
@Nullable public T find() { TypedQuery<T> q = buildQuery(); try {/* ww w .j ava 2s . c o m*/ return q.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java
public T getsingleCriteria(CriteriaQuery<T> cq) { TypedQuery<T> query = em.createQuery(cq); return query.getSingleResult(); }