Example usage for org.hibernate Criteria setFirstResult

List of usage examples for org.hibernate Criteria setFirstResult

Introduction

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

Prototype

public Criteria setFirstResult(int firstResult);

Source Link

Document

Set the first result to be retrieved.

Usage

From source file:com.dell.asm.asmcore.asmmanager.db.DeviceDiscoverDAO.java

License:Open Source License

/**
 * //from ww  w .jav  a  2  s.co m
 * @param sortInfos
 * @param filterInfos
 * @param paginationInfo
 * @return
 */
public List<DeviceDiscoverEntity> getAllDeviceDiscoverEntities(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) {
    Session session = null;
    Transaction tx = null;
    List<DeviceDiscoverEntity> entityList = new ArrayList<DeviceDiscoverEntity>();

    try {
        int offset = paginationInfo.getOffset();
        int limit = paginationInfo.getLimit();
        int pageSize = limit;

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(DeviceDiscoverEntity.class);
        BaseDAO.addSortCriteria(criteria, sortInfos);

        BaseDAO.addFilterCriteria(criteria, filterInfos, DeviceDiscoverEntity.class);

        criteria.setFirstResult(offset);
        criteria.setMaxResults(pageSize);

        entityList = criteria.list();
        tx.commit();

    } catch (Exception e) {
        logger.warn("Caught exception during get all DeviceDiscoverEntities: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get all DeviceDiscoverEntities: " + ex);
        }
        throw new AsmManagerInternalErrorException("Error Getting DeviceDiscoverEntities", "DeviceDiscoverDAO",
                e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get all DeviceDiscoverEntities: " + ex);
        }
    }

    return entityList;
}

From source file:com.dell.asm.asmcore.asmmanager.db.DeviceGroupDAO.java

License:Open Source License

/**
 * Retrieve all Device Groups// ww  w .j a  v a 2s  .c  o  m
 * 
 * @param sortInfos - column name(s) on which the sorting is done
 * @param filterInfos - column name(s) on which the filtering is done
 * @param paginationInfo - pagination information (offset and limit)
 * 
 * @return all the device groups (paginated list)
 * 
 * @throws AsmManagerCheckedException
 */
@SuppressWarnings("unchecked")
public List<DeviceGroupEntity> getAllDeviceGroup(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, PaginationParamParser.PaginationInfo paginationInfo)
        throws AsmManagerCheckedException {

    Session session = null;
    Transaction tx = null;
    List<DeviceGroupEntity> result = null;

    try {
        session = _dao._database.getNewSession();
        tx = session.beginTransaction();
        Criteria criteria = session.createCriteria(DeviceGroupEntity.class);

        if (paginationInfo != null) {
            int offset = paginationInfo.getOffset();
            int pageSize = paginationInfo.getLimit();
            criteria.setFirstResult(offset);
            criteria.setMaxResults(pageSize);
        }

        if (sortInfos != null) {
            addSortCriteria(criteria, sortInfos);
        }

        if (filterInfos != null) {
            addFilterCriteria(criteria, filterInfos, DeviceGroupEntity.class);
        }

        result = (List<DeviceGroupEntity>) criteria.list();
        tx.commit();

    } catch (Exception e) {
        logger.warn("Caught exception during getAllDeviceGroup: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during getAllDeviceGroup: " + ex);
        }
        throw new AsmManagerInternalErrorException("fetch Device Group", "DeviceGroupDAO", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during getAllDeviceGroup: " + ex);
        }
    }

    //if (result == null || result.size() == 0) {
    //    throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.RECORD_NOT_FOUND,
    //            AsmManagerMessages.deviceGroupsDataNotFound(""));
    //}

    return result;
}

From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java

License:Open Source License

/**
 * Retrieve all from Device Inventory.//from   w  ww  . j  av  a 2s.com
 *
 * @return list of entities
 */
