Example usage for org.hibernate.criterion Projections groupProperty

List of usage examples for org.hibernate.criterion Projections groupProperty

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections groupProperty.

Prototype

public static PropertyProjection groupProperty(String propertyName) 

Source Link

Document

A grouping property value projection

Usage

From source file:com.bean.StatisticBean.java

public List<Object[]> getTopUserMostPost() {
    Dao dao = new Dao();
    Criteria c = dao.createCriteria(Property.class);
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.groupProperty("users"));
    proj.add(Projections.rowCount(), "Count");
    c.setProjection(proj);/*from  ww w  .  j  a  va 2  s  .c  om*/
    c.addOrder(Order.desc("Count"));
    c.setFirstResult(0);
    c = selectTopUserMostPost == 0 ? c.setMaxResults(10) : c.setMaxResults(selectTopUserMostPost);
    List<Object[]> a = c.list();
    return a;
}

From source file:com.bean.StatisticBean.java

public List<Object[]> getTopPostMostFav() {
    Dao dao = new Dao();
    Criteria c = dao.createCriteria(FavoriteProperty.class);
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.groupProperty("property"));
    proj.add(Projections.rowCount(), "Count");
    c.setProjection(proj);//from www  .  jav a  2s  .  co  m
    c.addOrder(Order.desc("Count"));
    c.setFirstResult(0);
    c = selectTopPostMostFav == 0 ? c.setMaxResults(10) : c.setMaxResults(selectTopPostMostFav);
    List<Object[]> a = c.list();
    return a;
}

From source file:com.bloatit.data.queries.DaoUserContentQuery.java

License:Open Source License

/**
 * Group by member.
 */
public void groupByMember() {
    add(Projections.groupProperty(MEMBER));
}

From source file:com.bloatit.data.queries.DaoUserContentQuery.java

License:Open Source License

/**
 * Group by as team.
 */
public void groupByAsTeam() {
    add(Projections.groupProperty(AS_TEAM));
}

From source file:com.certus.actions.getAllProductsJsonAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();

    Criteria cr = s.createCriteria(ProductHasSize.class, "phs");
    cr.createAlias("phs.product", "product").createAlias("phs.size", "size")
            .createAlias("product.brand", "brand").add(Restrictions.eq("product.availability", true))
            .add(Restrictions.eq("brand.availability", true))
            .setProjection(Projections.groupProperty("product"));

    List<Product> pros = cr.list();
    List<ProductHasSize> newPros = new ArrayList<>();
    for (Product pro : pros) {
        ProductHasSize ph = productDetails(pro, s);
        newPros.add(ph);/*  ww  w  .  j  a  va 2s .c o  m*/
    }
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.registerTypeAdapter(ProductHasSize.class, new ProductFilterTypeAdapter()).create();
    String element = gson.toJson(newPros);
    s.close();
    response.getWriter().write(element);

}

