类javax.persistence.Tuple源码实例Demo

下面列出了怎么用javax.persistence.Tuple的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: HibernateTips   文件: TestCriteriaFunction.java
@Test
public void callSizeFunction() {
	log.info("... callSizeFunction ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createTupleQuery();
	Root<Author> root = cq.from(Author.class);
	cq.multiselect(root, cb.size(root.get(Author_.books)));
	cq.groupBy(root.get(Author_.id));
	
	TypedQuery<Tuple> q = em.createQuery(cq);
	List<Tuple> results = q.getResultList();
	
	for (Tuple r :  results) {
		log.info(r.get(0) + " wrote " +  r.get(1) + " books.");
	}

	em.getTransaction().commit();
	em.close();
}
 
源代码2 项目: o2oa   文件: EntityManagerContainer.java
public <T extends JpaObject, W extends GsonPropertyObject> List<T> fetchAscPaging(Class<T> clz,
		List<String> fetchAttributes, Predicate predicate, Integer page, Integer pageSize, String orderAttribute)
		throws Exception {
	List<T> list = new ArrayList<>();
	int max = (pageSize == null || pageSize < 1 || pageSize > MAX_PAGESIZE) ? DEFAULT_PAGESIZE : pageSize;
	int startPosition = (page == null || page < 1) ? 0 : (page - 1) * max;
	List<String> fields = ListTools.trim(fetchAttributes, true, true, JpaObject.id_FIELDNAME);
	EntityManager em = this.get(clz);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<T> root = cq.from(clz);
	List<Selection<?>> selections = new ArrayList<>();
	for (String str : fields) {
		selections.add(root.get(str));
	}
	cq.multiselect(selections).where(predicate).orderBy(cb.asc(root.get(orderAttribute)));
	T t = null;
	for (Tuple o : em.createQuery(cq).setFirstResult(startPosition).setMaxResults(max).getResultList()) {
		t = clz.newInstance();
		for (int i = 0; i < fields.size(); i++) {
			PropertyUtils.setProperty(t, fields.get(i), o.get(selections.get(i)));
		}
		list.add(t);
	}
	return list;
}
 
源代码3 项目: mPass   文件: PageQueryTemplate.java
/** 添加选择字段,包括多语言 */
private void appendSelectAndLangColumn(QueryContextImpl<E, Tuple> context,
		MetaProperty prop, String propName, List<Selection<?>> selects,
		ViewInfo current) {
	current.index = selects.size();
	Path<?> path = context.leftJoinPath(propName);
	selects.add(path);
	if (langSupport && prop.isLangSupport()) {
		String langName = PropertyLangUtil
				.getPropertyNameByLanguage(propName);
		if (langName != null) {
			if (langName.contains(".")) {
				langName = langName.substring(langName.lastIndexOf(".") + 1);
			}
			current.langIndex = selects.size();
			selects.add(path.getParentPath().get(langName));
		}
	}
}
 
源代码4 项目: hibernate-reactive   文件: ReactiveSessionImpl.java
private <T> ReactiveNativeQuery<T> createReactiveNativeQuery(NamedSQLQueryDefinition queryDefinition, Class<T> resultType) {
	if ( resultType != null && !Tuple.class.equals( resultType ) && !Object[].class.equals( resultType ) ) {
		resultClassChecking( resultType, queryDefinition );
	}

	final ReactiveNativeQueryImpl<T> query = new ReactiveNativeQueryImpl<>(
			queryDefinition,
			this,
			getFactory().getQueryPlanCache().getSQLParameterMetadata( queryDefinition.getQueryString(), false )
	);
	if ( Tuple.class.equals( resultType ) ) {
		query.setResultTransformer( new NativeQueryTupleTransformer() );
	}
	applyQuerySettingsAndHints( query );
	query.setHibernateFlushMode( queryDefinition.getFlushMode() );
	query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
	if ( queryDefinition.getLockOptions() != null ) {
		query.setLockOptions( queryDefinition.getLockOptions() );
	}

	initQueryFromNamedDefinition( query, queryDefinition );

	return query;
}
 
源代码5 项目: judgels   文件: StatsUserProblemHibernateDao.java
@Override
public Map<String, Long> selectCountsAcceptedByProblemJids(Set<String> problemJids) {
    if (problemJids.isEmpty()) {
        return Collections.emptyMap();
    }

    CriteriaBuilder cb = currentSession().getCriteriaBuilder();
    CriteriaQuery<Tuple> cq = cb.createTupleQuery();
    Root<StatsUserProblemModel> root = cq.from(getEntityClass());

    cq.select(cb.tuple(
            root.get(StatsUserProblemModel_.problemJid),
            cb.count(root)));

    cq.where(
            cb.equal(root.get(StatsUserProblemModel_.verdict), Verdict.ACCEPTED.getCode()),
            root.get(StatsUserProblemModel_.problemJid).in(problemJids));

    cq.groupBy(
            root.get(StatsUserProblemModel_.problemJid));

    return currentSession().createQuery(cq).getResultList()
            .stream()
            .collect(Collectors.toMap(tuple -> tuple.get(0, String.class), tuple -> tuple.get(1, Long.class)));
}
 
源代码6 项目: judgels   文件: StatsUserProblemHibernateDao.java
@Override
public Map<String, Long> selectCountsVerdictByUserJid(String userJid) {
    CriteriaBuilder cb = currentSession().getCriteriaBuilder();
    CriteriaQuery<Tuple> cq = cb.createTupleQuery();
    Root<StatsUserProblemModel> root = cq.from(getEntityClass());

    cq.select(cb.tuple(
            root.get(StatsUserProblemModel_.verdict),
            cb.count(root)));

    cq.where(
            cb.equal(root.get(StatsUserProblemModel_.userJid), userJid));

    cq.groupBy(
            root.get(StatsUserProblemModel_.verdict));

    return currentSession().createQuery(cq).getResultList()
            .stream()
            .collect(Collectors.toMap(tuple -> tuple.get(0, String.class), tuple -> tuple.get(1, Long.class)));
}
 
源代码7 项目: learning-code   文件: EmployeeServiceImpl.java
/**
 * 分组统计重名数量
 *
 * @param name
 * @return
 */
@Override
public List<Tuple> groupByName(String name) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Tuple> query = cb.createTupleQuery();
    Root<Employee> root = query.from(Employee.class);
    Join<Employee, EmployeeDetail> join = root.join(Employee_.detail, JoinType.LEFT);
    query.groupBy(join.get(EmployeeDetail_.name));
    if (name != null) {
        query.having(cb.like(join.get(EmployeeDetail_.name), "%" + name + "%"));
    }
    query.select(cb.tuple(join.get(EmployeeDetail_.name).alias("name"), cb.count(root).alias("count")));
    TypedQuery<Tuple> typedQuery = em.createQuery(query);
    return typedQuery.getResultList();
    // print sql :
    //select employeede1_.name as col_0_0_, count(employee0_.id) as col_1_0_ from employee employee0_
    // left outer join employee_detail employeede1_ on employee0_.detail_id=employeede1_.id
    // group by employeede1_.name having employeede1_.name like ?
}
 
