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.levinas.ecole.dao.UserDaoImpl.java

@Override
public HashMap listAll() {
    Session session = sessionFactory.getCurrentSession();
    HashMap result = new HashMap();
    Query query = session.getNamedQuery("TypeResponsable.findAll");
    double nbResult = query.list().size();
    List listItems = query.list();

    result.put("items", listItems);
    //result.put("page_count", Math.ceil(nbResult/iRpp.doubleValue()));
    result.put("total_items", nbResult);
    return result;
}

From source file:com.levinas.ecole.dao.UserDaoImpl.java

@Override
public User findByIdUser(int idUser) {
    Session session = sessionFactory.getCurrentSession();
    Query query = session.getNamedQuery("User.findByIdUser");
    query.setParameter("idUser", idUser);
    return (User) query.uniqueResult();
}

From source file:com.liusoft.dlog4j.dao.BBSForumDAO.java

License:Open Source License

/**
 * //w w w .j  a  va2s . c o  m
 * 
 * @param obj
 * @param pos
 * @param up
 * @throws CapacityExceedException
 */
public static void createForum(ForumBean obj, int pos, boolean up) throws CapacityExceedException {
    Session ssn = getSession();
    int order_value = 1;
    if (pos > 0) {
        ForumBean friend = (ForumBean) ssn.get(ForumBean.class, new Integer(pos));
        order_value = friend.getSortOrder();
    }
    obj.setSortOrder(order_value - (up ? 1 : 0));
    try {
        beginTransaction();
        ssn.save(obj);
        // 
        Query q = ssn.getNamedQuery("LIST_FORUMS");
        q.setInteger(0, obj.getSite().getId());
        List links = q.list();
        if (links.size() >= ConfigDAO.getMaxCatalogCount(obj.getSite().getId()))
            throw new CapacityExceedException(links.size());
        if (links.size() > 1) {
            for (int i = 0; i < links.size(); i++) {
                Orderable lb = (Orderable) links.get(i);
                executeNamedUpdate("UPDATE_FORUM_ORDER", i + 1, lb.getId());
            }
        }
        commit();
    } catch (HibernateException e) {
        rollback();
        throw e;
    }
}

From source file:com.liusoft.dlog4j.dao.DAO.java

License:Open Source License

/**
 * /*w  ww .j  a v  a  2 s  .  c  om*/
 * @param hql
 * @param args
 * @return
 */
protected static List executeNamedQuery(String hql, int fromIdx, int fetchCount, Object... args) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql).setReadOnly(true);
    for (int i = 0; i < args.length; i++) {
        q.setParameter(i, args[i]);
    }
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (fetchCount > 0)
        q.setMaxResults(fetchCount);
    return q.list();
}

From source file:com.liusoft.dlog4j.dao.DAO.java

License:Open Source License

/**
 * ()/*from  w w w . j  a va  2  s.com*/
 * @param hql
 * @param args
 * @return
 */
protected static List executeNamedQueryCacheable(String cache_region, String hql, int fromIdx, int fetchCount,
        Object... args) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql).setReadOnly(true).setCacheable(true);
    if (cache_region != null)
        q.setCacheRegion(cache_region);
    for (int i = 0; i < args.length; i++) {
        q.setParameter(i, args[i]);
    }
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (fetchCount > 0)
        q.setMaxResults(fetchCount);
    return q.list();
}

From source file:com.liusoft.dlog4j.dao.DAO.java

License:Open Source License

/**
 * /*from   w w w.  j  a v a 2s. co m*/
 * @param hql
 * @param args
 * @return
 */
protected static Object namedUniqueResult(String hql, Object... args) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql).setReadOnly(true);
    for (int i = 0; i < args.length; i++) {
        q.setParameter(i, args[i]);
    }
    q.setMaxResults(1);
    return q.uniqueResult();
}

From source file:com.liusoft.dlog4j.dao.DAO.java

License:Open Source License

/**
 * /* w ww.  jav a  2  s.  c  o  m*/
 * <b></b>
 * @param hql
 * @param args
 * @return
 */
protected static Object namedUniqueResultCacheable(String cache_region, String hql, Object... args) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql).setReadOnly(true).setCacheable(true);
    if (cache_region != null)
        q.setCacheRegion(cache_region);
    for (int i = 0; i < args.length; i++) {
        q.setParameter(i, args[i]);
    }
    //q.setMaxResults(1);
    return q.uniqueResult();
}

From source file:com.liusoft.dlog4j.dao.DAO.java

License:Open Source License

/**
 * /*w  ww  .j  a  va 2  s  .com*/
 * @param hql
 * @param args
 * @return
 */
protected static int executeNamedUpdate(String hql, Object... args) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql);
    for (int i = 0; i < args.length; i++) {
        q.setParameter(i, args[i]);
    }
    return q.executeUpdate();
}

From source file:com.liusoft.dlog4j.dao.DiaryDAO.java

License:Open Source License

/**
 * /*from w  ww.j  av  a  2s.c om*/
 * 
 * @param catalog_id
 * @param incCount
 * @return
 * @throws SQLException
 */
static int incTrackBackCount(Session ssn, int log_id, int incCount) {
    Query q = ssn.getNamedQuery("INC_DIARY_TB_COUNT");
    q.setInteger(0, incCount);
    q.setInteger(1, log_id);
    return q.executeUpdate();
}

From source file:com.liusoft.dlog4j.dao.SiteDAO.java

License:Open Source License

/**
 * /*from   w  w w  . j  ava  2  s .c  om*/
 * 
 * @param fromIdx
 * @param count
 * @return
 */
protected static List listSitesOrderBy(int fromIdx, int count, String hql) {
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql);
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (count > 0)
        q.setMaxResults(count);
    List objs = q.list();
    List<SiteBean> sites = new ArrayList<SiteBean>();
    for (int i = 0; i < objs.size(); i++) {
        Object[] res = (Object[]) objs.get(i);
        int siteid = ((Number) res[0]).intValue();
        SiteBean site = new SiteBean(siteid);
        site.setUniqueName((String) res[1]);
        site.setFriendlyName((String) res[2]);
        sites.add(site);
    }
    return sites;
}