javax.persistence.criteria.Predicate Java Examples

The following examples show how to use javax.persistence.criteria.Predicate. 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: StatisticUnitForDayFactory.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
public List<String> listByUnitDayDate(String name, String date) throws Exception {
	if (name == null || name.isEmpty()) {
		logger.error(new UnitNamesEmptyException());
		return null;
	}

	EntityManager em = this.entityManagerContainer().get(StatisticUnitForDay.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<StatisticUnitForDay> root = cq.from(StatisticUnitForDay.class);
	Predicate p = cb.equal(root.get(StatisticUnitForDay_.unitName), name);
	if (date == null || date.isEmpty()) {
		logger.error(new StatisticDateEmptyException());
	} else {
		p = cb.and(p, cb.equal(root.get(StatisticUnitForDay_.statisticDate), date));
	}
	cq.select(root.get(StatisticUnitForDay_.id));
	return em.createQuery(cq.where(p)).setMaxResults(62).getResultList();
}
 
Example #2
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据中心工作ID,查询所有的干系人姓名
 * 
 * @param centerId
 * @param identity
 *            干系人身份
 * @return
 * @throws Exception
 */
// @MethodDescribe( "根据中心工作ID,查询所有的干系人身份" )
public List<String> listDistinctIdentityNameByCenterId(String centerId, String identity) throws Exception {
	if (centerId == null || centerId.isEmpty()) {
		logger.warn("centerId is null!");
		return null;
	}
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	cq.distinct(true).select(root.get(OkrWorkPerson_.employeeIdentity));
	Predicate p = cb.equal(root.get(OkrWorkPerson_.centerId), centerId);
	if (identity != null && !identity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), identity));
	}
	return em.createQuery(cq.where(p)).setMaxResults(2000).getResultList();
}
 
Example #3
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据工作信息ID,获取工作干系人信息ID列表
 * 
 * @param workId
 * @return
 * @throws Exception
 */
// @MethodDescribe( "根据工作信息ID,用户身份,获取工作干系人信息ID列表" )
public List<String> listByWorkIdAndUserIdentity(String workId, String userIdentity, List<String> statuses)
		throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	Predicate p = cb.equal(root.get(OkrWorkPerson_.workId), workId);
	if (userIdentity != null && !userIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.employeeIdentity), userIdentity));
	}
	if (statuses != null && statuses.size() > 0) {
		p = cb.and(p, root.get(OkrWorkPerson_.status).in(statuses));
	}
	cq.select(root.get(OkrWorkPerson_.id));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #4
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private AppInfo getAppInfoWithAlias(Business business, String alias) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return null;
	}
	EntityManager em = business.entityManagerContainer().get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<AppInfo> cq = cb.createQuery(AppInfo.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	Predicate p = cb.equal( root.get(AppInfo_.appAlias ), alias);
	List<AppInfo> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
	if (os.size() == 1) {
		return os.get(0);
	} else {
		return null;
	}
}
 
Example #5
Source File: CleanupPromptErrorLog.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private void cleanupPromptErrorLog() throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		EntityManager em = emc.get(PromptErrorLog.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<String> cq = cb.createQuery(String.class);
		Root<PromptErrorLog> root = cq.from(PromptErrorLog.class);
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, -7);
		Predicate p = cb.not(cb.greaterThan(root.get(PromptErrorLog_.createTime), cal.getTime()));
		cq.select(root.get(PromptErrorLog_.id)).where(p);
		List<String> list = em.createQuery(cq).getResultList();
		for (int i = 0; i < list.size(); i++) {
			if (i % 100 == 0) {
				emc.beginTransaction(PromptErrorLog.class);
			}
			PromptErrorLog o = emc.find(list.get(i), PromptErrorLog.class);
			emc.remove(o);
			if ((i % 100 == 99) || (i == (list.size() - 1))) {
				emc.commit();
			}
		}
	}
}
 