@SuppressWarnings("unchecked")
public List<DeviceInventoryEntity> getAllDeviceInventory(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo)
        throws AsmManagerDAOException {

    Session session = null;
    Transaction tx = null;
    List<DeviceInventoryEntity> entityList = new ArrayList<DeviceInventoryEntity>();

    try {
        // NOTE[fcarta] need to at this here so we dont nest the session / transaction
        List<String> refIdsServices = ListUtils.EMPTY_LIST;
        List<String> refIdsGroups = ListUtils.EMPTY_LIST;
        List<String> refIdsAllGroups = ListUtils.EMPTY_LIST;

        boolean spFilterSet = false;
        boolean spGlobalFilterSet = false;
        if (CollectionUtils.isNotEmpty(filterInfos)) {
            for (FilterParamParser.FilterInfo filterInfo : filterInfos) {
                // if there is a service filter then grab the ref id for the device
                if (StringUtils.equals(SERVICE_FILTER_PARAM, filterInfo.getColumnName())) {
                    refIdsServices = getRefIdsOfDevicesByDeploymentIds(filterInfo.getColumnValue());
                } else if (StringUtils.equals(SERVERPOOL_FILTER_PARAM, filterInfo.getColumnName())) {
                    if (filterInfo.getColumnValue()
                            .contains(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_POOL_GLOBAL_ID)) {
                        refIdsAllGroups = getRefIdsOfDevicesByGroupIds(filterInfo.getColumnValue());
                        spGlobalFilterSet = true;
                    } else {
                        refIdsGroups = getRefIdsOfDevicesByGroupIds(filterInfo.getColumnValue());
                        spFilterSet = true;
                    }
                }
            }
        }

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(DeviceInventoryEntity.class);
        if (sortInfos != null) {
            BaseDAO.addSortCriteria(criteria, sortInfos);
        }

        if (filterInfos != null) {
            final List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos,
                    DeviceInventoryEntity.class);
            if (CollectionUtils.isNotEmpty(notFound)) {

                for (FilterParamParser.FilterInfo filterInfo : notFound) {
                    // if this is a filter by service then we need to get the subset of ref ids for devices
                    // only in the deployment id subset passed
                    if (StringUtils.equals(SERVICE_FILTER_PARAM, filterInfo.getColumnName())) {
                        if (CollectionUtils.isNotEmpty(refIdsServices)) {
                            criteria.add(Restrictions.in("refId", refIdsServices));
                        }
                    } else if (StringUtils.equals(SERVERPOOL_FILTER_PARAM, filterInfo.getColumnName())) {
                        if (spGlobalFilterSet) {
                            if (refIdsAllGroups.isEmpty()) {
                                // this means there are no servers in any server pool - all are in Global
                                criteria.add(Restrictions.sqlRestriction("(1=1)"));
                            } else {
                                criteria.add(Restrictions.not(Restrictions.in("refId", refIdsAllGroups)));
                            }
                        } else if (spFilterSet) {
                            if (refIdsGroups.isEmpty()) {
                                criteria.add(Restrictions.sqlRestriction("(1=0)"));
                            } else {
                                criteria.add(Restrictions.in("refId", refIdsGroups));
                            }
                        }
                    } else {
                        criteria.createAlias("deviceInventoryEntity", "deviceInventoryEntityAlias");
                        criteria.add(Restrictions.eq("deviceInventoryEntityAlias.deviceKey",
                                filterInfo.getColumnName()));
                        if (filterInfo.getColumnValue().size() == 1) {
                            criteria.add(Restrictions.eq("deviceInventoryEntityAlias.deviceValue",
                                    filterInfo.getColumnValue().get(0)));
                        } else if (filterInfo.getColumnValue().size() > 1) {
                            criteria.add(Restrictions.in("deviceInventoryEntityAlias.deviceValue",
                                    filterInfo.getColumnValue()));
                        }
                    }
                }
            }
        }

        if (paginationInfo != null) {
            int offset = paginationInfo.getOffset();
            int limit = paginationInfo.getLimit();
            int pageSize = limit;
            criteria.setFirstResult(offset);
            criteria.setMaxResults(pageSize);
        }

        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        entityList = criteria.list();
        this.setFirmwareBasedOnDeployment(entityList);
        tx.commit();
    } catch (Exception e) {
        logger.warn("Caught exception during get all devices in inventory: " + e, e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get all devices: " + ex);
        }
        throw new AsmManagerDAOException("Caught exception during get all devices in inventory: ", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get all devices: " + ex);
        }
    }

    return entityList;
}

From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java

License:Open Source License

/**
 * Retrieve DiscoveryResult based on parent job id.
 * @return the list of discovery results for given parent job id.
 *///from w  ww  . j av  a  2 s  .c om
