本文整理汇总了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;
}
示例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;
}