Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FriendRequestDAO.java

@Override
public FriendRequest getFriendRequest(Users logedInUser, Users user) {
    Session session = getCurrentSession();
    try {//from   w w  w  .  j  a  v  a  2  s.  c o m
        Query query = session.createQuery("from " + this.genericType.getName()
                + " request WHERE (request.userSender.id = :logedInUser AND request.userReciever.id = :user) OR ( request.userSender.id = :user AND request.userReciever.id = :logedInUser)");
        query.setLong("logedInUser", logedInUser.getId()).setLong("user", user.getId());
        return (FriendRequest) query.uniqueResult();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } finally {
        closeSession(session);
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FriendRequestDAO.java

@Override
public List<FriendRequest> getFriendRequests(Long userId) {
    Session session = getCurrentSession();
    try {//w  ww. j  ava 2 s. c  om
        Query query = session.createQuery("from " + this.genericType.getName()
                + " request WHERE request.userReciever.id = :userId ORDER BY request.dateSent DESC");
        query.setLong("userId", userId);
        return (List<FriendRequest>) query.list();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();
    } finally {
        closeSession(session);
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FriendsDAO.java

@Override
public Friends getFriend(Users logedInUser, Users user) {
    Session session = getCurrentSession();
    try {/*from w  w w.  j ava 2 s.  co m*/
        Query query = session.createQuery("from " + this.genericType.getName()
                + " friend WHERE (friend.user.id = :logedInUser AND friend.friend.id = :user) OR ( friend.user.id = :user AND friend.friend.id = :logedInUser) ORDER BY friend.friendsSince DESC");
        query.setLong("logedInUser", logedInUser.getId()).setLong("user", user.getId());
        return (Friends) query.uniqueResult();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } finally {
        closeSession(session);
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FriendsDAO.java

@Override
public List<Friends> getFriend(Users logedInUser) {
    Session session = getCurrentSession();
    try {/*from ww  w . j  a va2  s  .c om*/
        Query query = session.createQuery("from " + this.genericType.getName()
                + " friend WHERE (friend.user.id = :logedInUser) OR ( friend.friend.id = :logedInUser)");
        query.setLong("logedInUser", logedInUser.getId());
        return (List<Friends>) query.list();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();
    } finally {
        closeSession(session);
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.PostDAO.java

@Override
public Post getPostById(long postId) {
    Session session = this.getCurrentSession();
    try {// ww  w .  j  av a  2  s . c  o  m
        Query query = session
                .createQuery("from " + this.genericType.getName() + " post where post.id = :postId");
        return (Post) query.setLong("postId", postId).uniqueResult();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } finally {
        session.close();
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.PostDAO.java

@Override
public List<Post> getFriendsPosts(Long userId) {
    Session session = this.getCurrentSession();
    try {/*from  www  . j  a v a  2 s  .  co  m*/
        String qery = "select post from " + this.genericType.getName()
                + " post, Friends as f WHERE ((f.user.id = :userId AND post.user.id = f.friend.id ) OR (f.friend.id = :userId AND post.user.id = f.user.id)) AND post.visibility = :visibility ORDER BY post.dateSent DESC";
        Query selectQuery = session.createQuery(qery);
        selectQuery.setLong("userId", userId).setInteger("visibility", Visibility.FRIENDS);

        selectQuery.setMaxResults(Constants.MAX_RESULTS);
        List<Post> results = selectQuery.list();

        return results;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();

    } finally {
        session.close();
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.PostDAO.java

@Override
public List<Post> getFollowingPosts(Long userId) {
    Session session = this.getCurrentSession();
    try {/*  w  w  w . j  ava  2 s  .  com*/
        String qery = "select post from " + this.genericType.getName()
                + " post, Following as f WHERE (f.follower.id = :userId AND post.user.id = f.feeder.id ) AND post.visibility = :visibility ORDER BY post.dateSent DESC";
        Query selectQuery = session.createQuery(qery);
        selectQuery.setLong("userId", userId).setInteger("visibility", Visibility.PUBLIC);

        selectQuery.setMaxResults(Constants.MAX_RESULTS);
        List<Post> results = selectQuery.list();

        return results;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();

    } finally {
        session.close();
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.PostDAO.java

@Override
public List<Post> getUserPosts(Long userId) {
    Session session = this.getCurrentSession();
    try {/*from  www  .j av a 2  s. c  o m*/
        String qery = "from " + this.genericType.getName()
                + " post WHERE post.user.id = :userId ) ORDER BY post.dateSent DESC";
        Query selectQuery = session.createQuery(qery);
        selectQuery.setLong("userId", userId);

        selectQuery.setMaxResults(Constants.MAX_RESULTS);
        List<Post> results = selectQuery.list();

        return results;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();

    } finally {
        session.close();
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.PostDAO.java

@Override
public List<Tag> getPostTags(long postId) {
    Session session = getCurrentSession();
    try {/*  w w  w.j  av a2  s  .c o  m*/
        Query query = session.createQuery("select tags from " + this.genericType.getName()
                + " post INNER JOIN post.tags tags where post.id = :postId");
        query.setLong("postId", postId);
        return query.list();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.RatedPostsDAO.java

@Override
public RatedPosts getRateType(Long postId, String username) {
    Session session = this.getCurrentSession();
    try {//from  w  w  w .j  a v a  2  s .c om
        Query query = session.createQuery("from " + this.genericType.getName()
                + " rp WHERE rp.post.id = :postId AND rp.user.username = :username");
        return (RatedPosts) query.setLong("postId", postId).setString("username", username).uniqueResult();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } finally {
        session.close();
    }
}