Example usage for org.hibernate.query Query setParameter

List of usage examples for org.hibernate.query Query setParameter

Introduction

In this page you can find the example usage for org.hibernate.query Query setParameter.

Prototype

@Override
    <P> Query<R> setParameter(String name, P val, TemporalType temporalType);

Source Link

Usage

From source file:de.tudarmstadt.ukp.wikipedia.api.Wikipedia.java

License:Apache License

/**
 * Return an iterable containing all archived discussion pages for
 * the given article page. The most recent discussion page is not included.
 * The most recent discussion page can be obtained with {@link #getDiscussionPage(Page)}.
 * <br>//from w  w w.  ja va  2s.com
 * The provided page Object must not be a discussion page itself! If it is
 * a discussion page, is returned unchanged.
 *
 * @param articlePage the article page for which a discussion archives should be retrieved
 * @return An iterable with the discussion archive page objects for the given article page object
 * @throws WikiApiException If no page or redirect with this title exists or title could not be properly parsed.
 */
public Iterable<Page> getDiscussionArchives(Page articlePage) throws WikiApiException {
    String articleTitle = articlePage.getTitle().getWikiStyleTitle();
    if (!articleTitle.startsWith(WikiConstants.DISCUSSION_PREFIX)) {
        articleTitle = WikiConstants.DISCUSSION_PREFIX + articleTitle;
    }

    Session session = this.__getHibernateSession();
    session.beginTransaction();

    List<Page> discussionArchives = new LinkedList<Page>();

    Query query = session.createQuery("SELECT pageID FROM PageMapLine where name like :name");
    query.setParameter("name", articleTitle + "/%", StringType.INSTANCE);
    Iterator results = query.list().iterator();

    session.getTransaction().commit();

    while (results.hasNext()) {
        int pageID = (Integer) results.next();
        discussionArchives.add(getPage(pageID));
    }

    return discussionArchives;

}

From source file:hu.vitamas.enotesz.dao.EventsDao.java

License:Apache License

/**
 * Returns with upcoming events.//  w  w w . j ava 2 s .  c  om
 * 
 * @param userID id of current user
 * @return list of events
 */
public List<Events> upcomingEvents(Integer userID) {
    Instant nowInstant = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant();

    openSession();
    Query<Events> q = getSession()
            .createQuery("FROM Events WHERE dateTo >= :day and user = :user ORDER BY dateFrom", Events.class);
    q.setParameter("day", Date.from(nowInstant), TemporalType.DATE);
    q.setParameter("user", userID);
    q.setMaxResults(8);
    List<Events> result = q.list();
    closeSession();
    return result;
}

From source file:hu.vitamas.enotesz.dao.EventsDao.java

License:Apache License

/**
 * Returns with events by specified date.
 * /*w  w w. jav a2 s  .  c o m*/
 * @param day Date of selected day
 * @param userID id of current user
 * @return list of events
 */
public List<Events> eventsByDay(Date day, Integer userID) {
    openSession();
    Query<Events> q = getSession().createQuery(
            "FROM Events WHERE (dateFrom <= :day and dateTo >= :day) and user = :user", Events.class);
    q.setParameter("day", day, TemporalType.DATE);
    q.setParameter("user", userID);
    List<Events> result = q.list();
    closeSession();
    return result;
}