Example usage for javax.persistence TypedQuery setFirstResult

List of usage examples for javax.persistence TypedQuery setFirstResult

Introduction

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

Prototype

TypedQuery<X> setFirstResult(int startPosition);

Source Link

Document

Set the position of the first result to retrieve.

Usage

From source file:ar.edu.unlp.sedici.sedici2003.model.JerarquiasTermino.java

public static List<JerarquiasTermino> findAll(String text, String[] parents, boolean includeChilds,
        boolean includeSelf, int start, int count) {

    if (text == null || text.length() == 0)
        throw new IllegalArgumentException("The text argument is required");
    if (parents == null || parents.length == 0)
        throw new IllegalArgumentException("The parents argument is required");

    if (start < 0)
        start = 0;//from  w w  w  .java2s  .  c o  m
    if (count <= 0)
        count = 10;

    // Armamos el filtro de descendencia
    String parentFilter = "(";
    if (includeChilds) {
        for (String parentID : parents) {
            if (!parentID.endsWith("."))
                parentID += ".";
            parentFilter += " terminos.id LIKE '" + parentID + "%' OR";
        }
    } else {
        for (String parentID : parents) {
            parentFilter += " relaciones.id.idTermino1 = '" + parentID + "' OR";
        }
    }

    if (includeSelf) {
        for (String parentID : parents) {
            if (parentID.endsWith("."))
                parentID = parentID.substring(0, parentID.length() - 1);

            parentFilter += " terminos.id LIKE '" + parentID + "' OR";
        }
    }

    //Sacamos el ultimo OR
    parentFilter = parentFilter.substring(0, parentFilter.length() - 2) + ")";

    String sql = "SELECT terminos " + "FROM JerarquiasTermino AS terminos, JerarquiasRelaciones AS relaciones "
            + "WHERE terminos.id = relaciones.id.idTermino2 AND relaciones.tipoRelacion = 1 "
            + "AND LOWER(terminos.nombreEs) LIKE LOWER(:filtro) AND " + parentFilter;

    //Agrego el orden
    sql = sql + " ORDER BY terminos.nombreEs ASC";

    //  System.out.println(sql);
    EntityManager em = JerarquiasTermino.entityManager();
    TypedQuery<JerarquiasTermino> q = em.createQuery(sql, JerarquiasTermino.class);
    q.setParameter("filtro", "%" + text + "%");
    q.setFirstResult(start);
    q.setMaxResults(count);

    return q.getResultList();
}

From source file:ar.edu.unlp.sedici.sedici2003.model.TesaurosTermino.java

public static List<TesaurosTermino> findAll(String text, String[] parents, boolean includeChilds, int start,
        int count) {

    //if (text == null || text.length() == 0) throw new IllegalArgumentException("The text argument is required");
    if (parents == null || parents.length == 0)
        throw new IllegalArgumentException("The parents argument is required");

    if (start < 0)
        start = 0;//from   ww w  . j a  v a2  s.  c om
    if (count <= 0)
        count = 60;

    // Armamos el filtro de descendencia
    String parentFilter = "(";
    if (includeChilds) {
        for (String parentID : parents) {
            if (!parentID.endsWith("."))
                parentID += ".";
            parentFilter += " terminos.id LIKE '" + parentID + "%' OR";
        }
    } else {
        for (String parentID : parents) {
            parentFilter += " relaciones.id.idTermino1 = '" + parentID + "' OR";
        }
    }

    //Sacamos el ultimo OR
    parentFilter = parentFilter.substring(0, parentFilter.length() - 2) + ")";

    String sql = "SELECT terminos " + "FROM TesaurosTermino AS terminos, TesaurosRelaciones AS relaciones "
            + "WHERE terminos.id = relaciones.id.idTermino2 AND relaciones.id.tipoRelacion = 1 "
            + "AND LOWER(terminos.nombreEs) LIKE LOWER(:filtro) AND " + parentFilter;

    //Agrego el orden
    sql = sql + " ORDER BY terminos.nombreEs ASC";

    EntityManager em = TesaurosTermino.entityManager();
    TypedQuery<TesaurosTermino> q = em.createQuery(sql, TesaurosTermino.class);
    if (text != null || text.length() != 0) {
        q.setParameter("filtro", "%" + text.trim() + "%");

    }
    q.setFirstResult(start);
    q.setMaxResults(count);

    return q.getResultList();
}