Example #6
Source File: AttendanceDetailFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<AttendanceCycles> getCyclesFromDetailWithDateSplit( String empName, Date startDate, Date endDate )  throws Exception{
	if( startDate == null || startDate == null ){
		return null;
	}
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<AttendanceCycles> cq = cb.createQuery(AttendanceCycles.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);
	Predicate p = cb.between( root.get(AttendanceDetail_.recordDate), startDate, endDate);
	p = cb.and( p, cb.equal( root.get(AttendanceDetail_.empName), empName));
	List<Selection<?>> selectionList = new ArrayList<Selection<?>>();
	selectionList.add(root.get(AttendanceDetail_.cycleYear ));
	selectionList.add(root.get(AttendanceDetail_.cycleMonth ));
	cq.distinct(true).multiselect(selectionList);
	
	return em.createQuery(cq.where(p)).getResultList();
}
 
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> 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 #8
Source File: StatisticUnitForMonthFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据组织名称,统计年月,统计顶层组织所有人员异常打卡次数总和
 * @param unitName
 * @param cycleYear
 * @param cycleMonth
 * @return
 * @throws Exception
 */
public Long sumAbNormalDutyCountByUnitYearAndMonth(List<String> unitName, String sYear, String sMonth) throws Exception{
	if( unitName == null || unitName.size() == 0 ){
		logger.error( new UnitNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( StatisticUnitForMonth.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<StatisticUnitForMonth> root = cq.from( StatisticUnitForMonth.class);		
	//查询总数
	cq.select( cb.sum( root.get(StatisticUnitForMonth_.abNormalDutyCount) ) );		
	Predicate p = root.get(StatisticUnitForMonth_.unitName).in( unitName );
	if( sYear == null || sYear.isEmpty() ){
		logger.error( new StatisticYearEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticYear), sYear));
	}
	if( sMonth == null || sMonth.isEmpty() ){
		logger.error( new StatisticMonthEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticMonth), sMonth));
	}
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #9
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> listActivityNamePair(Business business, EffectivePerson effectivePerson)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Task> root = cq.from(Task.class);
	Predicate p = cb.equal(root.get(Task_.person), effectivePerson.getDistinguishedName());
	cq.select(root.get(Task_.activityName)).where(p).distinct(true);
	List<String> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> wos = new ArrayList<>();
	for (String str : os) {
		if (StringUtils.isNotEmpty(str)) {
			NameValueCountPair o = new NameValueCountPair();
			o.setValue(str);
			o.setName(str);
			wos.add(o);
		}
	}
	SortTools.asc(wos, "name");
	return wos;
}
 
Example #10
Source File: UserDaoRdbmsImpl.java    From devicehive-java-server with Apache License 2.0 6 votes vote down vote up
@Override
public List<UserVO> list(String login, String loginPattern,
                          Integer role, Integer status,
                          String sortField, boolean sortOrderAsc,
                          Integer take, Integer skip) {
    CriteriaBuilder cb = criteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> from = cq.from(User.class);

    Predicate[] predicates = CriteriaHelper.userListPredicates(cb, from, ofNullable(login), ofNullable(loginPattern), ofNullable(role), ofNullable(status));
    cq.where(predicates);
    CriteriaHelper.order(cb, cq, from, ofNullable(sortField), Boolean.TRUE.equals(sortOrderAsc));

    TypedQuery<User> query = createQuery(cq);
    cacheQuery(query, of(CacheConfig.refresh()));
    ofNullable(take).ifPresent(query::setMaxResults);
    ofNullable(skip).ifPresent(query::setFirstResult);
    return query.getResultList().stream().map(User::convertToVo).collect(Collectors.toList());
}
 
