public List
fetchDetailMetrics(Date dateFrom, Date dateTo, String navPage, String navOption, OrganizationDTO org) {
List
pageViews = new ArrayList (); log.warn("Date from " + dateFrom + " to " + dateTo);
DetachedCriteria metrics = DetachedCriteria.forClass(MetricsForUserSession.class);
metrics.add(Expression.between("dateTime", dateFrom, dateTo));
metrics.add(Expression.eq("navOption", navOption));
metrics.add(Expression.eq("navPage", navPage));
if (org != null)
{
log.warn(" org " + org.getName());
metrics.add(Expression.eq("organization.id", org.getId()));
}
ProjectionList projectList = Projections.projectionList();
// group by
projectList.add(Projections.groupProperty("entityId"));
// alias of the column head
projectList.add(Projections.alias(Projections.rowCount(), "count"));
metrics.setProjection(projectList);
// order by, sorting
metrics.addOrder(Order.desc("count"));
List
if (results == null || results.size() <>
log.warn("fetched nothing");
else
log.warn("fetched " + results.size());
log.warn("fetched navPages " + results.size());
for (Object[] column : results)
{
log.warn(column[0] + " " + column[1]);
PageView pageView = new PageView();
determineDescription(pageView, column, navPage);
pageView.setViewCount(new Integer(column[1].toString()));
pageViews.add(pageView);
}
return pageViews;
}
Hibernate Detached criteria with projections (GROUP BY)
Examples of Spring/Hibernate compare, group by, order by (sort) functionality:
My favorite quotations..
“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.” by Robert A. Heinlein
"We are but habits and memories we chose to carry along." ~ Uki D. Lucas
Recommended pages
Popular Recent Articles
-
Subclade R1b1b2a1a1d1* (23andMe.com nomenclature) or R1b1a2a1a1a4 (FTDNA nomenclature) is a men linage descended from the region that wa...
-
When trying to open the database you may get the following exception: java.sql.sqlexception: [sqlite_error] sql error or missing database (n...
-
I have noticed a very unsettling statistic on my blog. This prompted a fascinating question about AI, blogs' future, and maybe even the...
-
That is a good, if not easy, problem to solve! In the result, I would like to take the following code in <blockquote> tag function fol...
-
AIKO - "The Child of Artificial Intelligence" (in Japanese "ko" means child; "ai" means love denoting the ...
-
O'REILLY 201 0011 031 10110100180 000110111 01100041 001100010010000 5011011001010 1101110011 000100000 00000 10 1000012 Escaping the Bu...
-
On the mobile, the page is hard to read so I am including a LINK to Google document ...
-
This example shows you how to format a number based on user's language and region setting (LOCALE) /** * This method updates th...
-
Recently, I have been thinking about a new lever-action rifle. The appeal of these late 1800 models is that they are great, very light (5lbs...
-
Work Pressure! I am managing a project where budget is very (read insanely) small, deadlines are even worse, and most of the time it feels l...