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.ensa.model.controller.impl.ImageDAOImpl.java

@Override
public List<Image> getPublicImages() {
    List<Image> liste = new ArrayList<Image>();
    Session session = this.sessionFactory.getCurrentSession();
    Query query = session.createQuery("FROM Image img WHERE img.pravacy='public'");
    query.setMaxResults(100);
    liste = query.list();/*from  ww  w.j  a  va 2s .  com*/
    return liste;
}

From source file:com.eryansky.modules.sys.service.OrganManager.java

License:Apache License

/**
 *
 * ??Organ./*from   w  w  w .j ava 2  s . c  o m*/
 *
 * @param sysCode
 *            ?
 * @return
 */
public Organ getBySysCode(String sysCode) {
    if (StringUtils.isBlank(sysCode)) {
        return null;
    }
    Parameter parameter = new Parameter(StatusState.NORMAL.getValue(), sysCode);
    StringBuffer hql = new StringBuffer();
    hql.append("from Organ o  where o.status = :p1 and o.sysCode = :p2");
    Query query = getEntityDao().createQuery(hql.toString(), parameter);
    query.setMaxResults(1);
    List<Organ> list = query.list();
    return list.isEmpty() ? null : list.get(0);
}

From source file:com.eryansky.modules.sys.service.OrganManager.java

License:Apache License

/**
 *
 * ??Organ./* w  w w. j  a  v a2 s . c  o  m*/
 *
 * @param code
 *            ?
 * @return
 */
public Organ getByCode(String code) {
    if (StringUtils.isBlank(code)) {
        return null;
    }
    Parameter parameter = new Parameter(StatusState.NORMAL.getValue(), code);
    StringBuffer hql = new StringBuffer();
    hql.append("from Organ o  where o.status = :p1 and o.code = :p2");
    Query query = getEntityDao().createQuery(hql.toString(), parameter);
    query.setMaxResults(1);
    List<Organ> list = query.list();
    return list.isEmpty() ? null : list.get(0);
}

From source file:com.eryansky.modules.sys.service.ResourceManager.java

License:Apache License

/**
 * ????/*from   ww w .  ja  v  a2s . c  o  m*/
 * @param resourceCode ??
 * @return
 */
public Resource getByCode(String resourceCode) {
    Parameter parameter = new Parameter(StatusState.NORMAL.getValue(), resourceCode);
    StringBuffer hql = new StringBuffer();
    hql.append("from Resource r where r.status = :p1 and r.code = :p2 ");
    Query query = getEntityDao().createQuery(hql.toString(), parameter);
    query.setMaxResults(1);
    List<Resource> list = query.list();
    return list.isEmpty() ? null : list.get(0);
}

From source file:com.eryansky.modules.sys.service.UserPasswordManager.java

License:Apache License

/**
 * ?ID//from w  w  w  . j  a  v  a 2  s . c  om
 * <br/>? ??
 * @param userId ID
 * @param maxSize  null
 * @return
 */
public List<UserPassword> getUserPasswordsByUserId(String userId, Integer maxSize) {
    Parameter parameter = new Parameter(userId, StatusState.NORMAL.getValue());
    StringBuffer hql = new StringBuffer();
    hql.append("from UserPassword u where u.userId = :p1 and u.status = :p2 order by u.modifyTime desc");

    Query query = getEntityDao().createQuery(hql.toString(), parameter);
    if (maxSize != null) {
        query.setMaxResults(maxSize);
    }

    return query.list();
}

From source file:com.eurodyn.uns.dao.hibernate.HibernateChannelDao.java

License:Mozilla Public License