From source file:ar.edu.unlp.sedici.sedici2003.model.Personas.java

public static List<Personas> findPersonasesByApellidoYNombre(String apellido, String nombre, int start,
        int count) {
    if (apellido == null || apellido.length() == 0)
        apellido = "";
    if (nombre == null)
        nombre = "";
    if (start < 0)
        start = 0;//from   www  . j a  va2 s  . co m
    if (count <= 0)
        count = 20;

    apellido = Personas.convertirParaQuery(apellido);
    nombre = Personas.convertirParaQuery(nombre);

    String where = Personas.generateCondition(apellido, nombre);

    EntityManager em = Personas.entityManager();
    TypedQuery<Personas> q = em.createQuery(
            "SELECT o FROM Personas AS o " + where + " ORDER BY o.apellido, o.nombre ASC", Personas.class);
    if (apellido.length() != 0)
        q.setParameter("apellido", apellido);
    if (nombre.length() != 0)
        q.setParameter("nombre", nombre);
    q.setFirstResult(start);
    q.setMaxResults(count);
    return q.getResultList();

}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findDedupConfigEntries(int firstResult, int maxResults) {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findMatchConfigEntries(int firstResult, int maxResults) {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}

From source file:models.Service.java

public static Page<Service> queryServiceByPage(int page, int pageSize, User user) {
    if (user == null) {
        throw new IllegalArgumentException("user?");
    }//from w  w w . ja  v  a  2s  . c  o  m

    StringBuffer queryHql = new StringBuffer();
    StringBuffer countHql = new StringBuffer();
    Map<String, Object> paramMap = new HashMap<String, Object>();

    queryHql.append("from Service s where s.owner.id = :userId");
    countHql.append("select count(s.id) from Service s where s.owner.id = :userId");
    paramMap.put("userId", user.getId());

    queryHql.append(" order by s.createDate desc");

    TypedQuery<Service> listQuery = JPA.em().createQuery(queryHql.toString(), Service.class);
    TypedQuery<Long> countQuery = JPA.em().createQuery(countHql.toString(), Long.class);

    for (Entry<String, Object> e : paramMap.entrySet()) {
        listQuery.setParameter(e.getKey(), e.getValue());
        countQuery.setParameter(e.getKey(), e.getValue());
    }

    List<Service> data = listQuery.setFirstResult(page * pageSize).setMaxResults(pageSize).getResultList();
    Long count = countQuery.getSingleResult();

    return new Page<Service>(Constants.SUCESS, count, data);
}

From source file:ext.msg.model.Message.java

public static Page<Message> queryMessageByRead(int page, int pageSize, String consumeOnly,
        Collection<?> msgTypes, boolean unReadFirst) {
    String countQL = " select count(m) from Message m where m.consumeOnly = :consumeOnly ";
    String contentQL = " from Message m where m.consumeOnly = :consumeOnly ";

    if (CollectionUtils.isNotEmpty(msgTypes)) {
        countQL += "  and m.msgType in (:msgTypes) ";
        contentQL += "  and m.msgType in (:msgTypes)  ";
    }/*  w w  w. ja v a 2 s . com*/

    if (unReadFirst) {
        contentQL += " order by isRead asc, m.id desc ";
    } else {
        contentQL += " order by m.id desc ";
    }

    TypedQuery<Long> countQuery = JPA.em().createQuery(countQL, Long.class).setParameter("consumeOnly",
            consumeOnly);
    TypedQuery<Message> contentQuery = JPA.em().createQuery(contentQL, Message.class)
            .setParameter("consumeOnly", consumeOnly);

    if (CollectionUtils.isNotEmpty(msgTypes)) {
        countQuery.setParameter("msgTypes", msgTypes);
        contentQuery.setParameter("msgTypes", msgTypes);
    }

    contentQuery.setFirstResult(page * pageSize).setMaxResults(pageSize);

    Long total = countQuery.getSingleResult();
    List<Message> data = contentQuery.getResultList();
    Page<Message> pageMsg = new Page<Message>(Constants.SUCESS, total, data);
    return pageMsg;
}

From source file:models.Service.java

public static Page<Service> queryServiceByPage(int page, int pageSize, Long userId, String searchText,
        Long industryId, String skillTag, boolean isFetchUser, boolean isFetchUserExpert) {
    StringBuffer queryHql = new StringBuffer();
    StringBuffer countHql = new StringBuffer();
    Map<String, Object> paramMap = new HashMap<String, Object>();

    queryHql.append("from Service s ");
    countHql.append("select count(s.id) from Service s where 1=1 ");

    if (isFetchUser) {
        queryHql.append(" left join fetch s.owner o  ");
    }/*  w ww  .ja  va 2  s. c o m*/
    if (isFetchUser && isFetchUserExpert) {
        queryHql.append(" left join fetch o.experts ");
    }
    queryHql.append(" where 1=1 ");

    if (null != userId) {
        queryHql.append(" and s.owner.id = :userId ");
        countHql.append(" and s.owner.id = :userId ");
        paramMap.put("userId", userId);
    }
    if (StringUtils.isNotBlank(searchText)) {
        queryHql.append(
                " and (s.industry.tagName like :searchTextLike or s.title like :searchTextLike or s.price like :searchTextLike)");
        countHql.append(
                " and (s.industry.tagName like :searchTextLike or s.title like :searchTextLike or s.price like :searchTextLike)");
        paramMap.put("searchTextLike", "%" + searchText.trim() + "%");
    }
    if (null != industryId) {
        queryHql.append(" and s.industry.id = :industryId ");
        countHql.append(" and s.industry.id = :industryId ");
        paramMap.put("industryId", industryId);

    }
    if (StringUtils.isNotBlank(skillTag)) {
        queryHql.append(" and s.tags like :skillTag ");
        countHql.append(" and s.tags like :skillTag ");
        paramMap.put("skillTag", "%" + skillTag + "%");
    }
    queryHql.append(" order by s.createDate desc");

    TypedQuery<Service> listQuery = JPA.em().createQuery(queryHql.toString(), Service.class);
    TypedQuery<Long> countQuery = JPA.em().createQuery(countHql.toString(), Long.class);

    for (Entry<String, Object> e : paramMap.entrySet()) {
        listQuery.setParameter(e.getKey(), e.getValue());
        countQuery.setParameter(e.getKey(), e.getValue());
    }

    List<Service> data = listQuery.setFirstResult(page * pageSize).setMaxResults(pageSize).getResultList();
    Long count = countQuery.getSingleResult();

    return new Page<Service>(Constants.SUCESS, count, data);
}

From source file:com.costrategix.user.repository.JpaUserDao.java

public List<User> getAllList(int recordsPerPage, int pageNumber) {
    TypedQuery<User> query = em.createQuery("SELECT u FROM User u", User.class);
    query.setFirstResult(pageNumber * recordsPerPage);
    query.setMaxResults(recordsPerPage);
    return query.getResultList();
}

From source file:org.antbear.jee.wicket.persistence.PersonService.java

public Iterator<Person> iterator(int first, int count) {
    TypedQuery<Person> query = em.createNamedQuery("person.findall", Person.class);
    query.setFirstResult(first);
    query.setMaxResults(count);//from   w  w w.  ja  v  a 2s . c om
    return query.getResultList().iterator();
}