Example #11
Source File: OkrWorkBaseInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Long getCompletedWorkCountByCenterId(String centerId, List<String> status) throws Exception {
	if( centerId == null || centerId.isEmpty() ){
		throw new Exception( "centerId is null." );
	}
	if( status == null || status.isEmpty() ){
		throw new Exception( "status is null." );
	}
	EntityManager em = this.entityManagerContainer().get( OkrWorkBaseInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<OkrWorkBaseInfo> root = cq.from( OkrWorkBaseInfo.class);
	Predicate p = root.get( OkrWorkBaseInfo_.status ).in( status );
	p = cb.and( p, cb.equal( root.get( OkrWorkBaseInfo_.centerId ), centerId));
	p = cb.and( p, cb.equal( root.get( OkrWorkBaseInfo_.workProcessStatus ), "已完成"));
	//查询总数
	cq.select( cb.count( root ) );
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #12
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Long getWorkTotalByCenterId(String identity, List<String> status, String processIdentity) throws Exception {
	if (identity == null || identity.isEmpty()) {
		throw new Exception("identity is null.");
	}
	if (status == null || status.isEmpty()) {
		throw new Exception("status is null.");
	}
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	Predicate p = root.get(OkrWorkPerson_.status).in(status);
	p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.employeeIdentity), identity));
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	// 查询总数
	cq.select(cb.count(root));
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #13
Source File: AttendanceDetailStatisticFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据员工,打卡日期月,统计请假天数
 * @param unitNames
 * @param recordDate
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayDaysByUnitAndDate( List<String> unitNames, String recordDate ) throws Exception{
	if( unitNames == null || unitNames.size() == 0 ){
		logger.error( new UnitNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);			
	Predicate p = root.get( AttendanceDetail_.unitName ).in( unitNames );
	p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordStatus ), 1));
	if( recordDate == null || recordDate.isEmpty() ){
		logger.error( new RecordDateEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordDateString ), recordDate));
	}		
	//查询总数
	cq.select( cb.sum( root.get( AttendanceDetail_.getSelfHolidayDays ) ) );	
			
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #14
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleAliasWithPortal(Business business, String portalId, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("alias").in(list);
	p = cb.and(p, cb.equal(root.get("portal"), portalId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("alias")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #15
Source File: StatisticPersonForMonthFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据组织列表,统计年月,计算组织内所有员工出勤天数总和
 * @param unitName
 * @param sYear
 * @param sMonth
 * @return
 * @throws Exception
 */
public Double sumAttendanceDayCountByUnitYearAndMonth( List<String> unitName, String sYear, String sMonth) throws Exception{
	if( unitName == null || unitName.size() == 0 ){
		logger.error( new UnitNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( StatisticPersonForMonth.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<StatisticPersonForMonth> root = cq.from( StatisticPersonForMonth.class);		
	//查询总数
	cq.select( cb.sum( root.get(StatisticPersonForMonth_.onDutyDayCount) ) );		
	Predicate p = root.get(StatisticPersonForMonth_.unitName).in( unitName );
	if( sYear == null || sYear.isEmpty() ){
		logger.error( new StatisticYearEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticPersonForMonth_.statisticYear), sYear));
	}
	if( sMonth == null || sMonth.isEmpty() ){
		logger.error( new StatisticMonthEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticPersonForMonth_.statisticMonth), sMonth));
	}
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #16
Source File: JpaQueryUtils.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
public static void processGreaterOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter,
                                          Expression filterExpr) {
    Object value = filter.getValue();
    if (value instanceof Date) {
        Timestamp timestamp = new Timestamp(((Date) value).getTime());
        predicates.add(cb.greaterThan(filterExpr, timestamp));
    } else if (value instanceof String) {
        if (filterExpr.getJavaType().equals(Timestamp.class)) {
            java.util.Date date = DateUtils.convertToTimestamp((String) value);
            predicates.add(cb.greaterThan(filterExpr, new Timestamp(date.getTime())));
        } else {
            predicates.add(cb.greaterThan(filterExpr, (String) value));
        }
    } else if (value instanceof Number) {
        if (value instanceof Integer) predicates.add(cb.greaterThan(filterExpr, (Integer) value));
        if (value instanceof Long) predicates.add(cb.greaterThan(filterExpr, (Long) value));
        if (value instanceof Float) predicates.add(cb.greaterThan(filterExpr, (Float) value));
        if (value instanceof Double) predicates.add(cb.greaterThan(filterExpr, (Double) value));
    }
}
 
Example #17
Source File: LinqImpl.java    From linq with Apache License 2.0 6 votes vote down vote up
protected void applyPredicateToCriteria(AbstractQuery<?> query) {

		Predicate predicate = parsePredicate(junction);
		if (predicate != null) {
			query.where(predicate);
		}
		
		predicate = parsePredicate(having);
		if (predicate != null) {
			query.having(predicate);
		}
		
		if (query instanceof CriteriaQuery) {
			if (!CollectionUtils.isEmpty(orders)) {
				((CriteriaQuery<?>) query).orderBy(orders);
			}
		}
	}
 
Example #18
Source File: ActionClean.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<String> list(Business business, Boolean cleanWork, Boolean cleanWorkCompleted, Boolean cleanCms)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(Entry.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Entry> root = cq.from(Entry.class);
	Predicate p = cb.disjunction();
	if (BooleanUtils.isTrue(cleanWork)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_WORK));
	}
	if (BooleanUtils.isTrue(cleanWorkCompleted)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_WORKCOMPLETED));
	}
	if (BooleanUtils.isTrue(cleanCms)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_CMS));
	}
	cq.select(root.get(Entry_.id)).where(p);
	List<String> os = em.createQuery(cq).setMaxResults(BATCHSIZE).getResultList();
	return os;
}
 