@Override
public Map findTestEventsForChannel(Channel channel) throws DAOException {
    Session session = null;//  w ww.ja v a  2s .c om
    try {
        session = getSession();
        Query query = session
                .createQuery("select e  from Event as e where e.channel=:channel order by e.id desc) ");
        query.setEntity("channel", channel);
        query.setMaxResults(10);
        Map things = new HashMap();
        List eventList = query.list();
        for (Iterator iter = eventList.iterator(); iter.hasNext();) {
            Event event = (Event) iter.next();
            boolean hasTitle = false;
            String ext_id = event.getExtId();
            RDFThing thing = (RDFThing) things.get(ext_id);
            if (thing == null) {
                hasTitle = false;
                thing = new RDFThing(ext_id, event.getRtype());
                thing.setEventId(new Integer(event.getId()));
                thing.setReceivedDate(event.getCreationDate());
                things.put(ext_id, thing);
            }
            Collection event_metadata = event.getEventMetadataSet();
            for (Iterator iterator = event_metadata.iterator(); iterator.hasNext();) {
                EventMetadata em = (EventMetadata) iterator.next();
                String property = em.getProperty();
                String value = em.getValue();

                ArrayList vals = (ArrayList) thing.getMetadata().get(property);
                if (vals != null) {
                    vals.add(value);
                } else {
                    ArrayList nar = new ArrayList();
                    nar.add(value);
                    thing.getMetadata().put(property, nar);
                }

                //thing.getMetadata().put(property, value);
                if (!hasTitle && property.endsWith("/title")) {
                    if (value != null) {
                        thing.setTitle(value);
                    }
                }

            }

        }

        return things;
    } catch (HibernateException e) {
        throw new DAOException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery.java

License:Apache License

public Query getAsHqlQuery(Session session) {
    String text = getAsHqlText(0);
    LOGGER.trace("HQL text generated:\n{}", text);
    Query query = session.createQuery(text);
    for (Map.Entry<String, QueryParameterValue> parameter : parameters.entrySet()) {
        String name = parameter.getKey();
        QueryParameterValue parameterValue = parameter.getValue();
        LOGGER.trace("Parameter {} = {}", name, parameterValue.debugDump());

        if (parameterValue.getValue() instanceof Collection) {
            if (parameterValue.getType() != null) {
                query.setParameterList(name, (Collection) parameterValue.getValue(), parameterValue.getType());
            } else {
                query.setParameterList(name, (Collection) parameterValue.getValue());
            }//  w  ww .ja va 2s  .  c om
        } else {
            if (parameterValue.getType() != null) {
                query.setParameter(name, parameterValue.getValue(), parameterValue.getType());
            } else {
                query.setParameter(name, parameterValue.getValue());
            }
        }
    }
    if (maxResults != null) {
        query.setMaxResults(maxResults);
    }
    if (firstResult != null) {
        query.setFirstResult(firstResult);
    }
    if (resultTransformer != null) {
        query.setResultTransformer(resultTransformer);
    }
    return query;
}

From source file:com.example.app.login.oneall.model.OneAllDAO.java

License:Open Source License

/**
 * Gets principal for user token./*from  w ww  .j  a va2s.  com*/
 *
 * @param userToken the user token
 * @param provider the provider
 * @param domains the domains.  If empty, will return any principal within the system that is linked to the given token
 *
 * @return the principal for user token
 */
@Nullable
public Principal getPrincipalForUserToken(@Nonnull String userToken, @Nonnull String provider,
        @Nonnull AuthenticationDomainList domains) {
    if (!domains.isEmpty()) {
        return _principalDAO.getPrincipalByOpenAuth(OneAllLoginService.SERVICE_IDENTIFIER, userToken, provider,
                domains);
    } else {
        final String queryString = "select p from Principal p \n" + "inner join p.credentials cred \n"
                + "where cred.openAuthType = :openAuthType \n" + "and cred.openAuthId = :openAuthId \n"
                + "and cred.openAuthSubType = :openAuthSubType";
        return doInTransaction(session -> {
            Query query = getSession().createQuery(queryString);
            query.setParameter("openAuthType", OneAllLoginService.SERVICE_IDENTIFIER);
            query.setString("openAuthSubType", provider);
            query.setString("openAuthId", userToken);
            query.setMaxResults(1);
            return (Principal) query.uniqueResult();
        });
    }
}

From source file:com.fiveamsolutions.nci.commons.service.AbstractBaseAggregateSearchBean.java

License:Open Source License

/**
 * {@inheritDoc}/*from w w  w.  jav a  2 s  . c o m*/
 * 
 */
public Map<S, Long> aggregate(GroupableSearchCriteria<S, T> criteria, PageSortParams<T> pageSortParams,
        List<? extends GroupByCriteria<T>> groupByCriterias) {
    validateSearchCriteria(criteria);
    StringBuffer orderBy = new StringBuffer("");
    StringBuffer joinClause = new StringBuffer("");
    if (pageSortParams != null) {
        processFixedSortCriteria(criteria, pageSortParams, orderBy, joinClause);
        processDynamicSortCriteria(criteria, pageSortParams, orderBy);
    }

    StringBuffer groupBy = new StringBuffer("");
    if (groupByCriterias != null) {
        processFixedGroupByCriteria(criteria, groupByCriterias, groupBy);
    }

    Query q;
    q = criteria.getQuery(orderBy.toString(), joinClause.toString(), groupBy.toString(), false);

    if (pageSortParams != null) {
        q.setMaxResults(pageSortParams.getPageSize());
        if (pageSortParams.getIndex() > 0) {
            q.setFirstResult(pageSortParams.getIndex());
        }
    }

    return getAggregateResults(criteria, q);
}

From source file:com.fiveamsolutions.nci.commons.service.AbstractBaseSearchBean.java

License:Open Source License

/**
 * {@inheritDoc}/*  ww  w. ja va2  s.co m*/
 */
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<T> search(SearchCriteria<T> criteria, PageSortParams<T> pageSortParams) {
    validateSearchCriteria(criteria);
    StringBuffer orderBy = new StringBuffer("");
    StringBuffer joinClause = new StringBuffer("");
    if (pageSortParams != null) {
        processFixedSortCriteria(criteria, pageSortParams, orderBy, joinClause);
        processDynamicSortCriteria(criteria, pageSortParams, orderBy);
    }

    Query q = criteria.getQuery(orderBy.toString(), joinClause.toString(), false);

    if (pageSortParams != null) {
        q.setMaxResults(pageSortParams.getPageSize());
        if (pageSortParams.getIndex() > 0) {
            q.setFirstResult(pageSortParams.getIndex());
        }
    }

    return getResultList(q);
}