Example usage for org.hibernate Query setMaxResults

List of usage examples for org.hibernate Query setMaxResults

Introduction

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

Prototype

@Override
    Query<R> setMaxResults(int maxResult);

Source Link

Usage

From source file:com.ikon.dao.ProfileDAO.java

License:Open Source License

/**
 * Find by pk//from w  w  w  .  j  a v a 2s  .c  o m
 */
public static Profile findByPk(long upId) throws DatabaseException {
    log.debug("findByPk({})", upId);
    String qs = "from Profile prf where prf.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", upId);
        Profile ret = (Profile) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.ProfileDAO.java

License:Open Source License

/**
 * Find by user// ww w  .  ja va 2  s .  c om
 */
public static Profile findByUser(String user) throws DatabaseException {
    log.debug("findByUser({})", user);
    String qs = "select profile from UserConfig uc where uc.user=:user";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setString("user", user);
        Profile ret = (Profile) q.setMaxResults(1).uniqueResult();
        log.debug("findByUser: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.QueryParamsDAO.java

License:Open Source License

/**
 * Find by pk/*from   www .ja va2  s.  com*/
 */
public static QueryParams findByPk(long qpId) throws DatabaseException {
    log.debug("findByPk({})", qpId);
    String qs = "from QueryParams qp where qp.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", qpId);
        QueryParams ret = (QueryParams) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.ReportDAO.java

License:Open Source License

/**
 * Update//from www . ja va 2s.c  om
 */
public static void update(Report rp) throws DatabaseException {
    log.debug("update({})", rp);
    String qs = "select rp.fileContent, rp.fileName, rp.fileMime from Report rp where rp.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();

        if (rp.getFileContent() == null || rp.getFileContent().length() == 0) {
            Query q = session.createQuery(qs);
            q.setParameter("id", rp.getId());
            Object[] data = (Object[]) q.setMaxResults(1).uniqueResult();
            rp.setFileContent((String) data[0]);
            rp.setFileName((String) data[1]);
            rp.setFileMime((String) data[2]);
        }

        session.update(rp);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("update: void");
}

From source file:com.ikon.dao.ReportDAO.java

License:Open Source License

/**
 * Find by pk/*from   w  w  w  . j a va2  s.  c o m*/
 */
public static Report findByPk(long rpId) throws DatabaseException {
    log.debug("findByPk({})", rpId);
    String qs = "from Report rp where rp.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", rpId);
        Report ret = (Report) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.StapleGroupDAO.java

License:Open Source License

/**
 * Find by pk/*  w  w  w  .j av  a  2 s  .  c  o m*/
 */
public static StapleGroup findByPk(int sgId) throws DatabaseException {
    log.debug("findByPk({})", sgId);
    String qs = "from StapleGroup sg where sg.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setInteger("id", sgId);
        StapleGroup ret = (StapleGroup) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.StapleGroupDAO.java

License:Open Source License

/**
 * Update// w  w w  .  java 2  s.  co m
 */
public static void update(StapleGroup sg) throws DatabaseException {
    log.debug("update({})", sg);
    String qs = "select sg.user from StapleGroup sg where sg.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Query q = session.createQuery(qs);
        q.setParameter("id", sg.getId());
        String user = (String) q.setMaxResults(1).uniqueResult();
        sg.setUser(user);
        session.update(sg);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("update: void");
}

From source file:com.ikon.dao.TwitterAccountDAO.java

License:Open Source License

/**
 * Find by pk/*from   w ww . j  a  v  a 2 s .  c  o m*/
 */
public static TwitterAccount findByPk(long taId) throws DatabaseException {
    log.debug("findByPk({})", taId);
    String qs = "from TwitterAccount ta where ta.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", taId);
        TwitterAccount ret = (TwitterAccount) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.UserItemsDAO.java

License:Open Source License

/**
 * Find by user//from  www . j  ava 2s  . c om
 */
public static UserItems findByPk(String user) throws DatabaseException {
    log.debug("findByPk({})", user);
    String qs = "from UserItems ui where ui.user=:user";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setString("user", user);
        UserItems ui = (UserItems) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ui);
        return ui;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.module.db.DbDashboardModule.java

License:Open Source License

/**
 * Get documents from statement/* w w w. j a  v  a 2 s. com*/
 */
@SuppressWarnings("unchecked")
private ArrayList<DashboardDocumentResult> getUserDocuments(String user, String source, String qs)
        throws DatabaseException {
    log.debug("getUserDocuments({}, {}, {})", new Object[] { user, source, qs });
    ArrayList<DashboardDocumentResult> al = new ArrayList<DashboardDocumentResult>();
    org.hibernate.Session hSession = null;

    try {
        hSession = HibernateUtil.getSessionFactory().openSession();
        org.hibernate.Query q = hSession.createQuery(qs);
        q.setString("user", user);
        q.setMaxResults(MAX_RESULTS);

        for (Iterator<Object[]> it = q.list().iterator(); it.hasNext();) {
            Object[] actData = it.next();
            String actItem = (String) actData[0];
            Calendar actDate = (Calendar) actData[1];

            try {
                NodeDocument nDoc = NodeDocumentDAO.getInstance().findByPk(actItem);
                Document doc = BaseDocumentModule.getProperties(user, nDoc);
                DashboardDocumentResult vo = new DashboardDocumentResult();
                vo.setDocument(doc);
                vo.setDate(actDate);
                vo.setVisited(false);
                al.add(vo);
            } catch (PathNotFoundException e) {
                // Do nothing
            }
        }
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(hSession);
    }

    log.debug("getUserDocuments: {}", al);
    return al;
}