类javax.persistence.criteria.CriteriaQuery源码实例Demo

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

源代码1 项目: o2oa   文件: PersonFactory.java
public List<String> listSubDirect(String id) throws Exception {
	List<String> list = new ArrayList<>();
	if (StringUtils.isEmpty(id)) {
		return list;
	}
	Person person = this.pick(id);
	if (null == person) {
		return list;
	}
	EntityManager em = this.entityManagerContainer().get(Person.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Person> root = cq.from(Person.class);
	Predicate p = cb.equal(root.get(Person_.superior), person.getId());
	list = em.createQuery(cq.select(root.get(Person_.id)).where(p).distinct(true)).getResultList();
	return list;
}
 
源代码2 项目: o2oa   文件: OkrWorkBaseInfoFactory.java
/**
 * 查询具体工作部署者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctDeployerIdentity( List<String> identities_ok, List<String> identities_error ) throws Exception {
	EntityManager em = this.entityManagerContainer().get( OkrWorkBaseInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrWorkBaseInfo> root = cq.from(OkrWorkBaseInfo.class);
	
	Predicate p = cb.isNotNull( root.get( OkrWorkBaseInfo_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkBaseInfo_.deployerIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkBaseInfo_.deployerIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrWorkBaseInfo_.deployerIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码3 项目: o2oa   文件: StatisticUnitForMonthFactory.java
/**
 * 根据顶层组织名称,统计年月,统计顶层组织所有人员请假人次总和
 * @param topUnitNames
 * @param cycleYear
 * @param cycleMonth
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayCountByTopUnitNamesYearAndMonth( List<String> topUnitNames, String cycleYear, String cycleMonth ) throws Exception{
	if( topUnitNames == null || topUnitNames.size() == 0 ){
		logger.error( new TopUnitNamesEmptyException() );
		return null;
	}	
	EntityManager em = this.entityManagerContainer().get( StatisticUnitForMonth.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<StatisticUnitForMonth> root = cq.from( StatisticUnitForMonth.class);		
	//查询总数
	cq.select( cb.sum( root.get(StatisticUnitForMonth_.onSelfHolidayCount) ) );		
	Predicate p = root.get(StatisticUnitForMonth_.topUnitName).in( topUnitNames );
	if( cycleYear == null || cycleYear.isEmpty() ){
		logger.error( new CycleYearEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticYear), cycleYear));
	}
	if( cycleMonth == null || cycleMonth.isEmpty() ){
		logger.error( new CycleMonthEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticMonth), cycleMonth));
	}
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
源代码4 项目: angular-rest-springsecurity   文件: JpaUserDao.java
@Override
@Transactional(readOnly = true)
public User findByName(String name)
{
    final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder();
    final CriteriaQuery<User> criteriaQuery = builder.createQuery(this.entityClass);

    Root<User> root = criteriaQuery.from(this.entityClass);
    Path<String> namePath = root.get("name");
    criteriaQuery.where(builder.equal(namePath, name));

    TypedQuery<User> typedQuery = this.getEntityManager().createQuery(criteriaQuery);
    List<User> users = typedQuery.getResultList();

    if (users.isEmpty()) {
        return null;
    }

    return users.iterator().next();
}
 
源代码5 项目: tutorials   文件: ApplicationView.java
public String[] nullCriteria() {
    final Session session = HibernateUtil.getHibernateSession();
    final CriteriaBuilder cb = session.getCriteriaBuilder();
    final CriteriaQuery<Item> cr = cb.createQuery(Item.class);
    final Root<Item> root = cr.from(Item.class);
    cr.select(root)
        .where(cb.isNull(root.get("itemDescription")));
    // cr.add(Restrictions.isNull("itemDescription"));
    Query<Item> query = session.createQuery(cr);
    final List<Item> nullItemsList = query.getResultList();
    final String nullDescItems[] = new String[nullItemsList.size()];
    for (int i = 0; i < nullItemsList.size(); i++) {
        nullDescItems[i] = nullItemsList.get(i)
            .getItemName();
    }
    session.close();
    return nullDescItems;
}
 
源代码6 项目: 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(Review.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<Review> root = cq.from(Review.class);
		Predicate p = cb.equal(root.get(Review_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		List<Wo> wos = emc.fetchDescPaging(Review.class, Wo.copier, p, page, size, Review.sequence_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(Review.class, p));
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
源代码7 项目: o2oa   文件: ReviewFactory.java
public List<String> checkTaskIdsWithPermission(List<String> taskIds, String personName) throws Exception {
	if( ListTools.isEmpty( taskIds ) ) {
		throw new Exception("taskIds can not be empty!");
	}
	if( StringUtils.isEmpty( personName ) ) {
		throw new Exception("personName can not be empty!");
	}
	EntityManager em = this.entityManagerContainer().get( Review.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<Review> root = cq.from( Review.class );
	Predicate p = cb.equal( root.get( Review_.permissionObj ), personName );
	p = cb.and( p, root.get( Review_.taskId ).in( taskIds ));
	p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
	cq.select(root.get( Review_.taskId)).where(p);
	return em.createQuery( cq ).getResultList();
}
 
源代码8 项目: o2oa   文件: FileInfoFactory.java
/**
 * 列示指定文档的所有云文件图片信息ID列表
 * @param doucmentId 指定的文档ID
 * @return
 * @throws Exception 
 */
//@MethodDescribe("列示指定文档的所有云文件图片信息ID列表")
public List<String> listCloudPictureByDocument(String documentId) throws Exception {
	if( StringUtils.isEmpty(documentId) ){
		throw new Exception("内容管理listByDocument方法不接受document为空的查询操作!");
	}		
	EntityManager em = this.entityManagerContainer().get( FileInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<FileInfo> root = cq.from( FileInfo.class );		
	Predicate p = cb.equal(root.get( FileInfo_.documentId ), documentId);
	p = cb.and( p, cb.equal(root.get( FileInfo_.fileExtType ), "PICTURE") );
	p = cb.and( p, cb.equal(root.get( FileInfo_.fileType ), "CLOUD") );
	cq.select(root.get(FileInfo_.id));
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码9 项目: o2oa   文件: OkrWorkPersonFactory.java
public Long getOvertimenessWorkCountByCenterId(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));
	p = cb.and(p, cb.isFalse(root.get(OkrWorkPerson_.isOverTime)));
	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();
}
 
源代码10 项目: o2oa   文件: AttendanceDetailStatisticFactory.java
/**
 * 根据员工,打卡日期月,统计请假天数
 * @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();
}
 
源代码11 项目: herd   文件: SecurityRoleDaoImpl.java
@Override
public SecurityRoleEntity getSecurityRoleByName(String securityRoleName)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SecurityRoleEntity> criteria = builder.createQuery(SecurityRoleEntity.class);

    // The criteria root is the security role.
    Root<SecurityRoleEntity> securityRoleEntity = criteria.from(SecurityRoleEntity.class);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(securityRoleEntity.get(SecurityRoleEntity_.code)), securityRoleName.toUpperCase()));

    // Add the clauses for the query.
    criteria.select(securityRoleEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    return executeSingleResultQuery(criteria,
        String.format("Found more than one security role with parameters {securityRoleName=\"%s\"}.", securityRoleName));
}
 
源代码12 项目: herd   文件: SecurityFunctionDaoImpl.java
@Override
public SecurityFunctionEntity getSecurityFunctionByName(String securityFunctionName)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SecurityFunctionEntity> criteria = builder.createQuery(SecurityFunctionEntity.class);

    // The criteria root is the security role function.
    Root<SecurityFunctionEntity> securityFunctionEntity = criteria.from(SecurityFunctionEntity.class);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(securityFunctionEntity.get(SecurityFunctionEntity_.code)), securityFunctionName.toUpperCase()));

    // Add the clauses for the query.
    criteria.select(securityFunctionEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    return executeSingleResultQuery(criteria,
        String.format("Found more than one security function with parameters {securityFunctionName=\"%s\"}.", securityFunctionName));
}
 
源代码13 项目: o2oa   文件: ActionListWithIdentityObject.java
private List<Wo> list(Business business, Wi wi) throws Exception {
	List<Wo> wos = new ArrayList<>();
	List<Identity> os = business.identity().pick(wi.getIdentityList());
	List<String> ids = ListTools.extractProperty(os, JpaObject.id_FIELDNAME, String.class, true, true);
	EntityManager em = business.entityManagerContainer().get(Identity.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Identity> root = cq.from(Identity.class);
	Predicate p = root.get(Identity_.id).in(ids);
	List<String> unitIds = em.createQuery(cq.select(root.get(Identity_.unit)).where(p).distinct(true))
			.getResultList();
	unitIds = ListTools.trim(unitIds, true, true);
	for (Unit o : business.unit().pick(unitIds)) {
		wos.add(this.convert(business, o, Wo.class));
	}
	return wos;
}
 
源代码14 项目: o2oa   文件: ActionFilterAttribute.java
private List<NameValueCountPair> listActivityName(Business business, EffectivePerson effectivePerson,
		Application application) throws Exception {
	List<NameValueCountPair> wos = new ArrayList<>();
	EntityManager em = business.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_.application), application.getId());
	p = cb.and(p, cb.equal(root.get(Work_.creatorPerson), effectivePerson.getDistinguishedName()));
	cq.select(root.get(Work_.activityName)).where(p).distinct(true);
	List<String> list = em.createQuery(cq).getResultList();
	for (String str : list) {
		NameValueCountPair o = new NameValueCountPair();
		o.setValue(str);
		o.setName(str);
		wos.add(o);
	}
	SortTools.asc(wos, "name");
	return wos;
}
 
源代码15 项目: o2oa   文件: ActionFilterAttribute.java
private List<NameValueCountPair> listStartTimeMonthPair(Business business, EffectivePerson effectivePerson)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Predicate p = cb.equal(root.get(TaskCompleted_.person), effectivePerson.getDistinguishedName());
	p = cb.and(p,
			cb.or(cb.equal(root.get(TaskCompleted_.latest), true), cb.isNull(root.get(TaskCompleted_.latest))));
	cq.select(root.get(TaskCompleted_.startTimeMonth)).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.desc(wos, "name");
	return wos;
}
 
源代码16 项目: o2oa   文件: RestoreData.java
private <T> void clean(Class<T> cls, EntityManager em) throws Exception {
	List<T> list = null;
	do {
		if (ListTools.isNotEmpty(list)) {
			em.getTransaction().begin();
			for (T t : list) {
				em.remove(t);
			}
			em.getTransaction().commit();
		}
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<T> cq = cb.createQuery(cls);
		Root<T> root = cq.from(cls);
		cq.select(root);
		list = em.createQuery(cq).setMaxResults(Config.dumpRestoreData().getBatchSize()).getResultList();
	} while (ListTools.isNotEmpty(list));
}
 
private List<String> people(Business business, Wi wi) throws Exception {
	List<Unit> os = business.unit().pick(wi.getUnitList());
	List<String> unitIds = new ArrayList<>();
	for (Unit o : os) {
		unitIds.add(o.getId());
		unitIds.addAll(business.unit().listSubNested(o.getId()));
	}
	unitIds = ListTools.trim(unitIds, true, true);
	EntityManager em = business.entityManagerContainer().get(Identity.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Identity> root = cq.from(Identity.class);
	Predicate p = root.get(Identity_.unit).in(unitIds);
	List<String> list = em.createQuery(cq.select(root.get(Identity_.person)).where(p).distinct(true))
			.getResultList();
	return list;
}
 
源代码18 项目: o2oa   文件: OkrWorkReportProcessLogFactory.java
/**
 * 查询工作汇报处理者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctProcessorIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkReportProcessLog.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrWorkReportProcessLog> root = cq.from(OkrWorkReportProcessLog.class);
	Predicate p = cb.isNotNull( root.get( OkrWorkReportProcessLog_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkReportProcessLog_.processorIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkReportProcessLog_.processorIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrWorkReportProcessLog_.processorIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码19 项目: o2oa   文件: OkrWorkPersonFactory.java
public Long getCompletedWorkCountByCenterId(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));
	p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.workProcessStatus), "已完成"));
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	// 查询总数
	cq.select(cb.count(root));
	// logger.info( ">>>>getCompletedWorkCountByCenterId-SQL:" +
	// em.createQuery(cq.where(p)).toString() );
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
源代码20 项目: HibernateTips   文件: TestCriteriaConstructor.java
@Test
public void selectPojo() {
	log.info("... selectPojo ...");

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

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<AuthorValue> q = cb.createQuery(AuthorValue.class);
	Root<Author> root = q.from(Author.class);
	q.select(cb.construct(AuthorValue.class, root.get(Author_.firstName), root.get(Author_.lastName)));

	TypedQuery<AuthorValue> query = em.createQuery(q);
	List<AuthorValue> authors = query.getResultList();

	for (AuthorValue author : authors) {
		log.info(author.getFirstName() + " "
				+ author.getLastName());
	}

	em.getTransaction().commit();
	em.close();
}
 
源代码21 项目: o2oa   文件: OkrConfigSystemFactory.java
public String getValueWithConfigCode(String configCode) throws Exception {
	if( configCode == null || configCode.isEmpty() ){
		throw new Exception( "config code is null, can not find any system config!" );
	}
	EntityManager em = this.entityManagerContainer().get(OkrConfigSystem.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrConfigSystem> root = cq.from(OkrConfigSystem.class);
	Predicate p = cb.equal( root.get( OkrConfigSystem_.configCode ), configCode );
	cq.select(root.get(OkrConfigSystem_.configValue));
	//System.out.println("SQL:" + em.createQuery(cq.where(p)).toString() );
	List<String> valueList = em.createQuery(cq.where(p)).getResultList();
	if( valueList != null && valueList.size() > 0 ){
		//System.out.println("valueList.get(0):" + valueList.get(0) );
		return valueList.get(0);
	}
	return null;
}
 
源代码22 项目: o2oa   文件: OkrConfigSecretaryFactory.java
/**
 * 查询秘书代理领导身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctLeaderIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrConfigSecretary.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrConfigSecretary> root = cq.from(OkrConfigSecretary.class);
	
	Predicate p = cb.isNotNull( root.get( OkrConfigSecretary_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrConfigSecretary_.leaderIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrConfigSecretary_.leaderIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrConfigSecretary_.leaderIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码23 项目: o2oa   文件: AttendanceDetailStatisticFactory.java
/**
 * 根据顶层组织,打卡日期月,统计请假天数
 * @param topUnitNames
 * @param recordDate
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayDaysByTopUnitAndDate( List<String> topUnitNames, String recordDate ) throws Exception{
	if( topUnitNames == null || topUnitNames.size() == 0 ){
		logger.error( new TopUnitNamesEmptyException() );
		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_.topUnitName ).in( topUnitNames );
	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();
}
 
源代码24 项目: o2oa   文件: Attachment2Factory.java
public List<Attachment2> listWithFolder2(String folder, String status) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Attachment2.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Attachment2> cq = cb.createQuery(Attachment2.class);
	Root<Attachment2> root = cq.from(Attachment2.class);
	Predicate p = cb.equal(root.get(Attachment2_.folder), folder);
	if(StringUtils.isNotEmpty(status)){
		p = cb.and(p, cb.equal(root.get(Attachment2_.status), status));
	}
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码25 项目: o2oa   文件: TimerCategory.java
private Long countTaskCompleted(Business business, Date start, ApplicationStub applicationStub) throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Predicate p = cb.greaterThan(root.get(TaskCompleted_.startTime), start);
	p = cb.and(p, cb.equal(root.get(TaskCompleted_.application), applicationStub.getValue()));
	cq.select(cb.count(root)).where(p);
	return em.createQuery(cq).getSingleResult();
}
 
源代码26 项目: herd   文件: DataProviderDaoImpl.java
@Override
public List<DataProviderKey> getDataProviders()
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);

    // The criteria root is the data provider.
    Root<DataProviderEntity> dataProviderEntity = criteria.from(DataProviderEntity.class);

    // Get the columns.
    Path<String> dataProviderNameColumn = dataProviderEntity.get(DataProviderEntity_.name);

    // Add the select clause.
    criteria.select(dataProviderNameColumn);

    // Add the order by clause.
    criteria.orderBy(builder.asc(dataProviderNameColumn));

    // Run the query to get a list of data provider names back.
    List<String> dataProviderNames = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned data provider names.
    List<DataProviderKey> dataProviderKeys = new ArrayList<>();
    for (String dataProviderName : dataProviderNames)
    {
        dataProviderKeys.add(new DataProviderKey(dataProviderName));
    }

    return dataProviderKeys;
}
 
源代码27 项目: o2oa   文件: OkrWorkPersonFactory.java
public List<String> listAll() 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);
	cq.select(root.get(OkrWorkPerson_.id));
	return em.createQuery(cq).getResultList();
}
 
源代码28 项目: o2oa   文件: AppInfoFactory.java
public List<String> listByAppName(String appName) throws Exception {
	EntityManager em = this.entityManagerContainer().get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	Predicate p = cb.equal(root.get(AppInfo_.appName), appName);
	cq.select(root.get(AppInfo_.id));
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码29 项目: o2oa   文件: ProjectGroupFactory.java
/**
 * 根据用户列示ProjectGroup实体信息列表
 * @param person
 * @return
 * @throws Exception
 */
public List<String> listByPerson( String person ) throws Exception {
	if( StringUtils.isEmpty( person ) ){
		throw new Exception("person can not be empty!");
	}
	EntityManager em = this.entityManagerContainer().get(ProjectGroup.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<ProjectGroup> root = cq.from(ProjectGroup.class);
	Predicate p = cb.equal( root.get(ProjectGroup_.owner), person );
	cq.select( root.get(ProjectGroup_.id ) );
	return em.createQuery(cq.where(p)).getResultList();
}
 
源代码30 项目: o2oa   文件: ViewFactory.java
public List<View> listWithQueryObject(String queryId) throws Exception {
	EntityManager em = this.entityManagerContainer().get(View.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<View> cq = cb.createQuery(View.class);
	Root<View> root = cq.from(View.class);
	Predicate p = cb.equal(root.get(View_.query), queryId);
	cq.select(root).where(p);
	List<View> os = em.createQuery(cq).getResultList();
	return os;
}
 
 类所在包
 同包方法