源代码8 项目: o2oa   文件: FunctionAction.java
@POST
@Path("list/person")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listAllPersonName(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
		WrapInStringList wrapIn) {
	ActionResult<List<Tuple>> result = new ActionResult<>();
	List<Tuple> wraps = new ArrayList<>();
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		wraps = new ActionListAllPersonName().execute(business, wrapIn);
		result.setData(wraps);
	} catch (Throwable th) {
		th.printStackTrace();
		result.error(th);
	}
	asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
 
源代码9 项目: linq   文件: JpaUtil.java
@SuppressWarnings("rawtypes")
private static Object getValue(String propertyName, Object obj) {
	if (obj instanceof Map) {
          return ((Map) obj).get(propertyName);
       } else if (obj instanceof Tuple) {
           return ((Tuple) obj).get(propertyName);
       } else if (obj != null) {
           PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(obj.getClass(), propertyName);
           try {
              return pd.getReadMethod().invoke(obj, new Object[]{});
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
	return null;
}
 
源代码10 项目: o2oa   文件: ActionListToCurrentPersonPaging.java
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		ActionResult<List<Wo>> result = new ActionResult<>();
		EntityManager em = emc.get(EmpowerLog.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<EmpowerLog> root = cq.from(EmpowerLog.class);
		Predicate p = cb.equal(root.get(EmpowerLog_.toPerson), effectivePerson.getDistinguishedName());
		if (StringUtils.isNotEmpty(wi.getKey())) {
			String key = "%" + StringTools.escapeSqlLikeKey(wi.getKey()) + "%";
			p = cb.and(p, cb.like(root.get(EmpowerLog_.title), key, StringTools.SQL_ESCAPE_CHAR));
		}
		List<Wo> wos = emc.fetchDescPaging(EmpowerLog.class, Wo.copier, p, page, size,
				EmpowerLog.createTime_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(EmpowerLog.class, p));
		return result;
	}
}
 
源代码11 项目: zstack   文件: BridgeNameFinder.java
@Transactional(readOnly = true)
public Map<String, String> findByL3Uuids(Collection<String> l3Uuids) {
    String sql = "select t.tag, l3.uuid" +
            " from SystemTagVO t, L3NetworkVO l3" +
            " where t.resourceType = :ttype" +
            " and t.tag like :tag" +
            " and t.resourceUuid = l3.l2NetworkUuid" +
            " and l3.uuid in (:l3Uuids)" +
            " group by l3.uuid";
    TypedQuery<Tuple> tq = dbf.getEntityManager().createQuery(sql, Tuple.class);
    tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(KVMSystemTags.L2_BRIDGE_NAME.getTagFormat()));
    tq.setParameter("l3Uuids", l3Uuids);
    tq.setParameter("ttype", L2NetworkVO.class.getSimpleName());
    List<Tuple> ts = tq.getResultList();

    Map<String, String> bridgeNames = new HashMap<>();
    for (Tuple t : ts) {
        String brToken = t.get(0, String.class);
        String l3Uuid = t.get(1, String.class);
        bridgeNames.put(l3Uuid, KVMSystemTags.L2_BRIDGE_NAME.getTokenByTag(brToken, KVMSystemTags.L2_BRIDGE_NAME_TOKEN));
    }

    return bridgeNames;
}
 