From source file:com.certus.actions.mainSearchBarAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*w  w w.j  a v  a  2 s. c om*/
        Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
        String pNameMatch = request.getParameter("pName");
        // System.out.println("Start");
        Criteria cr = s.createCriteria(ProductHasSize.class, "phs");
        cr.createAlias("phs.product", "product").createAlias("phs.size", "size")
                .createAlias("product.brand", "brand").add(Restrictions.eq("product.availability", true))
                .add(Restrictions.eq("brand.availability", true))
                .add(Restrictions.like("product.name", pNameMatch, MatchMode.ANYWHERE))
                .setProjection(Projections.groupProperty("product"));
        // System.out.println("End");

        List<Product> pros = cr.list();

        String html = "";
        html += "<div class=\"items\">\n" + " <div class=\"container\">\n" + "   <div class=\"row\">\n"
                + "   <div class=\"col-md-12\">\n" + "   <h3 class=\"title\">Search Results</h3>\n"
                + "     </div>";

        Context env1 = (Context) new InitialContext().lookup("java:comp/env");
        String productsPath1 = (String) env1.lookup("uploadpathproducts");

        for (Product pro : pros) {
            ProductHasSize ph = productDetails(pro, s);

            html += "<div class='col-md-3 col-sm-4'>" + " <div class=\"item\">\n" + "     <!-- Item image -->\n"
                    + "     \n";
            if (ph.getProduct().getDiscountPrice() != 0) {

                html += "<span class=\"ico pull-right\"><img src=\"img/sale.png\" alt=\"\"></span>\n";
            }
            html += "   <div class=\"item-image\">\n" + "       \n" + "       <a href=\"single-item.jsp?cat="
                    + ph.getProduct().getSubCategory().getCategory().getId() + "&sub="
                    + ph.getProduct().getSubCategory().getId() + "&pid=" + ph.getProduct().getId()
                    + "\"><img src=\"" + productsPath1 + ph.getProduct().getImageMain()
                    + "\" alt=\"\" class=\"img-responsive\"></a>\n" + "   </div>\n"
                    + "   <!-- Item details -->\n" + "   <div class=\"item-details\">\n" + " <!-- Name -->\n"
                    + " <!-- Use the span tag with the class \"ico\" and icon link (hot, sale, deal, new) -->\n"
                    + " <div id=\"quickfit\">\n"
                    + "     <h5 style=\"white-space: nowrap;overflow: hidden;\"><a href=\"single-item.jsp?cat="
                    + ph.getProduct().getSubCategory().getCategory().getId() + "&sub="
                    + ph.getProduct().getSubCategory().getId() + "&pid=" + ph.getProduct().getId() + "\">"
                    + ph.getProduct().getName() + "</a></h5>\n" + " </div>\n"
                    + " <div class=\"clearfix\"></div>\n" + " <!-- Para. Note more than 2 lines. -->\n" + " <p>"
                    + ph.getProduct().getBrand().getBrandName() + "</p>\n" + " <hr>\n" + " <!-- Price -->\n"
                    + "       <div class=\"item-price pull-left\">\n";
            if (ph.getProduct().getDiscountPrice() != 0.0) {
                html += "   <del>Rs.&nbsp;" + ph.getPrice() + "</del>\n"
                        + "   <p style=\"color: #F25758;\">Rs.&nbsp;"
                        + ph.getDiscountPrice(ph.getPrice(), ph.getProduct().getDiscountPrice()) + "</p>\n";
            } else {
                html += "Rs " + ph.getPrice();
            }
            html += "</div>\n" + " <form action=\"addToCartAction\" method=\"GET\">\n"
                    + " <input name=\"pro_id\" value=\"" + ph.getProduct().getId() + "\" type=\"hidden\">\n"
                    + " <input name=\"size\" value=\""
                    + ph.getSize(ph.getProduct().getProductHasSizes(), ph.getProduct().getId())
                    + "\" type=\"hidden\">\n" + " <input name=\"qnty\" value=\"1\" type=\"hidden\">\n"
                    + " <input name=\"dom\" value=\"tyt\" type=\"hidden\">\n"
                    + " <div class=\"button pull-right\">\n"
                    + "     <button class=\"btn\" style=\"background-color: #F25758; color: #efd8d8;\" type=\"submit\">Add to Cart</button>\n"
                    + " </div>\n" + "        </form>\n" + "        <div class=\"clearfix\"></div>\n"
                    + "    </div>\n" + "</div>\n" + "</div>";
        }

        html += "</div></div>";
        s.close();
        response.getWriter().write(html);
    } catch (NamingException ex) {
        Logger.getLogger(mainSearchBarAction.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.certus.test.Test3.java

public static void main(String[] args) {
    //    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    //        List<Product> proList = s.createCriteria(Product.class).list();
    //        GsonBuilder gsonBuilder = new GsonBuilder();
    //        Gson gson = gsonBuilder.registerTypeAdapter(Product.class, new CustomTypeAdapter()).create();
    //        String element = gson.toJson(proList);
    //        System.out.println(element);

    //        A a = new A();
    //        a.setAge("23");
    //        a.setName("aaa");
    //        a.setSchool("bbb college");
    //        try {
    //            Map<String, String> map = BeanUtils.describe(a);
    ////w  w  w.j a  v  a  2 s  . c  o m
    //            for (Map.Entry<String, String> entry : map.entrySet()) {
    //                System.out.println(entry.getKey() + "/" + entry.getValue());
    //            }
    //
    //            Field[] allFields = a.getClass().getFields();
    //            for (Field field : allFields) {
    //                System.out.println(field.getName());
    //            }
    //
    //        } catch (Exception e) {
    //        }
    String pNameMatch = "top";
    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    Criteria cr = s.createCriteria(ProductHasSize.class, "phs");
    cr.createAlias("phs.product", "product").createAlias("phs.size", "size")
            .createAlias("product.brand", "brand").add(Restrictions.eq("product.availability", true))
            .add(Restrictions.eq("brand.availability", true))
            .add(Restrictions.like("product.name", pNameMatch, MatchMode.ANYWHERE))
            .setProjection(Projections.groupProperty("product"));

    List<Product> phs = cr.list();
    for (Product ph : phs) {
        ProductHasSize pp = new Test3().productDetails(ph, s);
        String sl = pp.getPrice() + " - " + pp.getProduct().getName();
        System.out.println(sl);
    }
    //System.out.println(phs.toArray());
    //  Map stateMap = new HashMap();
    //    for (Object[] obj : phs) {
    //        DownloadState downloadState = (DownloadState) obj[0];
    //        stateMap.put(downloadState.getDescription().toLowerCase() (Integer) obj[1]);
    //    }

}

From source file:com.dalamar.model.LateTrainDaoImpl.java

public LateTrainDao groupBy(String field) {
    Projection max = Projections.groupProperty(field);
    projections.add(max);
    return this;
}

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//from  ww  w  . j a  va 2  s . co  m
public List<Integer> getTopXVulnerableAppsFromList(int numApps, List<Integer> teamIdList,
        List<Integer> applicationIdList, List<Integer> tagIdList, List<Integer> vulnTagIdList) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Application.class);
    criteria.createAlias("vulnerabilities", "vulnerability");
    criteria.add(Restrictions.eq("active", true));
    criteria.add(Restrictions.eq("vulnerability.active", true));
    criteria.add(Restrictions.eq("vulnerability.hidden", false));
    criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false));

    if (vulnTagIdList.size() > 0) {
        criteria.createAlias("vulnerability.tags", "tags");
        criteria.add(Restrictions.in("tags.id", vulnTagIdList));
    }

    if (teamIdList.isEmpty() || applicationIdList.isEmpty()) {
        if (!applicationIdList.isEmpty()) {
            criteria.add(Restrictions.in("id", applicationIdList));
        }

        if (!teamIdList.isEmpty()) {
            criteria.add(Restrictions.in("organization.id", teamIdList));
        }
    } else {
        criteria.add(Restrictions.or(Restrictions.in("id", applicationIdList),
                Restrictions.in("organization.id", teamIdList)));
    }
    if (!tagIdList.isEmpty()) {
        criteria.createAlias("tags", "tag");
        criteria.add(Restrictions.in("tag.id", tagIdList));
    }

    criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id"))
            .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount")));
    criteria.addOrder(Order.desc("vulnCount"));

    List<Integer> list = list();
    List results = criteria.list();
    int i = 0;
    for (Object result : results) {
        if (i++ >= numApps) {
            break;
        }
        Object[] resultArray = (Object[]) result;
        list.add((Integer) resultArray[0]);
    }

    if (list.isEmpty())
        list = Arrays.asList(-1);
    return list;
}

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java

