javax.persistence.Tuple Java Examples

The following examples show how to use javax.persistence.Tuple. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
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());
}
 
Example #2
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #4
Source File: PageQueryTemplate.java    From mPass with Apache License 2.0 6 votes vote down vote up
/** 添加选择字段,包括多语言 */
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));
		}
	}
}
 
Example #5
Source File: StatsUserProblemHibernateDao.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@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)));
}
 
Example #6
Source File: BridgeNameFinder.java    From zstack with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #8
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #9
Source File: V2ListCreatePrev.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #10
Source File: V2ListCreatePaging.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #11
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #12
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #13
Source File: ImageCascadeExtension.java    From zstack with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: JpaUtil.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #15
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #16
Source File: V2ListCreatePrev.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #17
Source File: V2List.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #18
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #19
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #20
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #21
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #22
Source File: VolumeSnapshotManagerImpl.java    From zstack with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #23
Source File: V2ListCreatePaging.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #24
Source File: V2List.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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(Task.class);
			CriteriaBuilder cb = em.getCriteriaBuilder();
			CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
			Root<Task> root = cq.from(Task.class);
			Predicate p = this.toFilterPredicate(effectivePerson, business, wi);
			if (ListTools.isNotEmpty(wi.getJobList())) {
				p = cb.and(p, root.get(Task_.job).in(wi.getJobList()));
			}
			if (ListTools.isNotEmpty(wi.getIdList())) {
				p = cb.and(p, root.get(Task_.id).in(wi.getIdList()));
			}
			wos = emc.fetch(Task.class, Wo.copier, p);
			this.relate(business, wos, wi);
		}
	}
	result.setData(wos);
	return result;
}
 
Example #25
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByCreatorPerson(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> pathCreatorPerson = root.get(Task_.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());
}
 
Example #26
Source File: V2ListCreatePrev.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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(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));
		ActionResult<List<Wo>> result = this.standardListPrev(Wo.copier, id, count, JpaObject.sequence_FIELDNAME,
				DESC, p);
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
Example #27
Source File: V2ListCreatePaging.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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(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));
		List<Wo> wos = emc.fetchDescPaging(Read.class, Wo.copier, p, page, size, Read.sequence_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(Read.class, p));
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
Example #28
Source File: V2List.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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(Read.class);
			CriteriaBuilder cb = em.getCriteriaBuilder();
			CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
			Root<Read> root = cq.from(Read.class);
			Predicate p = this.toFilterPredicate(effectivePerson, business, wi);
			if (ListTools.isNotEmpty(wi.getJobList())) {
				p = cb.and(p, root.get(Read_.job).in(wi.getJobList()));
			}
			if (ListTools.isNotEmpty(wi.getIdList())) {
				p = cb.and(p, root.get(Read_.id).in(wi.getIdList()));
			}
			wos = emc.fetch(Read.class, Wo.copier, p);
			this.relate(business, wos, wi);
		}
	}
	result.setData(wos);
	return result;
}
 
Example #29
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByApplication(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Read> root = cq.from(Read.class);
	Path<String> pathApplication = root.get(Read_.application);
	Path<String> pathApplicationName = root.get(Read_.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());
}
 
Example #30
Source File: PortForwardingManagerImpl.java    From zstack with Apache License 2.0 6 votes vote down vote up
@Override
public RangeSet getVipUsePortRange(String vipUuid, String protocol, VipUseForList useForList){
    RangeSet portRangeList = new RangeSet();
    List<RangeSet.Range> portRanges = new ArrayList<RangeSet.Range>();

    if (protocol.toUpperCase().equals(PortForwardingProtocolType.UDP.toString()) || protocol.toUpperCase().equals(PortForwardingProtocolType.TCP.toString())) {
        List<Tuple> pfPortList = Q.New(PortForwardingRuleVO.class).select(PortForwardingRuleVO_.vipPortStart, PortForwardingRuleVO_.vipPortEnd)
                .eq(PortForwardingRuleVO_.vipUuid, vipUuid).eq(PortForwardingRuleVO_.protocolType, PortForwardingProtocolType.valueOf(protocol.toUpperCase())).listTuple();
        Iterator<Tuple> it = pfPortList.iterator();
        while (it.hasNext()){
            Tuple strRange = it.next();
            int start = strRange.get(0, Integer.class);
            int end = strRange.get(1, Integer.class);

            RangeSet.Range range = new RangeSet.Range(start, end);
            portRanges.add(range);
        }
    }

    portRangeList.setRanges(portRanges);
    return portRangeList;
}