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.jshop.dao.impl.JshopbasicInfoTDaoImpl.java

@SuppressWarnings("unchecked")
public List<JshopbasicInfoT> findAllJshopbasicInfoNoParam(final int currentPage, final int lineSize,
        final String state) {
    log.debug("find all findAllJshopbasicInfoNoParam");
    try {/*  w  w  w.j a  v  a  2 s .  c om*/
        List<JshopbasicInfoT> list = this.getHibernateTemplate().executeFind(new HibernateCallback() {

            String queryString = "from JshopbasicInfoT as jbi where jbi.state=:state and jbi.openstate=:openstate";

            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query query = session.createQuery(queryString);
                query.setFirstResult((currentPage - 1) * lineSize);
                query.setMaxResults(lineSize);
                query.setParameter("state", state);
                query.setParameter("openstate", state);
                List list = query.list();
                return list;
            }
        });
        return list;
    } catch (RuntimeException re) {
        log.error("find all findAllJshopbasicInfoNoParam error", re);
        throw re;
    }
}

From source file:com.knowbout.epg.entities.Network.java

License:Apache License

public static Network findByCallSign(String callSign) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Network.findByCallSign");
    query.setString("callSign", callSign);
    query.setMaxResults(1);
    return (Network) query.uniqueResult();
}

From source file:com.knowbout.epg.entities.Program.java

License:Apache License

@SuppressWarnings("unchecked")
private static Program createMissingShow(Session session, String showId) {
    log.debug("Calling createMissingShow()");
    boolean commit = false;
    if (TransactionManager.currentTransaction() == null) {
        TransactionManager.beginTransaction();
        commit = true;//from   w ww .j  a v a2s  .  com
    }
    try {
        Query query = session.getNamedQuery("Program.selectLikeId");
        String programIdLikeEpisode = "EP" + showId.substring(2, 10) + "%";
        query.setString("programIdLike", programIdLikeEpisode);
        query.setMaxResults(1);
        List<Program> programs = query.list();
        if (programs == null || programs.size() == 0) {
            return null;
        }
        Program sample = programs.get(0);
        Program show = new Program();
        show.setAdultSituationsAdvisory(sample.getAdultSituationsAdvisory());
        show.setAltSynEpiNum("");
        show.setAltTitle("");
        show.setBriefNudityAdvisory(sample.getBriefNudityAdvisory());
        show.setColorCode(sample.getColorCode());
        show.setDescription(truncateWithDots(255,
                "A series with a variety of episodes such as: " + sample.getDescription()));
        show.setDescriptionActors(show.getDescription());
        show.setGenreDescription(sample.getGenreDescription());
        show.setGraphicLanguageAdvisory(sample.getGraphicLanguageAdvisory());
        show.setGraphicViolenceAdvisory(sample.getGraphicViolenceAdvisory());
        show.setHoliday("");
        show.setProgramId(showId);
        show.setLastModified(new Date());
        show.setMadeForTv(sample.isMadeForTv());
        show.setMpaaRating("");
        show.setNetSynSource(sample.getNetSynSource());
        show.setNetSynType(sample.getNetSynType());
        show.setOrgCountry(sample.getOrgCountry());
        show.setOrginalAirDate(null);
        show.setOrgStudio(sample.getOrgStudio());
        show.setProgramLanguage(sample.getProgramLanguage());
        show.setRapeAdvisory(sample.getRapeAdvisory());
        show.setReducedDescription120("A series with a variety of episodes.");
        show.setReducedDescription60("A series with a variety of episodes.");
        show.setReducedDescription40("A series with a variety of episodes.");
        show.setReducedDescriptionActors("A series with a variety of episodes.");
        show.setReducedTitle10(sample.getReducedTitle10());
        show.setReducedTitle20(sample.getReducedTitle20());
        show.setReducedTitle40(sample.getReducedTitle40());
        show.setReducedTitle70(sample.getReducedTitle70());
        show.setRunTime(sample.getRunTime());
        show.setShowType(sample.getShowType());
        show.setSourceType(sample.getSourceType());
        show.setSscAdvisory(sample.getSscAdvisory());
        show.setStarRating(sample.getStarRating());
        show.setSynEpiNum(null);
        show.setProgramTitle(sample.getProgramTitle());
        show.setUniqueId("");
        show.setYear(null);
        show.insert();
        if (commit) {
            TransactionManager.commitTransaction();
        }

        return show;
    } catch (Error e) {
        log.error("Could not create SHow", e);
        TransactionManager.rollbackTransaction();
        throw e;
    }
}