@SuppressWarnings("unchecked")
public List<DiscoveryResultEntity> getDiscoveryResult(String parentJobId,
        List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos,
        PaginationInfo paginationInfo) throws AsmManagerDAOException {

    Session session = null;
    Transaction tx = null;
    List<DiscoveryResultEntity> entityList = new ArrayList<DiscoveryResultEntity>();

    logger.debug("getDiscoveryResult for job: " + parentJobId);

    try {

        int offset = paginationInfo.getOffset();
        int limit = paginationInfo.getLimit();
        int pageSize = limit;

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(DiscoveryResultEntity.class);
        BaseDAO.addSortCriteria(criteria, sortInfos);
        criteria.add(Restrictions.ne("serverType", Server.ServerType.BLADE.value())); // never return blades
        criteria.add(Restrictions.ne("serverType", Server.ServerType.COMPELLENT.value())); // never return compellents which now show up as iDrac7
        List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos,
                DiscoveryResultEntity.class);

        if (notFound != null && notFound.size() > 0) {
            criteria.createAlias("discoveryResultEntity", "discoveryResultEntityAlias");
            for (FilterParamParser.FilterInfo filterInfo : notFound) {
                criteria.add(
                        Restrictions.eq("discoveryResultEntityAlias.deviceKey", filterInfo.getColumnName()));
                if (filterInfo.getColumnValue().size() == 1) {
                    criteria.add(Restrictions.eq("discoveryResultEntityAlias.deviceValue",
                            filterInfo.getColumnValue().get(0)));
                } else if (filterInfo.getColumnValue().size() > 1) {
                    criteria.add(Restrictions.in("discoveryResultEntityAlias.deviceValue",
                            filterInfo.getColumnValue()));
                }
            }
        }

        //criteria.setFirstResult((pageNumber - 1) * pageSize);
        criteria.setFirstResult(offset);
        criteria.setMaxResults(pageSize);

        entityList = criteria.list();

        // Commit transaction.
        tx.commit();
        logger.debug("getDiscoveryResult for job: " + entityList.size());
    } catch (Exception e) {
        logger.warn("Caught exception during get discovery result for job: " + parentJobId + ", " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get device: " + ex);
        }
        //throw new AsmManagerDAOException("Caught exception during get discovery result for jobId: "    + parentJobId + ", "  + e, e);
        throw new AsmManagerInternalErrorException("Error Getting Discovery result", "DiscoveryResultDAO", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get device: " + ex);
        }
    }

    return entityList;
}

From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java

License:Open Source License

/**
 * Retrieve all from DiscoveryResultEntity.
 * @return list of entities//from   w w w  . java2  s  .c om
 */
@SuppressWarnings("unchecked")
public List<DiscoveryResultEntity> getAllDiscoveryResult(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo)
        throws AsmManagerDAOException {

    Session session = null;
    Transaction tx = null;
    List<DiscoveryResultEntity> entityList = new ArrayList<DiscoveryResultEntity>();

    try {

        int offset = paginationInfo.getOffset();
        int limit = paginationInfo.getLimit();
        int pageSize = limit;

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(DiscoveryResultEntity.class);
        BaseDAO.addSortCriteria(criteria, sortInfos);

        List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos,
                DiscoveryResultEntity.class);

        if (notFound != null && notFound.size() > 0) {
            criteria.createAlias("discoveryResultEntity", "discoveryResultEntityAlias");
            for (FilterParamParser.FilterInfo filterInfo : notFound) {
                criteria.add(Restrictions.eq("discoveryResultEntity.deviceKey", filterInfo.getColumnName()));
                if (filterInfo.getColumnValue().size() == 1) {
                    criteria.add(Restrictions.eq("discoveryResultEntityAlias.deviceValue",
                            filterInfo.getColumnValue().get(0)));
                } else if (filterInfo.getColumnValue().size() > 1) {
                    criteria.add(Restrictions.in("discoveryResultEntityAlias.deviceValue",
                            filterInfo.getColumnValue()));
                }
            }
        }

        //criteria.setFirstResult((pageNumber - 1) * pageSize);
        criteria.setFirstResult(offset);
        criteria.setMaxResults(pageSize);

        entityList = criteria.list();
        tx.commit();
    } catch (Exception e) {
        logger.warn("Caught exception during get all discovery entities: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get all discovery entities: " + ex);
        }
        throw new AsmManagerDAOException("Caught exception during get all discover entities: ", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get all discover entities: " + ex);
        }
    }

    return entityList;
}

From source file:com.dell.asm.asmcore.asmmanager.db.ServiceTemplateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ServiceTemplateEntity> getAllTemplates(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, int offset, int pageSize) {

    Session session = null;/*w  ww .jav  a2 s.  co m*/
    Transaction tx = null;
    List<ServiceTemplateEntity> entityList = new ArrayList<>();

    try {

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(ServiceTemplateEntity.class);
        BaseDAO.addSortCriteria(criteria, sortInfos);
        List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos,
                ServiceTemplateEntity.class);

        //criteria.setFirstResult((pageNumber - 1) * pageSize);
        if (offset >= 0)
            criteria.setFirstResult(offset);

        if (pageSize >= 0)
            criteria.setMaxResults(pageSize);

        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        entityList = criteria.list();

        // Commit transaction.
        tx.commit();
    } catch (Exception e) {
        logger.warn("Caught exception during get all templates: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get all templates: " + ex);
        }
        throw new AsmManagerInternalErrorException("Get All templates", "TemplateDAO", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get all devices: " + ex);
        }
    }

    logger.warn("Template DAO get all templates size: " + entityList.size());
    return entityList;
}

