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.AuthDAO.java

License:Open Source License

/**
 * Find role by pk/*from  w ww.ja  v a2 s.com*/
 */
public static Role findRoleByPk(String rolId) throws DatabaseException {
    log.debug("findRoleByPk({})", rolId);
    String qs = "from Role r where r.id=:id";
    Session session = null;

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

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

License:Open Source License

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

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", arId);
        AutomationRule ret = (AutomationRule) q.setMaxResults(1).uniqueResult();
        initialize(ret);
        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.AutomationDAO.java

License:Open Source License

/**
 * Get metadata by pk// w w w . j  a  va  2s .c  o m
 */
public AutomationMetadata findMetadataByPk(long amId) throws DatabaseException {
    log.debug("findMetadataByPk({})", amId);
    String qs = "from AutomationMetadata am where am.id=:id";
    Session session = null;

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

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

License:Open Source License

/**
 * Get validation by pk/*from  www  . j a v  a2  s.com*/
 */
public AutomationValidation findValidationByPk(long avId) throws DatabaseException {
    log.debug("findValidationByPk({})", avId);
    String qs = "from AutomationValidation av where av.id=:id";
    Session session = null;

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

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

License:Open Source License

/**
 * Get action by pk//from  w w w .  j  ava2 s. c o m
 */
public AutomationAction findActionByPk(long aaId) throws DatabaseException {
    log.debug("findActionByPk({})", aaId);
    String qs = "from AutomationAction aa where aa.id=:id";
    Session session = null;

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

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

License:Open Source License

/**
 * Find by pk//from  w w w. j  a  v a2  s .c o  m
 */
public static Bookmark findByPk(long bmId) throws DatabaseException, RepositoryException {
    log.debug("findByPk({})", bmId);
    String qs = "from Bookmark bm where bm.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Query q = session.createQuery(qs);
        q.setLong("id", bmId);
        Bookmark ret = (Bookmark) q.setMaxResults(1).uniqueResult();

        if (ret != null) {
            // If user bookmark is missing, set a default
            NodeBase nBase = (NodeBase) session.get(NodeBase.class, ret.getNode());

            if (nBase == null) {
                String rootPath = "/" + Repository.ROOT;
                String rootUuid = NodeBaseDAO.getInstance().getUuidFromPath(session, rootPath);
                ret.setNode(rootUuid);
                ret.setType(Folder.TYPE);
                session.save(ret);
            }
        }

        HibernateUtil.commit(tx);
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw new RepositoryException(e.getMessage(), e);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Update//from   ww  w. j  a  v  a2s . c  om
 */
public static void update(CronTab ct) throws DatabaseException {
    log.debug("update({})", ct);
    String qs = "select ct.fileContent, ct.fileName, ct.fileMime, ct.lastBegin, ct.lastEnd from CronTab ct where ct.id=:id";
    Session session = null;
    Transaction tx = null;

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

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

        session.update(ct);
        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.CronTabDAO.java

License:Open Source License

/**
 * Find by pk/*w  ww  . j av a  2s.c  om*/
 */
public static CronTab findByPk(long ctId) throws DatabaseException {
    log.debug("findByPk({})", ctId);
    String qs = "from CronTab ct where ct.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", ctId);
        CronTab ret = (CronTab) 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.CronTabDAO.java

License:Open Source License

/**
 * Find by filename/*from   w  w w .ja  va2  s.c  om*/
 */
public static CronTab findByName(String name) throws DatabaseException {
    log.debug("findByName({})", name);
    String qs = "from CronTab ct where ct.name=:name";
    Session session = null;

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

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

License:Open Source License

/**
 * Find by content and name/*from www.j  a  v  a  2 s . c  o m*/
 */
public Css findByContextAndName(String context, String name) throws DatabaseException {
    log.debug("findByContextAndName({},{})", context, name);
    String qs = "from Css c where c.context=:context and c.name=:name and c.active=:active";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setString("context", context);
        q.setString("name", name);
        q.setBoolean("active", true);
        Css ret = (Css) q.setMaxResults(1).uniqueResult();
        log.debug("findByContextAndName: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}