License:Mozilla Public License

@Override
public List<Map<String, Object>> retrieveAppsInfoMap(List<Integer> applicationIdList,
        List<Integer> vulnTagIds) {

    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Application.class);

    criteria.createAlias("vulnerabilities", "vulnerability");
    criteria.createAlias("organization", "team");
    criteria.add(Restrictions.eq("active", true));
    criteria.add(Restrictions.eq("vulnerability.active", true));
    criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false));
    criteria.createAlias("vulnerability.genericSeverity", "severity");

    if (applicationIdList.size() > 0) {
        criteria.add(Restrictions.in("id", applicationIdList));
    }/*w  w  w .  ja  va2  s.c  o m*/

    if (vulnTagIds.size() > 0) {
        criteria.createAlias("vulnerability.tags", "tags");
        criteria.add(Restrictions.in("tags.id", vulnTagIds));
    }

    criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id"), "appId")
            .add(Projections.groupProperty("name"), "appName")
            .add(Projections.groupProperty("team.id"), "teamId")
            .add(Projections.groupProperty("team.name"), "teamName")
            .add(Projections.groupProperty("severity.intValue"), "severityIntValue")
            .add(Projections.groupProperty("severity.name"), "severityNameValue")
            .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount")));
    criteria.addOrder(Order.desc("vulnCount"));
    criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

    List results = criteria.list();
    return results;
}