From source file:com.knowbout.epg.entities.Program.java

License:Apache License

@SuppressWarnings("unchecked")
private static Program createMissingTeam(Session session, String sportName, String teamName) {
    log.debug("Calling createMissingTeam()");
    boolean commit = false;
    if (TransactionManager.currentTransaction() == null) {
        TransactionManager.beginTransaction();
        commit = true;//from w  ww. j  a v a  2  s .  c om
    }
    try {
        Query query = session.getNamedQuery("Program.selectProgramsWithTeam");
        query.setString("programTitle", sportName);
        String episodeTitleLike = "%" + teamName + "%";
        query.setString("episodeTitleLike", episodeTitleLike);
        query.setMaxResults(1);
        List<Program> programs = query.list();
        if (programs == null || programs.size() == 0) {
            return null;
        }

        query = session.createQuery("select MAX(programId) from Program");
        String maxProgramId = (String) query.uniqueResult();
        String teamId = null;
        if (maxProgramId != null && maxProgramId.startsWith("TE")) {
            StringBuilder sb = new StringBuilder();
            Formatter formatter = new Formatter(sb, Locale.US);
            formatter.format("TE%08d0000", Integer.valueOf(maxProgramId.substring(2, 10)) + 1);
            teamId = sb.toString();
        } else {
            teamId = "TE000000010000";
        }

        Program sample = programs.get(0);
        Program team = new Program();
        team.setAdultSituationsAdvisory(sample.getAdultSituationsAdvisory());
        team.setAltSynEpiNum("");
        team.setAltTitle("");
        team.setBriefNudityAdvisory(sample.getBriefNudityAdvisory());
        team.setColorCode(sample.getColorCode());
        team.setDescription("Games played by the " + teamName);
        team.setDescriptionActors(team.getDescription());
        team.setEpisodeTitle(sportName);
        team.setGenreDescription(sample.getGenreDescription());
        team.setGraphicLanguageAdvisory(sample.getGraphicLanguageAdvisory());
        team.setGraphicViolenceAdvisory(sample.getGraphicViolenceAdvisory());
        team.setHoliday("");
        team.setProgramId(teamId);
        team.setLastModified(new Date());
        team.setMadeForTv(sample.isMadeForTv());
        team.setMpaaRating("");
        team.setNetSynSource(sample.getNetSynSource());
        team.setNetSynType(sample.getNetSynType());
        team.setOrgCountry(sample.getOrgCountry());
        team.setOrginalAirDate(null);
        team.setOrgStudio(sample.getOrgStudio());
        team.setProgramLanguage(sample.getProgramLanguage());
        team.setRapeAdvisory(sample.getRapeAdvisory());
        team.setReducedDescription120(truncateWithDots(120, team.getDescription()));
        team.setReducedDescription60("Games played by this team.");
        team.setReducedDescription40("Games played by this team.");
        team.setReducedDescriptionActors("Games played by this team.");
        team.setReducedTitle10(teamName.length() > 10 ? teamName.substring(0, 10) : teamName);
        team.setReducedTitle20(teamName.length() > 20 ? teamName.substring(0, 20) : teamName);
        team.setReducedTitle40(teamName.length() > 40 ? teamName.substring(0, 40) : teamName);
        team.setReducedTitle70(teamName.length() > 70 ? teamName.substring(0, 70) : teamName);
        team.setRunTime(sample.getRunTime());
        team.setShowType(sample.getShowType());
        team.setSourceType(sample.getSourceType());
        team.setSscAdvisory(sample.getSscAdvisory());
        team.setStarRating(sample.getStarRating());
        team.setSynEpiNum(null);
        team.setProgramTitle(teamName);
        team.setUniqueId("");
        team.setYear(null);
        team.insert();
        if (commit) {
            TransactionManager.commitTransaction();
        }

        return team;
    } catch (Error e) {
        log.error("Could not create TEam", e);
        TransactionManager.rollbackTransaction();
        throw e;
    }
}

From source file:com.knowbout.epg.entities.Schedule.java

License:Apache License

