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:com.salesmanager.core.service.order.impl.dao.OrderDao.java

License:Open Source License

public SearchOrderResponse searchOrder(SearchOrdersCriteria searchCriteria) {

    Criteria criteria = super.getSession().createCriteria(Order.class)
            .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId()))
            .add(Restrictions.eq("channel", OrderConstants.ONLINE_CHANNEL))
            .addOrder(org.hibernate.criterion.Order.desc("orderId"))
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    StringBuffer q = new StringBuffer();

    q.append(" select o from Order o where o.merchantId=:mId");
    q.append(" and channel=:channel");

    if (searchCriteria != null) {

        if (!StringUtils.isBlank(searchCriteria.getCustomerName())) {
            q.append(" and o.customerName like :cName");
        }/*  w  w  w  . j av  a2 s . c o m*/

        if (searchCriteria.getOrderId() != -1) {
            q.append(" and o.orderId= :oId");
        }

        if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) {
            if (searchCriteria.getSdate() != null) {
                q.append(" and o.datePurchased > :sDate");
            } else {
                q.append(" and o.datePurchased > :sDate");
            }
            if (searchCriteria.getEdate() != null) {
                q.append(" and o.datePurchased < :eDate");
            } else {
                q.append(" and o.datePurchased < :eDate");
            }
        }
    }
    q.append(" order by o.orderId desc");

    Query c = super.getSession().createQuery(q.toString());
    c.setInteger("channel", OrderConstants.ONLINE_CHANNEL);
    c.setInteger("mId", searchCriteria.getMerchantId());

    if (searchCriteria != null) {

        if (!StringUtils.isBlank(searchCriteria.getCustomerName())) {
            criteria.add(Restrictions.like("customerName", "%" + searchCriteria.getCustomerName() + "%"));
            c.setString("cName", "%" + searchCriteria.getCustomerName() + "%");
        }

        if (searchCriteria.getOrderId() != -1) {
            criteria.add(Restrictions.eq("orderId", searchCriteria.getOrderId()));
            c.setLong("oId", searchCriteria.getOrderId());
        }

        if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) {
            if (searchCriteria.getSdate() != null) {
                criteria.add(Restrictions.ge("datePurchased", searchCriteria.getSdate()));
                c.setDate("sDate", searchCriteria.getSdate());
            } else {
                criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), -1)));
                c.setDate("sDate", DateUtils.addDays(new Date(), -1));
            }
            if (searchCriteria.getEdate() != null) {
                criteria.add(Restrictions.le("datePurchased", searchCriteria.getEdate()));
                c.setDate("eDate", searchCriteria.getEdate());
            } else {
                criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), +1)));
                c.setDate("eDate", DateUtils.addDays(new Date(), +1));
            }
        }
    }

    criteria.setProjection(Projections.rowCount());
    Integer count = (Integer) criteria.uniqueResult();

    criteria.setProjection(null);

    int max = searchCriteria.getQuantity();

    List list = null;
    if (max != -1 && count > 0) {
        c.setMaxResults(searchCriteria.getUpperLimit(count));
        c.setFirstResult(searchCriteria.getLowerLimit());
        list = c.list();
    } else {
        list = c.list();
    }

    SearchOrderResponse response = new SearchOrderResponse();
    response.setCount(count);
    response.setOrders(list);

    return response;

}

From source file:com.salesmanager.core.service.order.impl.dao.OrderDao.java

License:Open Source License

