Example usage for org.hibernate SQLQuery setLong

List of usage examples for org.hibernate SQLQuery setLong

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setLong.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(int position, long val) 

Source Link

Document

Bind a positional long-valued parameter.

Usage

From source file:com.tysanclan.site.projectewok.util.forum.MemberForumViewContext.java

License:Open Source License

@Override
public List<ForumPost> getPosts(Session sess, ForumThread context, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();

    q.append("SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = :thread ");
    q.append("ORDER BY time ASC LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("thread", context.getId());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.addEntity(ForumPost.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java

License:Open Source License

@Override
public List<ForumCategory> getCategories(Session sess, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();
    q.append("SELECT * FROM FORUMCATEGORY FC ");
    q.append("WHERE EXISTS ( ");

    q.append("SELECT * FROM FORUM f ");
    q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = FC.id ");

    q.append(") ORDER BY id ASC LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.addEntity(ForumCategory.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java

License:Open Source License

@Override
public int countForums(Session sess, ForumCategory context, User viewer) {

    StringBuilder q = new StringBuilder();
    q.append("SELECT COUNT(*) FROM FORUM f ");
    q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = :cat");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("cat", context.getId());

    return count(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java

License:Open Source License

@Override
public List<Forum> getForums(Session sess, ForumCategory context, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();
    q.append("SELECT * FROM FORUM f ");
    q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = :cat ");
    q.append("ORDER BY position ASC ");
    q.append("LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("cat", context.getId());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.addEntity(Forum.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java

License:Open Source License

@Override
public int countThreads(Session sess, Forum context, User viewer) {

    StringBuilder q = new StringBuilder();

    q.append("SELECT COUNT(*) FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ft.shadow = false AND ");
    q.append("NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) AND ");
    q.append("EXISTS (SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = ft.id)");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("forum", context.getId());

    return count(query);

}

From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java

License:Open Source License

@Override
public List<ForumThread> getThreads(Session sess, Forum context, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();

    q.append("SELECT * FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ft.shadow = false AND ");
    q.append("NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) AND ");
    q.append("EXISTS (SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = ft.id) ");
    q.append("ORDER BY STICKY DESC, lastPost DESC ");
    q.append("LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("forum", context.getId());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.addEntity(ForumThread.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java

License:Open Source License

@Override
public List<ForumCategory> getCategories(Session sess, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();
    q.append("SELECT * FROM FORUMCATEGORY FC ");
    q.append("WHERE EXISTS (");

    q.append("SELECT * FROM FORUM f ");
    q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = FC.id");

    q.append(") ORDER BY id ASC LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.addEntity(ForumCategory.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java

License:Open Source License

@Override
public int countThreads(Session sess, Forum context, User viewer) {

    StringBuilder q = new StringBuilder();

    q.append("SELECT COUNT(*) FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ");
    q.append("NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) AND ");
    q.append(//w  ww  .j  a  v  a  2  s .c  o  m
            "EXISTS (SELECT * FROM FORUMPOST FP WHERE (fp.shadow = false OR fp.poster_id = :viewer ) AND fp.thread_id = ft.id)");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("forum", context.getId());
    query.setLong("viewer", viewer.getId());

    return count(query);

}

From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java

License:Open Source License

@Override
public List<ForumThread> getThreads(Session sess, Forum context, User viewer, long offset, long count) {
    StringBuilder q = new StringBuilder();

    q.append("SELECT * FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ");
    q.append(/*from ww w.j av  a  2  s . c  om*/
            "EXISTS (SELECT * FROM FORUMPOST FP WHERE (fp.shadow = false OR fp.poster_id = :viewer ) AND fp.thread_id = ft.id) ");
    q.append("AND NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) ");
    q.append("ORDER BY STICKY DESC, lastPost DESC ");
    q.append("LIMIT :count OFFSET :offset");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("forum", context.getId());
    query.setLong("count", count);
    query.setLong("offset", offset);
    query.setLong("viewer", viewer.getId());
    query.setLong("viewer2", viewer.getId());
    query.addEntity(ForumThread.class);

    return listOf(query);
}

From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java

License:Open Source License

@Override
public int countPosts(Session sess, ForumThread context, User viewer) {
    StringBuilder q = new StringBuilder();

    q.append(/*  w  ww  . j a v  a2s  . c o m*/
            "SELECT COUNT(*) FROM FORUMPOST FP WHERE (fp.shadow = false OR fp.poster_id = :viewer ) AND fp.thread_id = :thread");

    SQLQuery query = sess.createSQLQuery(q.toString());
    query.setLong("thread", context.getId());
    query.setLong("viewer", viewer.getId());

    return count(query);
}