private static Query createNextAiringsQuery(String lineup, String where, boolean onlyIfNew,
        boolean includeNowAiring, int limit) {
    StringBuilder q = new StringBuilder();
    q.append("from NetworkSchedule as n ");
    q.append(where);/*from w  ww  .ja v a 2  s .  c  o  m*/
    q.append(" and n.networkLineup.id = :lineup");
    if (includeNowAiring) {
        q.append(" and n.schedule.endTime > :currentTime");
    } else {
        q.append(" and n.schedule.airTime > :currentTime");
    }
    if (onlyIfNew) {
        q.append(" and n.schedule.newEpisode = true");
    }
    q.append(" order by n.schedule.airTime");
    Session session = HibernateUtil.currentSession();
    Query query = session.createQuery(q.toString());
    query.setTimestamp("currentTime", new Date());
    query.setString("lineup", lineup);
    if (limit > 0) {
        query.setMaxResults(limit);
    }
    return query;
}

From source file:com.knowbout.epg.entities.Schedule.java

License:Apache License

@SuppressWarnings("unchecked")
public static NetworkSchedule selectLastProgram(String lineup, String programId, Date startDate) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getLastProgramSchedule");
    query.setTimestamp("startTime", startDate);
    query.setString("programId", programId);
    query.setString("lineup", lineup);
    query.setMaxResults(1);
    return (NetworkSchedule) query.uniqueResult();
}

From source file:com.knowbout.epg.entities.Schedule.java

License:Apache License

@SuppressWarnings("unchecked")
public static NetworkSchedule selectLastShowOrEpisode(String lineup, String showId, Date startDate) {
    assert showId.startsWith("SH") : "showId must start with SH";
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getLastShowSchedule");
    query.setTimestamp("startTime", startDate);
    query.setString("showId", showId);
    query.setString("episodeIdLike", "EP" + showId.substring(2, 10) + "%");
    query.setString("lineup", lineup);
    query.setMaxResults(1);
    return (NetworkSchedule) query.uniqueResult();
}

From source file:com.knowbout.epg.entities.Schedule.java

License:Apache License

@SuppressWarnings("unchecked")
public static NetworkSchedule selectLastTeamGame(String lineup, String teamId, Date startDate) {
    assert teamId.startsWith("TE") : "teamId must start with TE";
    Program team = Program.selectById(teamId);
    assert (team != null) : "Couldn't find team for programId " + teamId;
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getLastTeamSchedule");
    query.setTimestamp("startTime", startDate);
    query.setString("sportName", team.getProgramTitle());
    query.setString("teamLike", "%" + team.getEpisodeTitle() + "%");
    query.setString("lineup", lineup);
    query.setMaxResults(1);
    return (NetworkSchedule) query.uniqueResult();
}

From source file:com.krawler.dao.BaseDAO.java

License:Open Source License

/**
 * Executes a limit select query using the provided query, parameters and
 * limits. Limits are provided using the pagingParam parameter.
 * /*w  w  w.j av a  2 s . c om*/
 * @param hql
 *            The query to execute
 * @param params
 *            Query Paramter
 * @param pagingParam
 *            Limit paramters. The first entry is the lower limit and the
 *            second is the upper limit
 * @return List
 */
public List executeQueryPaging(final String hql, final Object[] params, final Integer[] pagingParam) {
    List results = null;
    results = getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(hql);

            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    query.setParameter(i, params[i]);
                }
            }
            query.setFirstResult(pagingParam[0]);
            query.setMaxResults(pagingParam[1]);

            return query.list();
        }
    });
    return results;
}

From source file:com.krawler.dao.BaseDAO.java

License:Open Source License

public List executeQuery(final String hql, final Object[] params, final Map<String, Object> namedParams,
        final int[] pagingParams) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(hql);
            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    query.setParameter(i, params[i]);
                }/*www .  j  a v  a2s.  c  o  m*/
            }
            if (namedParams != null) {
                for (Map.Entry<String, Object> entry : namedParams.entrySet()) {
                    Object value = entry.getValue();
                    if (value != null) {
                        if (value instanceof Collection)
                            query.setParameterList(entry.getKey(), (Collection) value);
                        else if (entry.getValue().getClass().isArray())
                            query.setParameterList(entry.getKey(), (Object[]) value);
                        else
                            query.setParameter(entry.getKey(), entry.getValue());
                    } else
                        query.setParameter(entry.getKey(), entry.getValue());
                }
            }
            if (pagingParams != null) {
                query.setFirstResult(pagingParams[0]);
                query.setMaxResults(pagingParams[1]);
            }
            return query.list();
        }
    });
}