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.PhotoDAO.java

License:Open Source License

/**
 * /*w ww . ja  v a  2s . c  o  m*/
 * 
 * @param album
 * @param fromIdx
 * @param count
 * @return
 */
public static List listPhotos(AlbumBean album, int fromIdx, int count) {
    Query q = getSession().getNamedQuery("PHOTOS_OF_ALBUM");
    q.setInteger("album", album.getId());
    // q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE);
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (count > 0)
        q.setMaxResults(count);
    return q.list();
}

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

License:Open Source License

/**
 * //from ww w .ja  v a  2 s .  c  o  m
 * 
 * @param site
 * @param user
 * @param album_id
 * @param month_stamp
 *            ,20050620056
 * @param fromIdx
 * @param count
 * @return
 * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#list_photos(SiteBean,
 *      int, int)
 */
public static List listPhotos(int album_id, int month_stamp, int date, int fromIdx, int count) {
    StringBuffer hql = new StringBuffer("FROM PhotoOutlineBean AS p WHERE 1=1");
    if (album_id > 0)
        hql.append(" AND (p.album.id=:album OR p.album.parent.id=:album)");
    else {
        // hql.append(" AND (TO_DAYS(NOW()) - TO_DAYS(p.site.createTime) >
        // 2)");
    }
    if (month_stamp > 190000 && month_stamp < 209912) {
        hql.append(" AND p.year=:year AND p.month=:month");
    }
    hql.append(" AND p.status<>:hidden_status AND p.album.type=:owner_album");
    if (date > 0) {
        hql.append(" AND p.date=:date");
    }
    hql.append(" AND p.site.status=:site_status ORDER BY p.id DESC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setCacheable(true).setCacheRegion("query.new_photos");
        if (album_id > 0)
            q.setInteger("album", album_id);
        if (month_stamp > 190000 && month_stamp < 209912) {
            q.setInteger("year", month_stamp / 100);
            q.setInteger("month", month_stamp % 100);
        }
        q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE);
        q.setInteger("owner_album", AlbumBean.TYPE_PUBLIC);
        if (date > 0) {
            q.setInteger("date", date);
        }
        q.setInteger("site_status", SiteBean.STATUS_NORMAL);
        q.setFirstResult(fromIdx);
        q.setMaxResults(count);
        return q.list();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * //from ww  w  .j  ava 2s  .  com
 * 
 * @param site
 * @param user
 * @param album_id
 * @param month_stamp
 *            ,20050620056
 * @return
 * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#list_photos(SiteBean,
 *      int, int)
 */