源代码12 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByApplication(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Task> root = cq.from(Task.class);
	Path<String> pathApplication = root.get(Task_.application);
	Path<String> pathApplicationName = root.get(Task_.applicationName);
	cq.multiselect(pathApplication, pathApplicationName, cb.count(root)).where(predicate).groupBy(pathApplication);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathApplicationName));
		pair.setValue(o.get(pathApplication));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码13 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByProcess(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Task> root = cq.from(Task.class);
	Path<String> pathProcess = root.get(Task_.process);
	Path<String> pathProcessName = root.get(Task_.processName);
	cq.multiselect(pathProcess, pathProcessName, cb.count(root)).where(predicate).groupBy(pathProcess);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathProcessName));
		pair.setValue(o.get(pathProcess));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码14 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByCreatorUnit(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Task> root = cq.from(Task.class);
	Path<String> pathCreatorUnit = root.get(Task_.creatorUnit);
	cq.multiselect(pathCreatorUnit, cb.count(root)).where(predicate).groupBy(pathCreatorUnit);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathCreatorUnit));
		pair.setValue(o.get(pathCreatorUnit));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码15 项目: o2oa   文件: V2ListCreatePrev.java
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EntityManager em = emc.get(Read.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<Read> root = cq.from(Read.class);
		Predicate p = cb.equal(root.get(Read_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		ActionResult<List<Wo>> result = this.standardListPrev(Wo.copier, id, count, JpaObject.sequence_FIELDNAME,
				DESC, p);
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
源代码16 项目: o2oa   文件: V2ListCreatePaging.java
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EntityManager em = emc.get(TaskCompleted.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<TaskCompleted> root = cq.from(TaskCompleted.class);
		Predicate p = cb.equal(root.get(TaskCompleted_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		List<Wo> wos = emc.fetchDescPaging(TaskCompleted.class, Wo.copier, p, page, size, TaskCompleted.sequence_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(TaskCompleted.class, p));
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
源代码17 项目: o2oa   文件: V2ListCreatePrev.java
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EntityManager em = emc.get(Read.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<Read> root = cq.from(Read.class);
		Predicate p = cb.equal(root.get(Read_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		ActionResult<List<Wo>> result = this.standardListPrev(Wo.copier, id, count, JpaObject.sequence_FIELDNAME,
				DESC, p);
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
源代码18 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByCreatorUnit(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Path<String> pathCreatorUnit = root.get(TaskCompleted_.creatorUnit);
	cq.multiselect(pathCreatorUnit, cb.count(root)).where(predicate).groupBy(pathCreatorUnit);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathCreatorUnit));
		pair.setValue(o.get(pathCreatorUnit));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码19 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByStartTimeMonth(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Path<String> pathStartTimeMonth = root.get(TaskCompleted_.startTimeMonth);
	cq.multiselect(pathStartTimeMonth, cb.count(root)).where(predicate).groupBy(pathStartTimeMonth);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathStartTimeMonth));
		pair.setValue(o.get(pathStartTimeMonth));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream()
			.sorted((o1, o2) -> Objects.toString(o2.getName(), "").compareTo(Objects.toString(o1.getName(), "")))
			.collect(Collectors.toList());
}
 
源代码20 项目: zstack   文件: ImageCascadeExtension.java
@Transactional(readOnly = true)
private List<ImageDeletionStruct> getImageOnBackupStorage(List<String> bsUuids) {
    String sql = "select ref.backupStorageUuid, img from ImageVO img, ImageBackupStorageRefVO ref where img.uuid = ref.imageUuid and ref.backupStorageUuid in (:bsUuids) group by img.uuid";
    TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class);
    q.setParameter("bsUuids", bsUuids);
    List<Tuple> ts = q.getResultList();

    Map<String, ImageDeletionStruct> tmp = new HashMap<String, ImageDeletionStruct>();
    for (Tuple t : ts) {
        String bsUuid = t.get(0, String.class);
        ImageVO img = t.get(1, ImageVO.class);
        ImageDeletionStruct struct = tmp.get(img.getUuid());
        if (struct == null) {
            struct = new ImageDeletionStruct();
            struct.setImage(ImageInventory.valueOf(img));
            struct.setBackupStorageUuids(new ArrayList<String>());
            tmp.put(img.getUuid(), struct);
        }
        struct.getBackupStorageUuids().add(bsUuid);
    }

    List<ImageDeletionStruct> structs = new ArrayList<ImageDeletionStruct>();
    structs.addAll(tmp.values());
    return structs;
}
 
源代码21 项目: bdf3   文件: JpaUtil.java
@SuppressWarnings("rawtypes")
public static Object getValue(Object obj, String propertyName) {
	Object value = null;
	if (obj instanceof Map) {
		value = ((Map) obj).get(propertyName);
	} else if (obj instanceof Tuple) {
		value = ((Tuple) obj).get(propertyName);
	} else if (EntityUtils.isEntity(obj)) {
		value = EntityUtils.getValue(obj, propertyName);
	}  else if (obj != null) {
		PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(obj.getClass(), propertyName);
		try {
			value = pd.getReadMethod().invoke(obj, new Object[]{});
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			e.printStackTrace();
		}
	}
	return value;
}
 
源代码22 项目: o2oa   文件: ActionFilterAttribute.java
private List<NameValueCountPair> listProcessPair(Business business, EffectivePerson effectivePerson,
		Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathProcess = root.get(Review_.process);
	Path<String> pathProcessName = root.get(Review_.processName);
	cq.multiselect(pathProcess, pathProcessName, cb.count(root)).where(predicate).groupBy(pathProcess);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathProcessName));
		pair.setValue(o.get(pathProcess));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	list = list.stream().sorted((o1, o2) -> Objects.toString(o1.getName()).compareTo(o2.getName().toString()))
			.collect(Collectors.toList());
	return list;
}
 
源代码23 项目: o2oa   文件: ActionFilterAttribute.java
private List<NameValueCountPair> listCreatorUnitPair(Business business, EffectivePerson effectivePerson,
		Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathCreatorUnit = root.get(Review_.creatorUnit);
	cq.multiselect(pathCreatorUnit, cb.count(root)).where(predicate).groupBy(pathCreatorUnit);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setValue(o.get(pathCreatorUnit));
		pair.setName(OrganizationDefinition.name(o.get(pathCreatorUnit)));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	list = list.stream().sorted((o1, o2) -> Objects.toString(o1.getName()).compareTo(o2.getName().toString()))
			.collect(Collectors.toList());
	return list;
}
 
源代码24 项目: o2oa   文件: V2List.java
public ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	List<Wo> wos = new ArrayList<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	if ((!wi.isEmptyFilter()) || ListTools.isNotEmpty(wi.getJobList()) || ListTools.isNotEmpty(wi.getIdList())) {
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
			EntityManager em = emc.get(Review.class);
			CriteriaBuilder cb = em.getCriteriaBuilder();
			CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
			Root<Review> root = cq.from(Review.class);
			Predicate p = this.toFilterPredicate(effectivePerson, business, wi);
			if (ListTools.isNotEmpty(wi.getJobList())) {
				p = cb.and(p, root.get(Review_.job).in(wi.getJobList()));
			}
			if (ListTools.isNotEmpty(wi.getIdList())) {
				p = cb.and(p, root.get(Review_.id).in(wi.getIdList()));
			}
			wos = emc.fetch(Review.class, Wo.copier, p);
			this.relate(business, wos, wi);
		}
	}
	result.setData(wos);
	return result;
}
 
源代码25 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByApplication(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathApplication = root.get(Review_.application);
	Path<String> pathApplicationName = root.get(Review_.applicationName);
	cq.multiselect(pathApplication, pathApplicationName, cb.count(root)).where(predicate).groupBy(pathApplication);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathApplicationName));
		pair.setValue(o.get(pathApplication));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码26 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByProcess(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathProcess = root.get(Review_.process);
	Path<String> pathProcessName = root.get(Review_.processName);
	cq.multiselect(pathProcess, pathProcessName, cb.count(root)).where(predicate).groupBy(pathProcess);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathProcessName));
		pair.setValue(o.get(pathProcess));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码27 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByCreatorPerson(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathCreatorPerson = root.get(Review_.creatorPerson);
	cq.multiselect(pathCreatorPerson, cb.count(root)).where(predicate).groupBy(pathCreatorPerson);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathCreatorPerson));
		pair.setValue(o.get(pathCreatorPerson));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码28 项目: o2oa   文件: V2Count.java