Example #19
Source File: JpaSpecs.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
public static Specification<Conference> inProgressConferences() {
	return new Specification<Conference>() {

		@Override
		public Predicate toPredicate(Root<Conference> root,
				CriteriaQuery<?> query, CriteriaBuilder cb) {
			Expression<Timestamp> currentTimestamp = cb.currentTimestamp();
			return cb.and(
					cb.greaterThan(root.get("endedDate").as(Date.class),
							currentTimestamp), cb.lessThan(
							root.get("startedDate").as(Date.class),
							currentTimestamp));
		}

	};
}
 
Example #20
Source File: MindVersionInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public MindVersionInfo getLatestVersionWithMind(String mindId) throws Exception {
	if( StringUtils.isEmpty( mindId ) ){
		new Exception("脑图ID为空,无法查询版本信息!");
	}
	EntityManager em = this.entityManagerContainer().get(MindVersionInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<MindVersionInfo> cq = cb.createQuery(MindVersionInfo.class);
	Root<MindVersionInfo> root = cq.from(MindVersionInfo.class);
	Predicate p = cb.equal( root.get(MindVersionInfo_.mindId) , mindId);
	cq.orderBy( cb.desc( root.get( MindVersionInfo_.updateTime ) ) );
	List<MindVersionInfo> versions = em.createQuery(cq.where(p)).setMaxResults(1).getResultList();
	if(ListTools.isNotEmpty( versions )) {
		 return versions.get(0);
	 }
	return null;
}
 
Example #21
Source File: StatisticUnitForDayFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<String> listByUnitRecordDateString(List<String> unitName, String sDate) throws Exception {
	if (unitName == null || unitName.size() == 0) {
		logger.error(new UnitNamesEmptyException());
		return null;
	}
	EntityManager em = this.entityManagerContainer().get(StatisticUnitForDay.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<StatisticUnitForDay> root = cq.from(StatisticUnitForDay.class);
	Predicate p = root.get(StatisticUnitForDay_.unitName).in(unitName);
	if (sDate == null || sDate.isEmpty()) {
		logger.error(new StatisticDateEmptyException());
	} else {
		p = cb.and(p, cb.equal(root.get(StatisticUnitForDay_.statisticDate), sDate));
	}
	cq.select(root.get(StatisticUnitForDay_.id));
	return em.createQuery(cq.where(p)).setMaxResults(62).getResultList();
}
 
Example #22
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<String> listSubjectIdsBySection( String sectionId, Integer maxResults ) throws Exception {
	if( sectionId == null || sectionId.isEmpty() ){
		throw new Exception( "sectionId is null!" );
	}
	EntityManager em = this.entityManagerContainer().get(BBSSubjectInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.equal(  root.get(BBSSubjectInfo_.sectionId), sectionId);
	cq.select( root.get(BBSSubjectInfo_.id) );
	if( maxResults == null || maxResults == 0 ){
		return em.createQuery(cq.where(p)).getResultList();
	}else{
		return em.createQuery(cq.where(p)).setMaxResults( maxResults ).getResultList();
	}
}
 
Example #23
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Long countExpiredTaskTask(Business business, DateRange dateRange, String applicationId, String processId,
		String activityId, List<String> units, String person) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<Task> root = cq.from(Task.class);
	Predicate p = cb.between(root.get(Task_.expireTime), dateRange.getStart(), dateRange.getEnd());
	if (!StringUtils.equals(applicationId, StandardJaxrsAction.EMPTY_SYMBOL)) {
		p = cb.and(p, cb.equal(root.get(Task_.application), applicationId));
	}
	if (!StringUtils.equals(processId, StandardJaxrsAction.EMPTY_SYMBOL)) {
		p = cb.and(p, cb.equal(root.get(Task_.process), processId));
	}
	if (!StringUtils.equals(activityId, StandardJaxrsAction.EMPTY_SYMBOL)) {
		p = cb.and(p, cb.equal(root.get(Task_.activity), activityId));
	}
	if (ListTools.isNotEmpty(units)) {
		p = cb.and(p, root.get(Task_.unit).in(units));
	}
	if (!StringUtils.equals(person, StandardJaxrsAction.EMPTY_SYMBOL)) {
		p = cb.and(p, cb.equal(root.get(Task_.person), person));
	}
	cq.select(cb.count(root)).where(p);
	return em.createQuery(cq).getSingleResult();
}
 
Example #24
Source File: ActionListSummary.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/** From 的 data和mobileData 数据量大,如果直接取出,会有秒级的延时 */
private Map<String, List<WoForm>> mapForm(Business business, List<String> applicationIds) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Form.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Form> root = cq.from(Form.class);
	Predicate p = root.get(Form_.application).in(applicationIds);
	cq.select(root.get(Form_.id)).where(p);
	List<String> ids = em.createQuery(cq).getResultList();
	List<Form> os = business.entityManagerContainer().fetch(ids, Form.class,
			WoForm.copier.getCopyFields());
	List<WoForm> wos = WoForm.copier.copy(os);
	Map<String, List<WoForm>> map = wos.stream().collect(Collectors.groupingBy(Form::getApplication));
	return map;
}
 
Example #25
Source File: QueryFilterChain.java    From mPass with Apache License 2.0 5 votes vote down vote up
/**
 * 加上下一个过滤器的条件一起返回
 */
public Predicate andNextFilter(QueryContext context, Predicate predicate) {
    Predicate next = toPredicate(context);
    if (predicate == null) {
        return next;
    }
    if (next == null) {
        return predicate;
    }
    return context.getBuilder().and(predicate, next);
}
 
Example #26
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected boolean idleName(Business business, Reveal view) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Reveal.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<Reveal> root = cq.from(Reveal.class);
	Predicate p = cb.equal(root.get(Reveal_.query), view.getQuery());
	p = cb.and(p, cb.equal(root.get(Reveal_.name), view.getName()));
	p = cb.and(p, cb.notEqual(root.get(Reveal_.id), view.getId()));
	return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() == 0;
}
 
