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.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByInvitee(long id, User user) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getByInvitee");
    query.setLong("id", id);
    query.setEntity("user", user);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByInviter(long id, User user) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getByInviter");
    query.setLong("id", id);
    query.setEntity("user", user);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Friend> findFriends(User user) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getFriends");
    query.setEntity("user", user);
    return query.list();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Friend> findInvites(User user) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getInvites");
    query.setString("email", user.getPrimaryEmail());
    query.setEntity("invitee", user);
    return query.list();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static int getInviteCount(User user) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getInviteCount");
    query.setString("email", user.getPrimaryEmail());
    return (Integer) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByUser(User user, User friend) {
    Session session = getSession();
    Query query = session.getNamedQuery("Friend.getByUser");
    query.setEntity("inviter", user);
    query.setEntity("invitee", friend);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Message.java

License:Apache License

/**
 * /*from  w  ww  .j a  v  a  2s.c o  m*/
 * @param max
 * @return
 */
@SuppressWarnings("unchecked")
public static List<Message> getUnsentMessages(int maxResults, int maxAttempts) {
    Session session = getSession();
    Query query = session.getNamedQuery("Message.getUnsent");
    query.setTimestamp("now", new Timestamp(System.currentTimeMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.setMaxResults(maxResults);
    return query.list();
}

From source file:com.appeligo.search.entity.Message.java

License:Apache License

public static void deleteOldMessages(int days, int maxAttempts) {
    Session session = getSession();
    Query query = session.getNamedQuery("Message.deleteOldMessages");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, (0 - (days * 24)));
    query.setTimestamp("oldestSent", new Timestamp(cal.getTimeInMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.executeUpdate();/*ww  w. j  a v  a 2s  .  c  om*/
}

From source file:com.appeligo.search.entity.Rating.java

License:Apache License

public static List<Rating> findByUser(User user) {
    Permissions.checkUser(user);/*from w  ww. ja  va 2s  .  com*/
    Session session = getSession();
    Query query = session.getNamedQuery("Rating.getUserRatings");
    query.setEntity("user", user);
    return query.list();
}

From source file:com.appeligo.search.entity.Rating.java

License:Apache License

public static Rating findProgramRating(User user, String programId) {
    Permissions.checkUser(user);//from w w w  . jav  a 2  s .co m
    Session session = getSession();
    Query query = session.getNamedQuery("Rating.getProgram");
    query.setEntity("user", user);
    query.setString("programId", programId);
    return (Rating) query.uniqueResult();
}