private List<NameValueCountPair> groupByCreatorUnit(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathCreatorUnit = root.get(Review_.creatorUnit);
	cq.multiselect(pathCreatorUnit, cb.count(root)).where(predicate).groupBy(pathCreatorUnit);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathCreatorUnit));
		pair.setValue(o.get(pathCreatorUnit));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
源代码29 项目: zstack   文件: VolumeSnapshotManagerImpl.java
private void handle(GetVolumeSnapshotTreeRootNodeMsg msg) {
    List<Tuple> ts = SQL.New("select snapshot.primaryStorageInstallPath, tree.current from VolumeSnapshotTreeVO tree, VolumeSnapshotVO snapshot" +
            " where tree.volumeUuid = :volUuid" +
            " and snapshot.treeUuid = tree.uuid" +
            " and snapshot.parentUuid is null", Tuple.class)
            .param("volUuid", msg.getVolumeUuid())
            .list();
    GetVolumeSnapshotTreeRootNodeReply reply = new GetVolumeSnapshotTreeRootNodeReply();
    for (Tuple t : ts) {
        if (t.get(1, Boolean.class)) {
            reply.setCurrentRootInstallPath(t.get(0, String.class));
        } else {
            reply.addPreviousRootInstallPath(t.get(0, String.class));
        }
    }
    bus.reply(msg, reply);
}
 
源代码30 项目: o2oa   文件: V2ListCreatePaging.java
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EntityManager em = emc.get(Task.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<Task> root = cq.from(Task.class);
		Predicate p = cb.equal(root.get(Task_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		List<Wo> wos = emc.fetchDescPaging(Task.class, Wo.copier, p, page, size, Task.sequence_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(Task.class, p));
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
 类所在包
 类方法
 同包方法