Skip to content

Instantly share code, notes, and snippets.

@jamesfalkner
Created January 9, 2012 20:33
Show Gist options
  • Save jamesfalkner/1584792 to your computer and use it in GitHub Desktop.
Save jamesfalkner/1584792 to your computer and use it in GitHub Desktop.
Calendar now = Calendar.getInstance();
Calendar lastmonth = Calendar.getInstance();
lastmonth.add(Calendar.MONTH, -1);
DynamicQuery q = DynamicQueryFactoryUtil.forClass(MBThread.class);
/* threads with categoryId == -1 are for things other than message boards, like comments on blogs, etc */
q.add(RestrictionsFactoryUtil.ne("categoryId", -1L));
q.add(RestrictionsFactoryUtil.eq("groupId", 14L));
q.add(RestrictionsFactoryUtil.eq("companyId", 1L));
q.add(RestrictionsFactoryUtil.eq("status", 0L));
q.add(RestrictionsFactoryUtil.between("lastPostDate", now.getTime(), lastmonth.getTime()));
q.setProjection(ProjectionFactoryUtil.property("threadId"));
List<Long> res1 = MBThreadLocalServiceUtil.dynamicQuery(q);
DynamicQuery q2 = DynamicQueryFactoryUtil.forClass(MBMessage.class);
q2.add(RestrictionsFactoryUtil.in("threadId", res1));
q2.add(RestrictionsFactoryUtil.between("createDate", now.getTime(), lastmonth.getTime()));
q2.setProjection(
ProjectionFactoryUtil.projectionList()
.add(ProjectionFactoryUtil.groupProperty("threadId"))
.add(ProjectionFactoryUtil.rowCount()));
List<Object> res2 = MBMessageLocalServiceUtil.dynamicQuery(q2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment