Java Code Examples for javax.persistence.criteria.CriteriaQuery

The following examples show how to use javax.persistence.criteria.CriteriaQuery. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: o2oa   Source File: PersonFactory.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
/**
 * 查询具体工作部署者身份列表(去重复)
 * @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();
}
 
Example 3
/**
 * 根据顶层组织名称,统计年月,统计顶层组织所有人员请假人次总和
 * @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();
}
 
Example 4
Source Project: angular-rest-springsecurity   Source File: JpaUserDao.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 5
Source Project: tutorials   Source File: ApplicationView.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example 6
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;
	}
}
 
Example 7
Source Project: o2oa   Source File: ReviewFactory.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 8
Source Project: o2oa   Source File: FileInfoFactory.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 列示指定文档的所有云文件图片信息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();
}
 
Example 9
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();
}
 
Example 10
/**
 * 根据员工,打卡日期月,统计请假天数
 * @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 11
Source Project: herd   Source File: SecurityRoleDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 12
Source Project: herd   Source File: SecurityFunctionDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 13
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;
}
 
Example 14
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;
}
 
Example 15
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;
}
 
Example 16
Source Project: o2oa   Source File: RestoreData.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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));
}
 
Example 17
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;
}
 
Example 18
/**
 * 查询工作汇报处理者身份列表(去重复)
 * @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();
}
 
Example 19
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();
}
 
Example 20
Source Project: HibernateTips   Source File: TestCriteriaConstructor.java    License: MIT License 6 votes vote down vote up
@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();
}
 
Example 21
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;
}
 
Example 22
/**
 * 查询秘书代理领导身份列表(去重复)
 * @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();
}
 
Example 23
/**
 * 根据顶层组织,打卡日期月,统计请假天数
 * @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();
}
 
Example 24
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();
}
 
Example 25
Source Project: o2oa   Source File: TimerCategory.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 26
Source Project: herd   Source File: DataProviderDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 27
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();
}
 
Example 28
Source Project: o2oa   Source File: AppInfoFactory.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 29
/**
 * 根据用户列示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();
}
 
Example 30
Source Project: o2oa   Source File: ViewFactory.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}