From source file:com.dell.asm.asmcore.asmmanager.db.TemplateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<TemplateEntity> getAllTemplates(List<SortParamParser.SortInfo> sortInfos,
        List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) {

    Session session = null;//from   w w w  .  jav a  2 s  . co m
    Transaction tx = null;
    List<TemplateEntity> entityList = new ArrayList<>();

    try {
        int offset = paginationInfo.getOffset();
        int pageSize = paginationInfo.getLimit();

        session = _dao._database.getNewSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(TemplateEntity.class);
        BaseDAO.addSortCriteria(criteria, sortInfos);
        List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos,
                TemplateEntity.class);

        if (notFound != null && notFound.size() > 0) {
            criteria.createAlias("templateEntity", "templateEntityAlias");
            for (FilterParamParser.FilterInfo filterInfo : notFound) {
                criteria.add(Restrictions.eq("templateEntityAlias.deviceKey", filterInfo.getColumnName()));
                if (filterInfo.getColumnValue().size() == 1) {
                    criteria.add(Restrictions.eq("templateEntityAlias.deviceValue",
                            filterInfo.getColumnValue().get(0)));
                } else if (filterInfo.getColumnValue().size() > 1) {
                    criteria.add(
                            Restrictions.in("templateEntityAlias.deviceValue", filterInfo.getColumnValue()));
                }
            }
        }

        //criteria.setFirstResult((pageNumber - 1) * pageSize);
        criteria.setFirstResult(offset);
        criteria.setMaxResults(pageSize);
        criteria.setFetchMode("policyRefEntities", FetchMode.SELECT);

        entityList = criteria.list();

        //            Collection<PolicyRefEntity> dummy;
        //            for (TemplateEntity parm : entityList) {
        //              dummy = parm.getPolicyRefEntities();
        //              dummy.isEmpty();
        //            }

        // workaround for dupliacate templates
        //entityList.addAll(buildUniqueList(criteria.list()));

        // Commit transaction.
        tx.commit();
    } catch (Exception e) {
        logger.warn("Caught exception during get all templates: " + e);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
            logger.warn("Unable to rollback transaction during get all templates: " + ex);
        }
        throw new AsmManagerInternalErrorException("Get All templates", "TemplateDAO", e);
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            logger.warn("Unable to close session during get all devices: " + ex);
        }
    }

    logger.warn("Template DAO get all templates size: " + entityList.size());
    return entityList;
}

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java

License:Mozilla Public License

private Criteria performLookupSetup(VulnerabilitySearchParameters parameters) {
    assert parameters != null;

    Criteria criteria = VulnerabilitySearchCriteriaConstructor
            .getCriteriaWithRestrictions(sessionFactory.getCurrentSession(), parameters);

    if (parameters.getNumberVulnerabilities() != null) {
        criteria.setMaxResults(parameters.getNumberVulnerabilities());
        if (parameters.getPage() != null)
            criteria.setFirstResult(parameters.getNumberVulnerabilities() * (parameters.getPage() - 1));
    }//from   www .ja va 2 s  .  com

    return criteria;
}

