当前位置: 首页>>代码示例>>Java>>正文


Java Tuple.toArray方法代码示例

本文整理汇总了Java中javax.persistence.Tuple.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.toArray方法的具体用法?Java Tuple.toArray怎么用?Java Tuple.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.Tuple的用法示例。


在下文中一共展示了Tuple.toArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sumPriceByPurchaseCustomer

import javax.persistence.Tuple; //导入方法依赖的package包/类
public Map<Customer, Double> sumPriceByPurchaseCustomer() {
    // Create "tuple" query for use with groupBy; otherwise, throws PersistenceException: Exception [EclipseLink-6051]
    CriteriaQuery<Tuple> query = em.getCriteriaBuilder().createTupleQuery();
    Root<Customer> from = query.from(Customer.class);
    ListJoin<Customer, Purchase> joinPurchase = from.join(Customer_.purchases);
    ListJoin<Purchase, Product> joinProduct = joinPurchase.join(Purchase_.products);
    query.multiselect(from.get(BaseModel_.id), em.getCriteriaBuilder().sum(joinProduct.get(Product_.price)));
    query.groupBy(from.get(BaseModel_.id));
    List<Tuple> results = em.createQuery(query).getResultList();
    
    Map<Customer, Double> ret = new HashMap<>();
    for (Tuple result : results) {
        Object[] arr = result.toArray();
        ret.put(customerService.findById((Long)arr[0]), ((Double)arr[1]));
    }
    return ret;
}
 
开发者ID:codebulb,项目名称:JpaQueries,代码行数:18,代码来源:ProductServiceWithCriteria.java

示例2: sumPriceByPurchaseCustomer

import javax.persistence.Tuple; //导入方法依赖的package包/类
public Map<Customer, Double> sumPriceByPurchaseCustomer() {
    // Create "tuple" query for use with groupBy; otherwise, throws PersistenceException: Exception [EclipseLink-6051]
    CriteriaQuery<Tuple> query = em.getCriteriaBuilder().createTupleQuery();
    Root<Customer> from = query.from(Customer.class);
    Join<Customer, Purchase> joinPurchase = from.join("purchases");
    Join<Purchase, Product> joinProduct = joinPurchase.join("products");
    query.multiselect(from.get("id"), em.getCriteriaBuilder().sum(joinProduct.get("price").as(Double.class)));
    query.groupBy(from.get("id"));
    List<Tuple> results = em.createQuery(query).getResultList();
    
    Map<Customer, Double> ret = new HashMap<>();
    for (Tuple result : results) {
        Object[] arr = result.toArray();
        ret.put(customerService.findById((Long)arr[0]), ((Double)arr[1]));
    }
    return ret;
}
 
开发者ID:codebulb,项目名称:JpaQueries,代码行数:18,代码来源:ProductServiceWithCriteriaString.java


注:本文中的javax.persistence.Tuple.toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。