Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

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

Prototype

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

Source Link

Document

Bind a named int-valued parameter.

Usage

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

License:Open Source License

/**
 * //from www .j a v  a2s. c  om
 * @param site
 * @param fbean
 * @param fromIdx
 * @param count
 * @return
 */
public static List listEliteTopics(SiteBean site, ForumBean fbean, int fromIdx, int count) {
    StringBuffer hql = new StringBuffer("FROM TopicOutlineBean AS t WHERE t.status=:status");
    if (site != null)
        hql.append(" AND t.site.id=:site");
    if (fbean != null)
        hql.append(" AND t.forum.id=:forum");
    hql.append(" AND (t.type=:elite OR t.type=:top_elite) ORDER BY ROUND(t.type / 16, 0) DESC, t.id DESC");
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger("status", TopicBean.STATUS_NORMAL);
    q.setInteger("elite", TopicBean.INFO_TYPE_ELITE);
    q.setInteger("top_elite", TopicBean.INFO_TYPE_TOP_ELITE);
    if (site != null)
        q.setInteger("site", site.getId());
    if (fbean != null)
        q.setInteger("forum", fbean.getId());
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (count > 0)
        q.setMaxResults(count);
    return q.list();
}

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

License:Open Source License

/**
 * //from w  ww  .java2s .  c  om
 * 
 * @param forum_id
 * @param fromIdx
 * @param count
 * @return
 */
