List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:br.ufba.dcc.mestrado.computacao.repository.impl.OpenHubCrawlerLicenseRepositoryImpl.java
@Override public OpenHubCrawlerLicenseEntity findCrawlerConfig() { TypedQuery<OpenHubCrawlerLicenseEntity> crawlerConfig = super.createSelectAllQuery(); OpenHubCrawlerLicenseEntity result = null; try {/* w w w . j a v a 2s .c om*/ result = crawlerConfig.getSingleResult(); } catch (NoResultException ex) { } return result; }
From source file:org.jasig.portlet.attachment.dao.jpa.JpaAttachmentDao.java
private Attachment getResult(String select, Map<String, String> params) { try {/*from w ww . ja va 2 s. co m*/ final TypedQuery<Attachment> query = createQuery(select, params); Attachment attachment = query.getSingleResult(); return attachment; } catch (NoResultException noResultException) { return null; } }
From source file:br.eti.danielcamargo.backend.hsnpts.core.business.AlunoService.java
public Aluno getByUserId(Long userId) throws BusinessException { try {//from w w w . j ava 2 s.c o m StringBuilder hql = new StringBuilder(); hql.append("SELECT "); hql.append(" a "); hql.append("FROM "); hql.append(" Aluno a "); hql.append(" JOIN a.usuario u "); hql.append("WHERE "); hql.append(" u.id = :userId "); TypedQuery<Aluno> query = em.createQuery(hql.toString(), Aluno.class); query.setParameter("userId", userId); Aluno aluno = query.getSingleResult(); return aluno; } catch (NoResultException e) { throw new BusinessException("hsnpts", new ValidationOccurrence("hsnpts.aluno-nao-encontrado")); } }
From source file:br.com.semanticwot.cd.daos.RuleDAO.java
@Override public Role findByName(String name) { TypedQuery<Role> query = entityManager .createQuery("select distinct(p) from Role p where p.name=:name", Role.class) .setParameter("name", name); return query.getSingleResult(); }
From source file:eu.domibus.common.dao.ErrorLogDao.java
public long countEntries() { final TypedQuery<Long> query = this.em.createNamedQuery("ErrorLogEntry.countEntries", Long.class); return query.getSingleResult(); }
From source file:fr.univrouen.poste.provider.DatabaseUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { username = username.trim().toLowerCase(); TypedQuery<User> query = User.findUsersByEmailAddress(username, null, null); try {//from w w w. j ava 2 s . co m User targetUser = (User) query.getSingleResult(); return loadUserByUser(targetUser); } catch (EmptyResultDataAccessException e) { throw new RuntimeException(username + " not found in the Database.", e); } }
From source file:top.knos.user.UserRepositoryImpl.java
@Override public User findUserByNameQuery(String value) { TypedQuery<User> tq = em.createQuery("select u from User u where u.username = ?1", User.class); tq.setParameter(1, value);// ww w.j av a 2 s. co m return tq.getSingleResult(); }
From source file:com.samples.platform.core.SystemUserInitDao.java
/** * Get the {@link AuthenticationType}s out of the database. * * @param enabled//from w ww. jav a2s . com * if not <code>null</code> and <code>true</code> only the * enabled {@link AuthenticationType}s are replied. * @return the list of {@link AuthenticationType}s. */ @Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public void enterSystemUser(final String contextName, final String userName, final String password, final String... roleNames) { AuthenticationType ac = this.of.createAuthenticationType(); ac.setContext(contextName); ac.setEnabled(true); GrantedAuthorityType r; for (String roleName : roleNames) { r = this.of.createGrantedAuthorityType(); r.setRoleName(roleName); ac.getGrantedAuthority().add(r); } ac.setPassword(password); ac.setUserName(userName); CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<AuthenticationType> q = cb.createQuery(AuthenticationType.class); Root<AuthenticationType> c = q.from(AuthenticationType.class); Predicate ands = cb.conjunction(); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.context), contextName)); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.userName), userName)); q.where(ands); q.orderBy(cb.asc(c.<String>get(AuthenticationType_.userName))); TypedQuery<AuthenticationType> typedQuery = this.em.createQuery(q); try { AuthenticationType stored = typedQuery.getSingleResult(); if (stored != null) { this.em.persist(ac); } } catch (NoResultException e) { this.em.persist(ac); } }
From source file:com.web.mavenproject6.service.GuestServiceImp.java
@Override public Object findByAccessNumber(String accessNumber) { TypedQuery query = em.createQuery("select g from guest g where g.accessNumber = ?1", guest.class); query.setParameter(1, accessNumber); try {//from w ww .ja va2 s . c om return query.getSingleResult(); } catch (Exception ee) { return false; } }
From source file:br.ufba.dcc.mestrado.computacao.repository.impl.LicenseRepositoryImpl.java
@Override public OpenHubLicenseEntity findByName(String name) { CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<OpenHubLicenseEntity> criteriaQuery = criteriaBuilder.createQuery(getEntityClass()); Root<OpenHubLicenseEntity> root = criteriaQuery.from(getEntityClass()); CriteriaQuery<OpenHubLicenseEntity> select = criteriaQuery.select(root); Predicate namePredicate = criteriaBuilder.equal(root.get("name"), name); select.where(namePredicate);/*from w ww. j a va 2s . c om*/ TypedQuery<OpenHubLicenseEntity> query = getEntityManager().createQuery(criteriaQuery); OpenHubLicenseEntity result = null; try { result = query.getSingleResult(); } catch (NoResultException ex) { } catch (NonUniqueResultException ex) { } return result; }