Example #27
Source File: BBSConfigSettingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public BBSConfigSetting getWithConfigCode(String configCode) throws Exception {
	if( configCode == null || configCode.isEmpty() ){
		throw new Exception( "config code is null, can not find any system setting!" );
	}
	EntityManager em = this.entityManagerContainer().get(BBSConfigSetting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSConfigSetting> cq = cb.createQuery(BBSConfigSetting.class);
	Root<BBSConfigSetting> root = cq.from(BBSConfigSetting.class);
	Predicate p = cb.equal( root.get( BBSConfigSetting_.configCode ), configCode );
	List<BBSConfigSetting> valueList = em.createQuery(cq.where(p)).getResultList();
	if( valueList != null && valueList.size() > 0 ){
		return valueList.get(0);
	}
	return null;
}
 
Example #28
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listPinyinInitial(String key) throws Exception {
	String str = key.replaceAll("_", "\\\\_");
	str = str.replaceAll("%", "\\\\%");
	str = str.toLowerCase();
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.like(root.get(Meeting_.pinyinInitial), str + "%", '\\');
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example #29
Source File: TimerStartWorkUnitStubs.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private Collection<String> listUnitFromWork(Business business, DateRange dateRange) throws Exception {
	EntityManagerContainer emc = business.entityManagerContainer();
	EntityManager em = emc.get(Work.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Work> root = cq.from(Work.class);
	Predicate p = cb.between(root.get(Work_.startTime), dateRange.getStart(), dateRange.getEnd());
	cq.select(root.get(Work_.creatorUnit)).distinct(true).where(p);
	List<String> list = em.createQuery(cq).getResultList();
	return list;
}
 
Example #30
Source File: WorkFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithActivityToken(String activityToken) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Work.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Work> root = cq.from(Work.class);
	Predicate p = cb.equal(root.get(Work_.activityToken), activityToken);
	cq.select(root.get(Work_.id)).where(p);
	return em.createQuery(cq).getResultList();
}