Example usage for org.hibernate Query setFirstResult

List of usage examples for org.hibernate Query setFirstResult

Introduction

In this page you can find the example usage for org.hibernate Query setFirstResult.

Prototype

@Override
    Query<R> setFirstResult(int startPosition);

Source Link

Usage

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<License> findProdLicenses(Long prodId, Integer firstResult, Integer maxResults, String orderBy,
        String orderDir) {/*from  www . j  a  v a2  s .co m*/
    List<License> licenses = null;
    try {
        String qs = "from License as lic where lic.product.id= :prodId and lic.decom=false order by lic."
                + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("prodId", prodId);
        licenses = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return licenses;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<License> findInUseProdLicenses(Long prodId, Integer firstResult, Integer maxResults, String orderBy,
        String orderDir) {/*  w ww . jav  a  2  s . c o  m*/
    List<License> licenses = null;
    try {
        String qs = "from License as lic where lic.product.id= :prodId and inUse= :inUse and lic.decom= :decom order by lic."
                + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("prodId", prodId);
        query.setParameter("inUse", true);
        query.setParameter("decom", false);
        licenses = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return licenses;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<License> findIsvProdLicenses(Long isvId, Long prodId, Integer firstResult, Integer maxResults,
        String orderBy, String orderDir) {
    List<License> licenses = null;
    try {//w w w  . j  a va 2s  .  c  o m
        String qs = "from License as lic where lic.isv.id= :isvId and lic.product.id= :prodId and lic.decom= :decom order by lic."
                + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("isvId", isvId);
        query.setParameter("prodId", prodId);
        query.setParameter("decom", false);
        licenses = query.list();

    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return licenses;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<License> findInUseIsvProdLicenses(Long isvId, Long prodId, Long prodDefId, Long storeId,
        Long platformId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) {
    List<License> licenses = null;
    try {/*from   w  w  w . java 2  s .  co  m*/
        String qs = "from License as lic where lic.isv.id= :isvId and ";
        if (prodId != null)
            qs += "lic.product.id= :prodId and ";
        else if (prodDefId != null)
            qs += "lic.product.productDef.id= :prodDefId and ";

        if (storeId != null)
            qs += "lic.product.listingStore.id= :storeId and ";

        if (platformId != null)
            qs += "lic.product.platform.id= :platformId and ";

        qs += "inUse= :inUse and decom= :decom order by lic." + orderBy + " " + orderDir;

        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("isvId", isvId);

        if (prodId != null)
            query.setParameter("prodId", prodId);
        else if (prodDefId != null)
            query.setParameter("prodDefId", prodDefId);

        if (storeId != null)
            query.setParameter("storeId", storeId);

        if (platformId != null)
            query.setParameter("platformId", platformId);

        query.setParameter("inUse", true);
        query.setParameter("decom", false);
        licenses = query.list();

    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return licenses;
}

From source file:com.lm.lic.manager.hibernate.ProductDAO.java

@SuppressWarnings("unchecked")
public List<Product> findIsvProducts(Long isvId, Integer firstResult, Integer maxResults, String orderBy,
        String orderDir) {//ww w  .j  a  v  a2  s  .com
    List<Product> products = null;
    try {
        String qs = "from Product as prod where prod.isv.id= :isvId order by prod." + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("isvId", isvId);
        products = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return products;
}

From source file:com.lm.lic.manager.hibernate.ProductDAO.java

@SuppressWarnings("unchecked")
public List<QuickyProduct> findAllIsvQuickyProducts(Long isvId, Integer firstResult, Integer maxResults,
        String orderBy, String orderDir) {
    List<QuickyProduct> products = null;
    try {//from   ww w.j  ava2  s .  co m
        String qs = "from QuickyProduct as qp where qp.isv.id= :isvId and deleted = false order by qp."
                + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("isvId", isvId);
        products = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return products;
}

From source file:com.lm.lic.manager.hibernate.RequestForLicenseDAO.java

@SuppressWarnings("unchecked")
public List<RequestForLicense> findProdRequests(Long prodId, Integer firstResult, Integer maxResults,
        String orderBy, String orderDir) {
    List<RequestForLicense> rfls = null;
    try {/* w  w w.java 2s .  c om*/
        String qs = "from RequestForLicense as rfl where rfl.product.id= :prodId order by rfl." + orderBy + " "
                + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("prodId", prodId);
        rfls = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return rfls;
}

From source file:com.lm.lic.manager.hibernate.RequestForLicenseDAO.java

@SuppressWarnings("unchecked")
public List<RequestForLicense> findProdGoodSales(Long prodId, String store, Integer firstResult,
        Integer maxResults, String orderBy, String orderDir) {
    List<RequestForLicense> rfls = null;
    try {/* w  w w . j a  v  a 2  s  .com*/
        String qs = "from RequestForLicense as rfl where rfl.product.id= :prodId and rfl.requestor= :requestor order by rfl."
                + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("prodId", prodId);
        query.setParameter("requestor", store);
        rfls = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return rfls;
}

From source file:com.lm.lic.manager.hibernate.RequestForLicenseDAO.java

@SuppressWarnings("unchecked")
public List<RequestForLicense> findProdBadSales(Long prodId, String store, List<QuickyProduct> products,
        Integer firstResult, Integer maxResults, String orderBy, String orderDir) {
    List<RequestForLicense> rfls = null;
    try {//from  w w  w  .  jav  a  2  s  .  c o  m
        String qs = "from RequestForLicense as rfl where rfl.product.id= :prodId and rfl.requestor= :requestor "
                + "and rfl.response= :response order by rfl." + orderBy + " " + orderDir;
        Query query = getSession().createQuery(qs);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        query.setParameter("prodId", prodId);
        query.setParameter("requestor", store);
        query.setParameter("response", "InProgress");
        rfls = query.list();
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return rfls;
}

From source file:com.lp.server.anfrage.fastlanereader.AnfrageartHandler.java

License:Open Source License

/**
 * gets the page of data for the specified row using the current
 * queryParameters.//from ww  w  . j  a v a2 s  .c  o m
 * 
 * @param rowIndex
 *            diese Zeile soll selektiert sein
 * @return QueryResult das Ergebnis der Abfrage
 * @throws EJBExceptionLP
 *             Ausnahme
 * @see UseCaseHandler#getPageAt(java.lang.Integer)
 */
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = AnfrageartHandler.PAGE_SIZE;
        int startIndex = Math.max(rowIndex.intValue() - (pageSize / 2), 0);
        int endIndex = startIndex + pageSize - 1;

        session = factory.openSession();
        String queryString = this.getFromClause() + this.buildWhereClause() + this.buildOrderByClause();

        Query query = session.createQuery(queryString);
        session = setFilter(session);

        query.setFirstResult(startIndex);
        query.setMaxResults(pageSize);
        List<?> resultList = query.list();
        Iterator<?> resultListIterator = resultList.iterator();

        Object[][] rows = new Object[resultList.size()][colCount];
        int row = 0;
        int col = 0;

        String sLocUI = Helper.locale2String(theClientDto.getLocUi());

        while (resultListIterator.hasNext()) {
            Object o[] = (Object[]) resultListIterator.next();
            FLRAnfrageart anfrageart = (FLRAnfrageart) o[0];

            Iterator<?> sprsetIterator = anfrageart.getAnfrageart_anfrageart_set().iterator();

            rows[row][col++] = anfrageart.getC_nr();
            rows[row][col++] = anfrageart.getC_nr();
            rows[row][col++] = anfrageart.getI_sort();
            rows[row][col++] = findSpr(sLocUI, sprsetIterator);

            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (Exception e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he);
        }
    }
    return result;
}