Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

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 w  w.j  av  a2 s .c  o m
    }
    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  ww  w  .  j a  va  2s  .  c  o m*/
    }
    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.Program.java

License:Apache License

@SuppressWarnings("unchecked")
public static Program selectByTeam(String sportName, String teamName) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Program.selectByTeam");
    query.setString("programTitle", teamName);
    query.setString("episodeTitle", sportName);
    Program program = (Program) query.uniqueResult();
    if (program == null) {
        program = createMissingTeam(session, sportName, teamName);
    }//from   w  w w . j av a  2s .c  o m
    return program;
}

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

License:Apache License

@SuppressWarnings("unchecked")
public static List<Program> selectByModificationDate(Date date) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Program.selectAfterModifiedDate");
    query.setTimestamp("date", date);
    List<Program> list = query.list();
    return list;//from  ww  w .j  a  va 2s .  co m

}

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

License:Apache License

public static ScrollableResults selectAllShowsMoviesSports() {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Program.selectAllShowsMoviesSports");
    ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
    return scroll;
}

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

License:Apache License

public static ScrollableResults selectAllTeams() {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Program.selectAllTeams");
    ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
    return scroll;
}

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

License:Apache License

/**
 *//*from   w w w  . j  a  v  a  2 s .  c  om*/
public static NetworkSchedule selectByTimeAndNetwork(String lineup, Date date, long networkId) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getNowPlaying");
    query.setTimestamp("currentTime", date);
    query.setLong("network", networkId);
    query.setString("lineup", lineup);
    NetworkSchedule sked = (NetworkSchedule) query.uniqueResult();
    return sked;
}

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

License:Apache License

/**
 *//*from  w  ww.j ava  2 s.c  o m*/
public static NetworkSchedule selectByTimeAndNetwork(String lineup, Date date, String callSign) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getNowPlayingCallSign");
    query.setTimestamp("currentTime", date);
    query.setString("callSign", callSign);
    query.setString("lineup", lineup);
    NetworkSchedule sked = (NetworkSchedule) query.uniqueResult();
    return sked;
}

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

License:Apache License

/**
 *//*from   w  w  w  .  j a  v a 2s . c  o m*/
@SuppressWarnings("unchecked")
public static List<NetworkSchedule> selectByTime(String lineup, Date date) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getNowPlayingLineup");
    query.setTimestamp("currentTime", date);
    query.setString("lineup", lineup);
    return (List<NetworkSchedule>) query.uniqueResult();
}

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

License:Apache License

@SuppressWarnings("unchecked")
public static List<NetworkSchedule> selectNextPrograms(List<String> programId, Date startDate) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Schedule.getAllNextProgramSchedulesForList");
    query.setTimestamp("startTime", startDate);
    query.setParameterList("programIds", programId, new StringType());
    return query.list();
}