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

License:Open Source License

/**
 * //from w  w  w  .  j  a  v a  2  s  . com
 * 
 * @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.DiaryDAO.java

License:Open Source License

/**
 * /*from   ww w . j a va 2s  . c o  m*/
 * 
 * @param site
 * @param user
 * @param fromIdx
 * @param count
 * @return
 */
public static List listDiaryReplies(SiteBean site, int fromIdx, int count, SessionUserObject user) {
    StringBuffer hql = new StringBuffer(
            "FROM DiaryReplyBean AS r WHERE r.status=:status AND r.site.id=:site AND r.diary.status=:diary_status");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (r.diary.catalog.type<>:cat_type");
        if (user != null)
            hql.append(
                    " OR (r.diary.catalog.type=:cat_type AND r.diary.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:userid))");
        hql.append(')');
        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.setInteger("status", DiaryReplyBean.STATUS_NORMAL);
    q.setInteger("site", site.getId());
    q.setInteger("diary_status", DiaryOutlineBean.STATUS_NORMAL);
    if (!site.isOwner(user)) {
        q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
        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.DiaryDAO.java

License:Open Source License

/**
 * (j_replies.vm)//from www. j  a  v  a  2s . com
 * 
 * @param site
 * @param user
 * @return
 */
public static int getDiaryReplyCount(SiteBean site, SessionUserObject user) {
    StringBuffer hql = new StringBuffer(
            "SELECT COUNT(*) FROM DiaryReplyBean AS r WHERE r.status=? AND r.site.id=?");
    if (!site.isOwner(user)) {
        // 
        hql.append(" AND (r.diary.catalog.type<>?");
        if (user != null)
            hql.append(
                    " OR (r.diary.catalog.type=? AND r.diary.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=?))");
        hql.append(')');
    }
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger(0, DiaryReplyBean.STATUS_NORMAL);
    q.setInteger(1, site.getId());
    if (!site.isOwner(user)) {
        q.setInteger(2, CatalogBean.TYPE_OWNER);
        if (user != null) {
            q.setInteger(3, CatalogBean.TYPE_OWNER);
            q.setInteger(4, user.getId());
        }
    }
    return ((Number) q.uniqueResult()).intValue();
}

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

License:Open Source License

/**
 * //from w w w.  j  av  a  2s.c o  m
 * 
 * @param ownerId
 * @param friendId
 */
public static int deleteMsgs(int ownerId, String[] msgIds) {
    if (msgIds == null || msgIds.length == 0)
        return 0;
    // 
    int max_msg_count = Math.min(msgIds.length, 50);
    StringBuffer hql = new StringBuffer("DELETE FROM MessageBean AS f WHERE f.toUser.id=? AND f.id IN (");
    for (int i = 0; i < max_msg_count; 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 < max_msg_count; i++) {
            String s_id = (String) msgIds[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.MusicDAO.java

License:Open Source License

/**
 * //  www.  java 2 s .co  m
 * @param music_id
 * @param incCount
 * @return
 */
public static int incViewCount(int incCount, int[] music_ids) {
    StringBuffer hql = new StringBuffer("UPDATE MusicBean d SET d.viewCount=d.viewCount+? WHERE d.id IN (");
    for (int i = 0; i < music_ids.length; i++) {
        if (i > 0)
            hql.append(',');
        hql.append('?');
    }
    hql.append(')');
    try {
        Session ssn = getSession();
        beginTransaction();
        Query q = ssn.createQuery(hql.toString());
        q.setInteger(0, incCount);
        for (int i = 1; i <= music_ids.length; i++) {
            q.setParameter(i, music_ids[i - 1]);
        }
        int er = q.executeUpdate();
        commit();
        return er;
    } catch (HibernateException e) {
        rollback();
        throw e;
    }
}

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

License:Open Source License

/**
 * /*from   ww  w .j a v  a 2 s. co m*/
 * @param ids
 * @return
 */
public static List listSongs(List ids) {
    Session ssn = getSession();
    StringBuffer hql = new StringBuffer("FROM MusicBean m WHERE m.id IN (");
    int i = 0;
    for (; i < ids.size(); i++) {
        hql.append("?,");
    }
    hql.append("?) ORDER BY m.id DESC");
    Query q = ssn.createQuery(hql.toString());
    for (i = 0; i < ids.size(); i++) {
        int id = ((Number) ids.get(i)).intValue();
        q.setInteger(i, id);
    }
    q.setInteger(i, -1);
    return q.list();
}

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

License:Open Source License

/**
 * //from w ww  . j  a va2  s. co  m
 * @param mbean
 */
public static void deleteMusics(int siteid, int[] ids) {
    Session ssn = getSession();
    try {
        StringBuffer hql = new StringBuffer("FROM MusicBean m WHERE m.site.id=? AND m.id IN (");
        StringBuffer hql2 = new StringBuffer("UPDATE DiaryBean d SET d.bgSound=? WHERE d.bgSound.id IN (");
        int i = 0;
        for (; i < ids.length; i++) {
            hql.append("?,");
            hql2.append("?,");
        }
        hql.append("?)");
        hql2.append("?)");
        Query q = ssn.createQuery(hql.toString());
        q.setInteger(0, siteid);
        i = 0;
        for (; i < ids.length; i++) {
            q.setInteger(i + 1, ids[i]);
        }
        q.setInteger(i + 1, ids[0]);
        List musics = q.list();
        if (musics.size() > 0) {
            beginTransaction();
            //
            Query q2 = ssn.createQuery(hql2.toString());
            i = 0;
            q2.setParameter(0, null);
            for (; i < ids.length; i++) {
                q2.setInteger(i + 1, ids[i]);
            }
            q2.setInteger(i + 1, ids[0]);
            q2.executeUpdate();
            //
            for (i = 0; i < musics.size(); i++) {
                MusicBean mbean = (MusicBean) musics.get(i);
                if (mbean.getMusicBox() != null)
                    mbean.getMusicBox().incMusicCount(-1);
                ssn.delete(mbean);
            }
            commit();
        }
    } catch (HibernateException e) {
        rollback();
        throw e;
    }
}

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

License:Open Source License

/**
 * ()/*w  ww. j  a  v  a2s  .  co m*/
 * 
 * @param site
 * @param user
 * @param album_id
 * @param photo_id
 * @return
 */
public static PhotoOutlineBean getPrevPhoto(SiteBean site, SessionUserObject user, int album_id, int photo_id) {
    if (site == null)
        return null;
    boolean is_owner = site.isOwner(user);
    StringBuffer hql = new StringBuffer(
            "FROM PhotoOutlineBean AS p WHERE p.status=:photo_status AND p.site.id=:site AND p.id<:photo");
    if (!is_owner) {
        // 
        hql.append(" AND p.album.type=:album_type");
    }
    if (album_id > 0) {
        hql.append(" AND p.album.id=:album");
    }
    hql.append(" ORDER BY p.id DESC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("photo_status", PhotoBean.STATUS_NORMAL);
        q.setInteger("site", site.getId());
        q.setInteger("photo", photo_id);
        if (album_id > 0)
            q.setInteger("album", album_id);
        if (!is_owner)
            q.setInteger("album_type", AlbumBean.TYPE_PUBLIC);
        q.setMaxResults(1);
        return (PhotoOutlineBean) q.uniqueResult();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * ()/* w w  w .j  a  v  a2  s  . c  o m*/
 * 
 * @param site
 * @param user
 * @param album_id
 * @param photo_id
 * @return
 */
public static PhotoOutlineBean getNextPhoto(SiteBean site, SessionUserObject user, int album_id, int photo_id) {
    if (site == null)
        return null;
    StringBuffer hql = new StringBuffer(
            "FROM PhotoOutlineBean AS p WHERE p.status=:photo_status AND p.site.id=:site AND p.id>:photo");
    if (user == null || !site.isOwner(user)) {
        // 
        hql.append(" AND p.album.type=:album_type");
    }
    if (album_id > 0) {
        hql.append(" AND p.album.id=:album");
    }
    hql.append(" ORDER BY p.id ASC");
    Session ssn = getSession();
    try {
        Query q = ssn.createQuery(hql.toString());
        q.setInteger("photo_status", PhotoBean.STATUS_NORMAL);
        q.setInteger("site", site.getId());
        q.setInteger("photo", photo_id);
        if (album_id > 0)
            q.setInteger("album", album_id);
        if (!site.isOwner(user))
            q.setInteger("album_type", AlbumBean.TYPE_PUBLIC);
        q.setMaxResults(1);
        return (PhotoOutlineBean) q.uniqueResult();
    } finally {
        hql = null;
    }
}

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

License:Open Source License

/**
 * //from  ww w .ja  v a2  s .co  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(SiteBean site, SessionUserObject user, int album_id, int month_stamp, int date,
        int fromIdx, int count) {
    StringBuffer hql = new StringBuffer("FROM PhotoOutlineBean AS p WHERE p.site.id=:site");
    if (album_id > 0)
        hql.append(" AND (p.album.id=:album OR p.album.parent.id=:album)");
    if (month_stamp > 190000 && month_stamp < 209912) {
        hql.append(" AND p.year=:year AND p.month=:month");
    }
    if (user == null || site.getOwner().getId() != user.getId()) {
        hql.append(" AND p.status<>:hidden_status AND p.album.type=:owner_album");
    }
    if (date > 0) {
        hql.append(" AND p.date=:date");
    }
    hql.append(" ORDER BY p.id DESC");
    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 (user == null || site.getOwner().getId() != user.getId()) {
            q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE);
            q.setInteger("owner_album", AlbumBean.TYPE_PUBLIC);
        }
        if (date > 0) {
            q.setInteger("date", date);
        }
        q.setFirstResult(fromIdx);
        q.setMaxResults(count);
        return q.list();
    } finally {
        hql = null;
    }
}