From source file:com.duroty.application.admin.manager.AdminManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from w  ww.  j  av a  2 s  .c om*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param token DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
public SearchUsersObj allUsers(Session hsession, int page, int byPage) throws Exception {
    SearchUsersObj searchUsersObj = new SearchUsersObj();
    Vector users = new Vector();

    try {
        Criteria crit = hsession.createCriteria(Users.class);
        searchUsersObj.setHits(crit.list().size());

        crit = hsession.createCriteria(Users.class);
        crit.setFirstResult(page * byPage);
        crit.setMaxResults(byPage);
        crit.addOrder(Order.asc("useName"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Users user = (Users) scroll.get(0);

            UserObj obj = new UserObj();

            obj.setActive(user.isUseActive());
            obj.setEmail(user.getUseEmail());

            Iterator it = user.getMailPreferenceses().iterator();
            MailPreferences mailPreferences = (MailPreferences) it.next();

            obj.setHtmlMessages(mailPreferences.isMaprHtmlMessage());
            obj.setIdint(user.getUseIdint());
            obj.setLanguage(user.getUseLanguage());
            obj.setMessagesByPage(mailPreferences.getMaprMessagesByPage());
            obj.setName(user.getUseName());
            obj.setPassword(user.getUsePassword());
            obj.setQuotaSize(mailPreferences.getMaprQuotaSize());
            obj.setRegisterDate(user.getUseRegisterDate());

            Integer[] roles = new Integer[user.getUserRoles().size()];

            if (roles.length > 0) {
                it = user.getUserRoles().iterator();

                int i = 0;

                while (it.hasNext()) {
                    UserRole userRole = (UserRole) it.next();
                    roles[i] = new Integer(userRole.getId().getRoles().getRolIdint());
                    i++;
                }
            }

            obj.setRoles(roles);

            obj.setSignature(mailPreferences.getMaprSignature());

            if (mailPreferences.getMaprSpamTolerance() == 100) {
                obj.setSpamTolerance(true);
            } else {
                obj.setSpamTolerance(false);
            }

            obj.setUsername(user.getUseUsername());
            obj.setVacationBody(mailPreferences.getMaprVacationBody());
            obj.setVacationSubject(mailPreferences.getMaprVacationSubject());
            obj.setVactionActive(mailPreferences.isMaprVacationActive());

            int usedQuotaSize = getUsedQuotaSize(hsession, user);
            usedQuotaSize /= 1024;

            if (usedQuotaSize > 1024) {
                usedQuotaSize /= 1024;
                obj.setUsedQuota(usedQuotaSize + " MB");
            } else {
                obj.setUsedQuota(((usedQuotaSize > 0) ? (usedQuotaSize + "") : "<1") + " kB");
            }

            users.addElement(obj);
        }

        searchUsersObj.setUsers(users);

        return searchUsersObj;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.admin.manager.AdminManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*  w  ww  . j ava 2 s . co  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param token DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
public SearchUsersObj suggestUsers(Session hsession, String token, int page, int byPage) throws Exception {
    SearchUsersObj searchUsersObj = new SearchUsersObj();
    Vector users = new Vector();

    try {
        Criteria crit = hsession.createCriteria(Users.class);
        crit.add(Restrictions.or(Restrictions.ilike("useName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("useEmail", token, MatchMode.ANYWHERE)));
        searchUsersObj.setHits(crit.list().size());

        crit = hsession.createCriteria(Users.class);
        crit.add(Restrictions.or(Restrictions.ilike("useName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("useEmail", token, MatchMode.ANYWHERE)));
        crit.setFirstResult(page * byPage);
        crit.setMaxResults(byPage);
        crit.addOrder(Order.asc("useName"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Users user = (Users) scroll.get(0);

            UserObj obj = new UserObj();

            obj.setActive(user.isUseActive());
            obj.setEmail(user.getUseEmail());

            Iterator it = user.getMailPreferenceses().iterator();
            MailPreferences mailPreferences = (MailPreferences) it.next();

            obj.setHtmlMessages(mailPreferences.isMaprHtmlMessage());
            obj.setIdint(user.getUseIdint());
            obj.setLanguage(user.getUseLanguage());
            obj.setMessagesByPage(mailPreferences.getMaprMessagesByPage());
            obj.setName(user.getUseName());
            obj.setPassword(user.getUsePassword());
            obj.setQuotaSize(mailPreferences.getMaprQuotaSize());
            obj.setRegisterDate(user.getUseRegisterDate());

            Integer[] roles = new Integer[user.getUserRoles().size()];

            if (roles.length > 0) {
                it = user.getUserRoles().iterator();

                int i = 0;

                while (it.hasNext()) {
                    UserRole userRole = (UserRole) it.next();
                    roles[i] = new Integer(userRole.getId().getRoles().getRolIdint());
                    i++;
                }
            }

            obj.setRoles(roles);

            obj.setSignature(mailPreferences.getMaprSignature());

            if (mailPreferences.getMaprSpamTolerance() == 100) {
                obj.setSpamTolerance(true);
            } else {
                obj.setSpamTolerance(false);
            }

            obj.setUsername(user.getUseUsername());
            obj.setVacationBody(mailPreferences.getMaprVacationBody());
            obj.setVacationSubject(mailPreferences.getMaprVacationSubject());
            obj.setVactionActive(mailPreferences.isMaprVacationActive());

            int usedQuotaSize = getUsedQuotaSize(hsession, user);
            usedQuotaSize /= 1024;

            if (usedQuotaSize > 1024) {
                usedQuotaSize /= 1024;
                obj.setUsedQuota(usedQuotaSize + " MB");
            } else {
                obj.setUsedQuota(((usedQuotaSize > 0) ? (usedQuotaSize + "") : "<1") + " kB");
            }

            users.addElement(obj);
        }

        searchUsersObj.setUsers(users);

        return searchUsersObj;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}