public SearchOrderResponse searchOrderByCustomer(SearchOrdersCriteria searchCriteria) {

    Criteria criteria = super.getSession().createCriteria(Order.class)
            .add(Restrictions.eq("customerId", searchCriteria.getCustomerId()))
            .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId()))
            .add(Restrictions.eq("channel", OrderConstants.ONLINE_CHANNEL))
            .addOrder(org.hibernate.criterion.Order.desc("orderId"));

    StringBuffer q = new StringBuffer();

    q.append(" select o from Order o where o.merchantId=:mId");
    q.append(" and channel=:channel");

    q.append(" and o.customerId = :cId");
    q.append(" and o.merchantId = :mId");
    q.append(" order by o.orderId desc");

    Query query = super.getSession().createQuery(q.toString());
    query.setInteger("channel", OrderConstants.ONLINE_CHANNEL);
    query.setInteger("mId", searchCriteria.getMerchantId());
    query.setLong("cId", searchCriteria.getCustomerId());
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    criteria.setProjection(Projections.rowCount());
    Integer count = (Integer) criteria.uniqueResult();

    criteria.setProjection(null);//from   ww  w .  java2 s. co m

    int max = searchCriteria.getQuantity();

    List list = null;
    if (max != -1 && count > 0) {
        query.setMaxResults(searchCriteria.getUpperLimit(count));
        query.setFirstResult(searchCriteria.getLowerLimit());
        list = query.list();
    } else {
        list = query.list();
    }

    SearchOrderResponse response = new SearchOrderResponse();
    response.setCount(count);
    response.setOrders(list);

    return response;

}

From source file:com.slambook.repository.implementation.AlbumDAOImpl.java

@Override
public long getAlbumCoverImage(long albumId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Album.getAlbumCoverImage");
    query.setLong("albumId", albumId);
    long coverImage;
    coverImage = (Long) query.list().get(0);
    return coverImage;
}

From source file:com.slambook.repository.implementation.AlbumDAOImpl.java

@Override
public int getAlbumImageCount(long albumId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Album.getAlbumImageCount");
    query.setLong("albumId", albumId);
    int imageCount = ((Long) query.uniqueResult()).intValue();
    return imageCount;
}

From source file:com.slambook.repository.implementation.AlbumDAOImpl.java

@Override
public ArrayList getAlbums(long userId, int clickTimes) {

    int start = 0;
    int end = 0;/*  w  w w  .j  av  a  2  s  .  c  om*/

    if (clickTimes == 0) {

        start = 0;
        end = 4;

    } else {

        start = 4 * clickTimes;
        end = 4;

    }

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Album.getUserAlbums");
    query.setLong("userId", userId);
    query.setFirstResult(start);
    query.setMaxResults(end);
    return (ArrayList) query.list();

}

From source file:com.slambook.repository.implementation.AlbumDAOImpl.java

@Override
public ArrayList getAllAlbums(long userId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Album.getAllAlbumName");
    query.setLong("userId", userId);
    return (ArrayList) query.list();

}

From source file:com.slambook.repository.implementation.AlbumDAOImpl.java

@Override
public String getAlbumName(long albumId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Album.getAlbumName");
    query.setLong("albumId", albumId);
    String albumName = (String) query.uniqueResult();
    return albumName;

}

From source file:com.slambook.repository.implementation.AnswersDAOImpl.java

@Override
public Answers getAnswer(long questionId, long friendId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Answers.getAnswer");
    query.setLong("questionId", questionId);
    query.setLong("friendId", friendId);

    return (Answers) query.list().get(0);

}

From source file:com.slambook.repository.implementation.FriendsDAOImpl.java

@Override
public ArrayList getUserFriends(long userId) {

    Query query = sessionFactory.getCurrentSession().getNamedQuery("Friends.getUserFriends");
    query.setLong("userId", userId);
    query.setBoolean("allow", true);
    return (ArrayList) query.list();
}

From source file:com.slambook.repository.implementation.FriendsDAOImpl.java

@Override
public boolean isAlreadyAFriend(long friendId, long userId) {

    boolean status = false;
    Query query = sessionFactory.getCurrentSession().getNamedQuery("Friends.isAlreadyAFriend");
    query.setLong("userId", userId);
    query.setLong("senderId", friendId);

    if (!query.list().isEmpty()) {

        status = true;/*from   w  w w  .  ja va2s .c  o  m*/

    }

    return status;
}