public static int getPhotoCount(SiteBean site, SessionUserObject user, int album_id, int month_stamp,
        int date) {
    boolean is_owner = site.isOwner(user);
    StringBuffer hql = new StringBuffer("SELECT COUNT(*) FROM PhotoBean AS p WHERE p.site.id=:site");
    if (album_id > 0)
        hql.append(" AND p.album.id=:album");
    if (month_stamp > 190000 && month_stamp < 209912) {
        hql.append(" AND p.year=:year AND p.month=:month");
    }
    if (!is_owner) {
        hql.append(" AND p.status=:normal_status AND p.album.type=:public_album");
    }
    if (date > 0) {
        hql.append(" AND p.date=:date");
    }
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("site", site.getId());
        if (album_id > 0)
            q.setInteger("album", album_id);
        if (month_stamp > 190000 && month_stamp < 209912) {
            q.setInteger("year", month_stamp / 100);
            q.setInteger("month", month_stamp % 100);
        }
        if (!is_owner) {
            q.setInteger("normal_status", PhotoBean.STATUS_NORMAL);
            q.setInteger("public_album", AlbumBean.TYPE_PUBLIC);
        }
        if (date > 0) {
            q.setInteger("date", date);
        }
        return ((Number) q.uniqueResult()).intValue();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * /*from  w  w w.j  ava2  s .c  om*/
 * 
 * @param sid
 * @param album_id
 * @return
 */
public static int getTotalPhotoSize(int sid, int album_id) {
    if (sid < 1)
        return -1;
    StringBuffer hql = new StringBuffer("SELECT SUM(p.photoInfo.size) FROM PhotoBean AS p WHERE p.site.id=?");
    if (album_id > 0)
        hql.append(" AND p.album.id=?");
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger(0, sid);
    if (album_id > 0)
        q.setInteger(1, album_id);
    try {
        Number size = (Number) q.uniqueResult();
        return (size != null) ? size.intValue() : 0;
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * /*from   w w  w . ja  v  a  2 s .  co m*/
 * 
 * @param sid
 * @param album_id
 * @return
 */
public static int getTotalPhotoCount(int sid, int album_id, int month) {
    if (sid < 1)
        return -1;
    StringBuffer hql = new StringBuffer("SELECT COUNT(*) FROM PhotoBean AS p WHERE p.site.id=:site");
    if (album_id > 0)
        hql.append(" AND p.album.id=:album");
    if (month >= 190001 && month <= 209912) {
        hql.append(" AND p.year = :year AND p.month = :month");
    }
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger("site", sid);
    if (album_id > 0)
        q.setInteger("album", album_id);
    if (month >= 190001 && month <= 209912) {
        q.setInteger("year", month / 100);
        q.setInteger("month", month % 100);
    }
    try {
        Number size = (Number) q.uniqueResult();
        return (size != null) ? size.intValue() : 0;
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 *  FIXME: photo/show.vm// w  w w.  j av  a 2  s  .co m
 * 
 * @param site
 * @param loginUser
 * @param month
 * @return
 */
public static int[] statCalendarPhotoCount(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];

    // 
    boolean is_owner = site.isOwner(user);
    StringBuffer hql = new StringBuffer(
            "SELECT j.createTime FROM PhotoBean AS j WHERE j.createTime>=:beginTime AND j.createTime<:endTime AND j.site.id=:site");
    if (!is_owner) {
        // 
        hql.append(" AND j.status=:status AND j.album.type=:album_type");
    }

    try {
        Session ssn = getSession();
        Query q = ssn.createQuery(hql.toString());
        q.setCacheable(true);
        q.setCacheRegion("query.photo_calendar");
        q.setTimestamp("beginTime", firstDate.getTime());
        q.setTimestamp("endTime", nextMonthFirstDate.getTime());
        q.setInteger("site", site.getId());
        if (!is_owner) {
            q.setInteger("status", PhotoBean.STATUS_NORMAL);
            q.setInteger("album_type", AlbumBean.TYPE_PUBLIC);
        }
        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.PhotoDAO.java

License:Open Source License

/**
 * /*from  w w w. j  av a2 s . c  o m*/
 * 
 * @param site
 * @param user
 * @param fromIdx
 * @param count
 * @return
 */
public static List listPhotoReplies(SiteBean site, int fromIdx, int count, SessionUserObject user) {
    boolean is_owner = site.isOwner(user);
    StringBuffer hql = new StringBuffer(
            "FROM PhotoReplyBean AS r WHERE r.status=:status AND r.site.id=:site AND r.photo.status=:photo_status");
    if (!is_owner) {
        // 
        hql.append(" AND r.photo.album.type=:album_type");
        hql.append(" AND (r.ownerOnly = 0 OR r.user.id=:userid)");
    }
    hql.append(" ORDER BY r.id DESC");
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setCacheable(true).setCacheRegion("query.new_replies_of_site");
    q.setInteger("status", PhotoReplyBean.STATUS_NORMAL);
    q.setInteger("photo_status", PhotoBean.STATUS_NORMAL);
    q.setInteger("site", site.getId());
    if (!is_owner) {
        q.setInteger("album_type", AlbumBean.TYPE_PUBLIC);
        q.setInteger("userid", (user != null) ? user.getId() : -1);
    }
    if (fromIdx > 0)
        q.setFirstResult(fromIdx);
    if (count > 0)
        q.setMaxResults(count);
    return q.list();
}

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

License:Open Source License

/**
 * // w  w  w .  jav  a  2 s  .  c  om
 * 
 * @param site
 * @param fromIdx
 * @param count
 * @return
 */
public static List listTags(SiteBean site, int fromIdx, int count) {
    StringBuffer hql = new StringBuffer("SELECT t.name,COUNT(*) FROM TagBean t");
    if (site != null)
        hql.append(" WHERE t.site.id = ?");
    hql.append(" GROUP BY t.name ORDER BY 2 DESC");
    Query query = getSession().createQuery(hql.toString());
    query.setCacheable(true);
    query.setCacheRegion(CACHE_KEY);
    if (site != null)
        query.setInteger(0, site.getId());
    if (fromIdx > 0)
        query.setFirstResult(fromIdx);
    if (count > 0)
        query.setMaxResults(count);
    List<String> tags = new ArrayList<String>();
    List results = query.list();
    for (int i = 0; results != null && i < results.size(); i++) {
        tags.add((String) ((Object[]) results.get(i))[0]);
    }
    return tags;
}

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

License:Open Source License

/**
 * //  w  ww . ja  v a2s. c om
 * @param ownerId
 * @param friendId
 */
public static int deleteFriend(int ownerId, String[] friendIds) {
    if (friendIds == null || friendIds.length == 0)
        return 0;
    StringBuffer hql = new StringBuffer("DELETE FROM FriendBean f WHERE f.owner=? AND f.friend.id IN (");
    for (int i = 0; i < friendIds.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 < friendIds.length; i++) {
            String s_id = (String) friendIds[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;
    }
}

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

License:Open Source License

/**
 * //from   w  w  w .ja  v  a  2  s  . co  m
 * @param ownerId
 * @param friendId
 */
public static int deleteBlacklist(int ownerId, String[] otherIds) {
    if (otherIds == null || otherIds.length == 0)
        return 0;
    StringBuffer hql = new StringBuffer("DELETE FROM MyBlackListBean f WHERE f.myId=? AND f.other.id IN (");
    for (int i = 0; i < otherIds.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 < otherIds.length; i++) {
            String s_id = (String) otherIds[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;
    }
}