List of usage examples for org.hibernate.criterion Projections min
public static AggregateProjection min(String propertyName)
From source file:postgreHibernateClient.postgreHibClient.java
License:Open Source License
@Override public HashMap<String, String> getInitialStats() { HashMap<String, String> stats = new HashMap<String, String>(); // session = sessionFactory.openSession(); try {/*www . j a va 2s. c o m*/ tx = session.beginTransaction(); Criteria c = session.createCriteria(USERS.class).setProjection(Projections.count("userid")); Long usercount = (Long) c.list().get(0); usercount = usercount > 0 ? usercount : 0; stats.put("usercount", Long.toString(usercount)); Criteria c1 = session.createCriteria(USERS.class).setProjection(Projections.min("userid")); String offset = (String) c1.list().get(0); //get resources per user USERS u = new USERS(); u = (USERS) session.get(USERS.class, offset); stats.put("avgfriendsperuser", Integer.toString(u.getConfFriendCnt())); stats.put("resourcesperuser", Integer.toString(u.getResCnt())); stats.put("avgpendingperuser", Integer.toString(u.getPendFriendCnt())); } catch (Exception e) { e.printStackTrace(); } finally { // session.close(); } return stats; }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
@Override public void visitPropertySelection(QPropertySelection n) throws Exception { String name = parseSubcriteria(n.getProperty()); switch (n.getFunction()) { default:/*from ww w. j a v a 2 s. co m*/ throw new IllegalStateException("Unexpected selection item function: " + n.getFunction()); case AVG: m_lastProj = Projections.avg(name); break; case MAX: m_lastProj = Projections.max(name); break; case MIN: m_lastProj = Projections.min(name); break; case SUM: m_lastProj = Projections.sum(name); break; case COUNT: m_lastProj = Projections.count(name); break; case COUNT_DISTINCT: m_lastProj = Projections.countDistinct(name); break; case ID: m_lastProj = Projections.id(); break; case PROPERTY: m_lastProj = Projections.groupProperty(name); break; case ROWCOUNT: m_lastProj = Projections.rowCount(); break; case DISTINCT: m_lastProj = Projections.distinct(Projections.property(name)); break; } }