Example usage for javax.persistence TypedQuery getResultList

List of usage examples for javax.persistence TypedQuery getResultList

Introduction

In this page you can find the example usage for javax.persistence TypedQuery getResultList.

Prototype

List<X> getResultList();

Source Link

Document

Execute a SELECT query and return the query results as a typed List.

Usage

From source file:io.github.todolist.core.repository.impl.UserRepositoryImpl.java

/**
 * {@inheritDoc}//from  www .j a v  a 2s  . co  m
 */
public boolean login(final String email, final String password) {
    TypedQuery<User> query = entityManager.createNamedQuery("findUserByEmailAndPassword", User.class);
    query.setParameter("p_email", email);
    query.setParameter("p_password", password);
    List<User> users = query.getResultList();
    return (users != null && !users.isEmpty());
}

From source file:br.com.semanticwot.cd.daos.SwotApplicationDAO.java

@Override
public List<SwotApplication> findByUser(SystemUser systemUser) {
    TypedQuery<SwotApplication> query = entityManager
            .createQuery("select distinct(p) from SwotApplication p join fetch p.systemUser",
                    SwotApplication.class)
            .setParameter("login", systemUser);
    return query.getResultList();
}

From source file:eu.domibus.common.dao.ErrorLogDao.java

public List<ErrorLogEntry> findPaged(int from, int max, String column, boolean asc,
        HashMap<String, Object> filters) {
    CriteriaBuilder cb = this.em.getCriteriaBuilder();
    CriteriaQuery<ErrorLogEntry> cq = cb.createQuery(ErrorLogEntry.class);
    Root<ErrorLogEntry> ele = cq.from(ErrorLogEntry.class);
    cq.select(ele);//  w  ww  . ja va 2 s  . c  o m
    List<Predicate> predicates = new ArrayList<Predicate>();
    for (Map.Entry<String, Object> filter : filters.entrySet()) {
        if (filter.getValue() != null) {
            if (filter.getValue() instanceof String) {
                if (!filter.getValue().toString().isEmpty()) {
                    switch (filter.getKey().toString()) {
                    case "":
                        break;
                    case "timestampFrom":
                        predicates.add(cb.greaterThanOrEqualTo(ele.<Date>get("timestamp"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    case "timestampTo":
                        predicates.add(cb.lessThanOrEqualTo(ele.<Date>get("timestamp"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    case "notifiedFrom":
                        predicates.add(cb.greaterThanOrEqualTo(ele.<Date>get("notified"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    case "notifiedTo":
                        predicates.add(cb.lessThanOrEqualTo(ele.<Date>get("notified"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    default:
                        predicates.add(cb.like(ele.<String>get(filter.getKey()), (String) filter.getValue()));
                        break;
                    }
                }
            } else {
                predicates.add(cb.equal(ele.<String>get(filter.getKey()), filter.getValue()));
            }
        }
    }
    cq.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    if (column != null) {
        if (asc) {
            cq.orderBy(cb.asc(ele.get(column)));
        } else {
            cq.orderBy(cb.desc(ele.get(column)));
        }

    }
    final TypedQuery<ErrorLogEntry> query = this.em.createQuery(cq);
    query.setFirstResult(from);
    query.setMaxResults(max);
    return query.getResultList();
}

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

public List<ProjectArticle> findProjectChannellArticleLimit(Integer channelId, Integer number) {
    String hql = "From ProjectArticle As p where p.channelId=:channelId and p.release=true Order By p.published desc limit "
            + number;/*from  w w w  . j a  va 2s.co  m*/
    TypedQuery<ProjectArticle> query = this.getEntityManager().createQuery(hql, ProjectArticle.class);
    query.setParameter("channelId", channelId);
    return query.getResultList();
}

From source file:fr.univrouen.poste.web.SignUpController.java

private String activateUser(String activationKey, String emailAddress, Model model) {
    String textePremierePageAnonyme = AppliConfig.getCacheTextePremierePageAnonyme();
    model.addAttribute("textePremierePageAnonyme", textePremierePageAnonyme);
    TypedQuery<User> query = User.findUsersByActivationKeyAndEmailAddress(activationKey, emailAddress, null,
            null);//w  w w .j  a  v  a  2  s  .c  o  m
    if (!query.getResultList().isEmpty()) {
        User user = query.getSingleResult();
        if (user.getPassword() != null) {
            user.setActivationDate(new Date());
            user.setEnabled(true);
            user.merge();
            return "login";
        } else {
            UserRegistrationForm form = new UserRegistrationForm();
            form.setEmailAddress(emailAddress);
            form.setActivationKey(activationKey);
            model.addAttribute("User", form);
            return "signup/initpassword";
        }
    } else {
        return "signup/errorlink";
    }
}

From source file:org.mitre.openid.connect.repository.impl.JpaApprovedSiteRepository.java

@Override
@Transactional(value = "defaultTransactionManager")
public Collection<ApprovedSite> getByClientId(String clientId) {
    TypedQuery<ApprovedSite> query = manager.createNamedQuery(ApprovedSite.QUERY_BY_CLIENT_ID,
            ApprovedSite.class);
    query.setParameter(ApprovedSite.PARAM_CLIENT_ID, clientId);

    return query.getResultList();
}

From source file:com.beto.test.securityinterceptor.model.dao.impl.MenuServiceImpl.java

@Override
public List<SecPageDef> pageList() {
    LOGGER.debug("\n\n\nTEST OK\n\n\n");
    List<SecRoleDef> secRoleDefs = userDao.getUser(ProjectUtil.getUser().getUsername()).getSecRoleDefList();
    List<String> list = new ArrayList<>();
    for (SecRoleDef secRoleDef : secRoleDefs) {
        list.add(secRoleDef.getRole());/*from  w  w  w.java 2  s  .c  o  m*/
    }
    TypedQuery<SecPageDef> tq = em.createQuery(
            "SELECT DISTINCT(p) FROM SecPageRoleDef s,SecPageDef p WHERE s.role IN:inList AND s.viewId=p.viewId",
            SecPageDef.class);
    tq.setParameter("inList", list);
    return tq.getResultList();
}

From source file:io.hops.hopsworks.common.dao.user.security.audit.AccountAuditFacade.java

public List<AccountAudit> findByInitiator(Users user) {
    TypedQuery<AccountAudit> query = em.createNamedQuery("AccountAudit.findByInitiator", AccountAudit.class);
    query.setParameter("initiator", user);

    return query.getResultList();
}

From source file:com.sonoport.service.account.jpa.UserServiceImpl.java

@Override
public List<User> listAll() {
    TypedQuery<User> query = entityManager.createQuery("select u from User u", User.class);
    // Force hard refresh, useful if running parallel instances
    query.setHint("javax.persistence.cache.storeMode", "REFRESH");
    return query.getResultList();
}

From source file:com.jcertif.abj2014.intro.spring.data.before.SpeakerServiceImpl.java

@Override
public List<Speaker> findByLastname(String lastname, int page, int pageSize) {
    TypedQuery<Speaker> query = em.createQuery("select s from Speaker s where s.lastname = ?1", Speaker.class);

    query.setParameter(1, lastname);//from   w w w . j  a va 2s .  c  o  m
    query.setFirstResult(page * pageSize);
    query.setMaxResults(pageSize);

    return query.getResultList();
}