public static List listHotTopics(SiteBean site, ForumBean forum, int fromIdx, int count, int days) {
    StringBuffer hql = new StringBuffer(
            "FROM TopicOutlineBean AS t WHERE t.site.id=? AND t.status=? AND t.createTime >= ? AND t.replyCount > 0");
    if (forum != null)
        hql.append(" AND t.forum.id=?");
    hql.append(" ORDER BY ROUND(t.type / 16, 0) DESC, t.replyCount DESC, t.id DESC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger(0, site.getId());
        q.setInteger(1, TopicOutlineBean.STATUS_NORMAL);
        Calendar cur_time = Calendar.getInstance();
        cur_time.add(Calendar.DATE, -days);
        q.setTimestamp(2, new Timestamp(cur_time.getTime().getTime()));
        if (forum != null)
            q.setInteger(3, forum.getId());
        if (fromIdx > 0)
            q.setFirstResult(fromIdx);
        q.setMaxResults(count);
        return q.list();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * /*from  w ww . j  a v a  2  s.c  om*/
 * @param ownerId
 * @param bookmarkIds
 */
public static int deleteBookmarks(int ownerId, String[] bookmarkIds) {
    if (bookmarkIds == null || bookmarkIds.length == 0)
        return 0;
    StringBuffer hql = new StringBuffer("DELETE FROM BookmarkBean AS f WHERE f.owner=? AND f.id IN (");
    for (int i = 0; i < bookmarkIds.length; i++) {
        hql.append("?,");
    }
    hql.append("?)");
    Session ssn = getSession();
    try {
        beginTransaction();
        Query q = ssn.createQuery(hql.toString());
        q.setInteger(0, ownerId);
        int i = 0;
        for (; i < bookmarkIds.length; i++) {
            String s_id = (String) bookmarkIds[i];
            int id = -1;
            try {
                id = Integer.parseInt(s_id);
            } catch (Exception e) {
            }
            q.setInteger(i + 1, id);
        }
        q.setInteger(i + 1, -1);
        int er = q.executeUpdate();
        commit();
        return er;
    } catch (HibernateException e) {
        rollback();
        throw e;
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 *  (session)//from   w  ww .  j  a  v a  2 s .c o m
 * 
 * @param site
 * @param user_id
 * @param maintain
 *            
 * @return
 * @throws HibernateException
 */
@SuppressWarnings("unchecked")
public static List listCatalogs(SiteBean site, SessionUserObject user, boolean maintain) {
    List<CatalogBean> catalogs = findNamedAll("LIST_CATALOGS", site.getId());
    if (user == null || user.getOwnSiteId() != site.getId()) {
        List perms = null;
        if (user != null) {
            Query q = getSession().getNamedQuery("USER_PERMS");
            q.setInteger(0, user.getId());
            perms = q.list();
        }
        Iterator iter = catalogs.iterator();
        while (iter.hasNext()) {
            CatalogBean catalog = (CatalogBean) iter.next();
            // 
            if (catalog.getType() == CatalogBean.TYPE_FREE)
                continue;
            int role = getUserRoleInCatalog(perms, catalog, user);
            if (!maintain) {// 
                if (catalog.getType() != CatalogBean.TYPE_GENERAL) {
                    if (role < 0)
                        iter.remove();
                }
            } else {// 
                if (role != CatalogPermBean.ROLE_BLOG)
                    iter.remove();
            }
        }
    }
    return catalogs;
}

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

License:Open Source License

/**
 * /*from   www  .  jav  a  2s . c  om*/
 * 
 * @param site
 * @param loginUser
 * @param month
 * @return
 */
public static int[] statCalendarLogs(SiteBean site, SessionUserObject user, Calendar month) {
    Calendar firstDate = (Calendar) month.clone();
    firstDate.set(Calendar.DATE, 1);
    DateUtils.resetTime(firstDate);
    Calendar nextMonthFirstDate = (Calendar) firstDate.clone();
    nextMonthFirstDate.add(Calendar.MONTH, 1);

    // 
    Calendar tempCal = (Calendar) nextMonthFirstDate.clone();
    tempCal.add(Calendar.DATE, -1);
    int dateCount = tempCal.get(Calendar.DATE);
    int[] logCounts = new int[dateCount + 1];

    // 

    StringBuffer hql = new StringBuffer(
            "SELECT j.writeTime FROM DiaryBean AS j WHERE j.writeTime>=:beginTime AND j.writeTime<:endTime AND j.status=:status AND j.site.id=:site");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (j.catalog.type<>:cat_type");
        if (user != null)
            hql.append(
                    " OR (j.catalog.type=:cat_type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
        hql.append(')');
    }

    Session ssn = getSession();

    try {
        Query q = ssn.createQuery(hql.toString()).setCacheable(true);
        q.setTimestamp("beginTime", firstDate.getTime());
        q.setTimestamp("endTime", nextMonthFirstDate.getTime());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("site", site.getId());
        if (!site.isOwner(user)) {
            q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
            if (user != null)
                q.setInteger("user", user.getId());
        }
        q.setCacheable(true).setCacheRegion("query.diary_calendar");
        int total = 0;
        Iterator logs = q.list().iterator();
        while (logs.hasNext()) {
            tempCal.setTime((Date) logs.next());
            int date = tempCal.get(Calendar.DATE);
            logCounts[date]++;
            total++;
        }

        logCounts[0] = total;

        return logCounts;
    } finally {
        hql = null;
        firstDate = null;
        nextMonthFirstDate = null;
        tempCal = null;
    }
}

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

License:Open Source License

/**
 * ()/*from  w w  w .jav a2 s.c o m*/
 * 
 * @param site
 * @param user
 * @param cat_id
 * @param log_id
 * @return
 */
public static DiaryOutlineBean getPrevDiary(SiteBean site, SessionUserObject user, int cat_id, int log_id) {
    if (site == null)
        return null;
    StringBuffer hql = new StringBuffer(
            "FROM DiaryOutlineBean AS j WHERE j.site.id=:site AND j.status=:status AND j.id<:diary");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (j.catalog.type<>:type");
        if (user != null)
            hql.append(
                    " OR (j.catalog.type=:type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
        hql.append(')');
    }
    if (cat_id > 0) {
        hql.append(" AND j.catalog.id=:catalog");
    }
    hql.append(" ORDER BY j.id DESC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("site", site.getId());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("diary", log_id);
        if (cat_id > 0)
            q.setInteger("catalog", cat_id);
        if (!site.isOwner(user)) {
            q.setInteger("type", CatalogBean.TYPE_OWNER);
            if (user != null)
                q.setInteger("user", user.getId());
        }
        q.setMaxResults(1);
        return (DiaryOutlineBean) q.uniqueResult();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * ()/*from w ww  .ja v  a  2s  . c  om*/
 * 
 * @param site
 * @param user
 * @param cat_id
 * @param log_id
 * @return
 */
public static DiaryOutlineBean getNextDiary(SiteBean site, SessionUserObject user, int cat_id, int log_id) {
    if (site == null)
        return null;
    StringBuffer hql = new StringBuffer(
            "FROM DiaryOutlineBean AS j WHERE j.site.id=:site AND j.status=:status AND j.id>:diary");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (j.catalog.type<>:type");
        if (user != null)
            hql.append(
                    " OR (j.catalog.type=:type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
        hql.append(')');
    }
    if (cat_id > 0) {
        hql.append(" AND j.catalog.id=:catalog");
    }
    hql.append(" ORDER BY j.id ASC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("site", site.getId());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("diary", log_id);
        if (cat_id > 0)
            q.setInteger("catalog", cat_id);
        if (!site.isOwner(user)) {
            q.setInteger("type", CatalogBean.TYPE_OWNER);
            if (user != null)
                q.setInteger("user", user.getId());
        }
        q.setMaxResults(1);
        return (DiaryOutlineBean) q.uniqueResult();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * //from ww  w .ja  v a2s  .c om
 * 
 * @param site
 * @param user
 * @param catalog_id
 * @param year
 * @param month
 * @param date
 * @return
 */
public static int getDiaryCount(SiteBean site, SessionUserObject user, int catalog_id, int year, int month,
        int date) {
    StringBuffer hql = new StringBuffer(
            "SELECT COUNT(*) FROM DiaryBean AS a WHERE a.status=:status AND a.site.id=:site");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (a.catalog.type<>:cat_type");
        if (user != null)
            hql.append(
                    " OR (a.catalog.type=:cat_type AND a.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
        hql.append(')');
    }
    if (catalog_id > 0)
        hql.append(" AND a.catalog.id=:catalog");
    if (year > 0 || month > 0 || date > 0) {
        hql.append(" AND a.writeTime >= :beginTime AND a.writeTime < :endTime");
    }
    try {
        Session ssn = getSession();
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("site", site.getId());
        if (!site.isOwner(user)) {
            q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
            if (user != null) {
                q.setInteger("user", user.getId());
            }
        }
        if (catalog_id > 0) {
            q.setInteger("catalog", catalog_id);
        }
        if (year > 0 || month > 0 || date > 0) {
            Calendar[] cals = genTimeParams(year, month, date);
            q.setTimestamp("beginTime", cals[0].getTime());
            q.setTimestamp("endTime", cals[1].getTime());
        }
        return ((Number) q.uniqueResult()).intValue();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * // w  ww  .  ja  v  a 2s . co m
 * 
 * @param site
 * @param user
 * @param catalog_id
 * @param year
 * @param month
 * @param date
 * @param fromIdx
 * @param count
 * @return
 */
public static List listDiary(int year, int month, int date, int fromIdx, int count, boolean withContent) {
    StringBuffer hql = new StringBuffer("FROM ");
    hql.append(withContent ? "DiaryBean" : "DiaryOutlineBean");
    hql.append(" AS a WHERE a.status=:status");
    // 
    hql.append(" AND (a.catalog.type<>:cat_type)");
    if (year > 0 || month > 0 || date > 0) {
        hql.append(" AND a.writeTime >= :beginTime AND a.writeTime < :endTime");
    }
    hql.append(" ORDER BY a.id DESC");
    try {
        Session ssn = getSession();
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
        if (year > 0 || month > 0 || date > 0) {
            Calendar[] cals = genTimeParams(year, month, date);
            q.setTimestamp("beginTime", cals[0].getTime());
            q.setTimestamp("endTime", cals[1].getTime());
        }
        if (fromIdx > 0)
            q.setFirstResult(fromIdx);
        if (count > 0)
            q.setMaxResults(count);
        return q.list();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * //from w ww .  java  2s . com
 * 
 * @param site
 * @param user
 * @param catalog_id
 * @param year
 * @param month
 * @param date
 * @param fromIdx
 * @param count
 * @return
 */
public static List listDiary(SiteBean site, SessionUserObject user, int catalog_id, int year, int month,
        int date, int fromIdx, int count, boolean withContent) {
    StringBuffer hql = new StringBuffer("FROM ");
    hql.append(withContent ? "DiaryBean" : "DiaryOutlineBean");
    hql.append(" AS a WHERE a.status=:status AND a.site.id=:site");
    // (2006-5-22 by Winter Lau)
    if (user == null || site.getOwner().getId() != user.getId()) {
        // 
        hql.append(" AND (a.catalog.type<>:cat_type");
        if (user != null)
            hql.append(
                    " OR (a.catalog.type=:cat_type AND a.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
        hql.append(')');
    }
    if (catalog_id > 0)
        hql.append(" AND a.catalog.id=:catalog");
    if (year > 0 || month > 0 || date > 0) {
        hql.append(" AND a.writeTime >= :beginTime AND a.writeTime < :endTime");
    }
    hql.append(" ORDER BY a.id DESC");
    try {
        Session ssn = getSession();
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("status", DiaryBean.STATUS_NORMAL);
        q.setInteger("site", site.getId());
        if (user == null || site.getOwner().getId() != user.getId()) {
            q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
            if (user != null) {
                q.setInteger("user", user.getId());
            }
        }
        if (catalog_id > 0) {
            q.setInteger("catalog", catalog_id);
        }
        if (year > 0 || month > 0 || date > 0) {
            Calendar[] cals = genTimeParams(year, month, date);
            q.setTimestamp("beginTime", cals[0].getTime());
            q.setTimestamp("endTime", cals[1].getTime());
        }
        if (fromIdx > 0)
            q.setFirstResult(fromIdx);
        if (count > 0)
            q.setMaxResults(count);
        return q.list();
    } finally {
        hql = null;
    }
}