Java Code Examples for javax.persistence.criteria.CriteriaBuilder#not()
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#not() .
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: CleanupOauthCode.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private void removeExpired(EntityManagerContainer emc) throws Exception { EntityManager em = emc.get(OauthCode.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<OauthCode> root = cq.from(OauthCode.class); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -15); Predicate p = cb.not(cb.greaterThan(root.get(OauthCode_.createTime), cal.getTime())); cq.select(root.get(OauthCode_.id)).where(p); List<String> list = em.createQuery(cq).getResultList(); for (int i = 0; i < list.size(); i++) { if (i % 100 == 0) { emc.beginTransaction(OauthCode.class); } OauthCode o = emc.find(list.get(i), OauthCode.class); emc.remove(o); if ((i % 100 == 99) || (i == (list.size() - 1))) { emc.commit(); } } }
Example 2
Source File: CleanupPromptErrorLog.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
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 3
Source File: CleanupWarnLog.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private void cleanupWarnLog() throws Exception { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { EntityManager em = emc.get(WarnLog.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<WarnLog> root = cq.from(WarnLog.class); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -7); Predicate p = cb.not(cb.greaterThan(root.get(WarnLog_.createTime), cal.getTime())); cq.select(root.get(WarnLog_.id)).where(p); List<String> list = em.createQuery(cq).getResultList(); for (int i = 0; i < list.size(); i++) { if (i % 100 == 0) { emc.beginTransaction(WarnLog.class); } WarnLog o = emc.find(list.get(i), WarnLog.class); emc.remove(o); if ((i % 100 == 99) || (i == (list.size() - 1))) { emc.commit(); } } } }
Example 4
Source File: ActionProcessOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<String> listOrphanProcess(Business business, List<String> applicationIds) throws Exception { EntityManager em = business.entityManagerContainer().get(Process.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Process> root = cq.from(Process.class); Predicate p = cb.not(root.get(Process_.application).in(applicationIds)); cq.select(root.get(Process_.id)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 5
Source File: BranchSpecification.java From mojito with Apache License 2.0 | 5 votes |
public static SingleParamSpecification<Branch> branchStatisticTranslated(final Boolean translated) { return new SingleParamSpecification<Branch>(translated) { @Override public Predicate toPredicate(Root<Branch> root, CriteriaQuery<?> query, CriteriaBuilder builder) { Join<Branch, BranchStatistic> branchStatisticJoin = root.join(Branch_.branchStatistic, JoinType.LEFT); Predicate predicate = builder.equal(branchStatisticJoin.get(BranchStatistic_.forTranslationCount), 0L); if (!translated) { predicate = builder.not(predicate); } return predicate; } }; }
Example 6
Source File: ActionCover.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private <T extends JpaObject, W extends JpaObject> List<T> orphanProcessElement(Business business, List<W> list, Class<T> cls, String processId) throws Exception { EntityManager em = business.entityManagerContainer().get(cls); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(cls); Root<T> root = cq.from(cls); Predicate p = cb.not(root.get(JpaObject.id_FIELDNAME) .in(ListTools.extractProperty(list, JpaObject.id_FIELDNAME, String.class, true, true))); p = cb.and(p, cb.equal(root.get("process"), processId)); cq.select(root).where(p); return em.createQuery(cq).getResultList(); }
Example 7
Source File: ActionCover.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private <T extends JpaObject, W extends JpaObject> List<T> orphanFormElement(Business business, List<W> list, Class<T> cls, String formId) throws Exception { EntityManager em = business.entityManagerContainer().get(cls); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(cls); Root<T> root = cq.from(cls); Predicate p = cb.not(root.get(JpaObject.id_FIELDNAME) .in(ListTools.extractProperty(list, JpaObject.id_FIELDNAME, String.class, true, true))); p = cb.and(p, cb.equal(root.get(FormField.form_FIELDNAME), formId)); cq.select(root).where(p); return em.createQuery(cq).getResultList(); }
Example 8
Source File: ActionScriptOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<String> listOrphanScript(Business business, List<String> applicationIds) throws Exception { EntityManager em = business.entityManagerContainer().get(Script.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Script> root = cq.from(Script.class); Predicate p = cb.not(root.get(Script_.application).in(applicationIds)); cq.select(root.get(Script_.id)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 9
Source File: RdbmsUtils.java From modeldb with Apache License 2.0 | 5 votes |
private static Predicate getFuzzyUsersQueryPredicate( AuthService authService, CriteriaBuilder builder, Root<?> entityRootPath, KeyValueQuery requestedPredicate) { if (requestedPredicate.getValue().getKindCase().equals(Value.KindCase.STRING_VALUE)) { Operator operator = requestedPredicate.getOperator(); UserInfoPaginationDTO userInfoPaginationDTO = authService.getFuzzyUserInfoList(requestedPredicate.getValue().getStringValue()); List<UserInfo> userInfoList = userInfoPaginationDTO.getUserInfoList(); if (userInfoList != null && !userInfoList.isEmpty()) { Expression<String> exp = entityRootPath.get(requestedPredicate.getKey()); List<String> vertaIds = userInfoList.stream() .map(authService::getVertaIdFromUserInfo) .collect(Collectors.toList()); if (operator.equals(Operator.NOT_CONTAIN) || operator.equals(Operator.NE)) { return builder.not(exp.in(vertaIds)); } else { return exp.in(vertaIds); } } } else { Status invalidValueTypeError = Status.newBuilder() .setCode(Code.INVALID_ARGUMENT_VALUE) .setMessage("Predicate for the owner search only supporting 'String' value") .build(); throw StatusProto.toStatusRuntimeException(invalidValueTypeError); } return null; }
Example 10
Source File: ActionFormOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<String> listOrphanForm(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 = cb.not(root.get(Form_.application).in(applicationIds)); cq.select(root.get(Form_.id)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 11
Source File: ActionApplicationDictOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<String> listOrphanApplicationDictItem(Business business, List<String> applicationDictIds) throws Exception { EntityManager em = business.entityManagerContainer().get(ApplicationDictItem.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<ApplicationDictItem> root = cq.from(ApplicationDictItem.class); Predicate p = cb.not(root.get(ApplicationDictItem_.bundle).in(applicationDictIds)); cq.select(root.get(ApplicationDictItem_.id)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 12
Source File: ActionApplicationDictOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<String> listOrphanApplicationDict(Business business, List<String> applicationIds) throws Exception { EntityManager em = business.entityManagerContainer().get(ApplicationDict.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<ApplicationDict> root = cq.from(ApplicationDict.class); Predicate p = cb.not(root.get(ApplicationDict_.application).in(applicationIds)); cq.select(root.get(ApplicationDict_.id)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 13
Source File: ActionProcessOrphan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private <T extends JpaObject, W> List<String> listOrphanProcessElement(Business business, List<String> processIds, WrapCopier<T, W> copier) throws Exception { EntityManager em = business.entityManagerContainer().get(copier.getOrigClass()); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<T> root = cq.from(copier.getOrigClass()); Predicate p = cb.not(root.get(Agent.process_FIELDNAME).in(processIds)); cq.select(root.get(JpaObject.id_FIELDNAME)).where(p).distinct(true); return em.createQuery(cq).getResultList(); }
Example 14
Source File: NotLike.java From specification-arg-resolver with Apache License 2.0 | 4 votes |
@Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { return builder.not(builder.like(this.<String>path(root), pattern)); }
Example 15
Source File: AppInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 根据权限查询用户可以发布文档的栏目ID列表(检测allPeoplePublish ) * * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds * - 栏目ID的最大范围 * @param excludAppInfoIds * - 需要排队的栏目ID * @return * @throws Exception */ public List<String> listPublishableAppInfoIds(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> excludAppInfoIds, String documentType, Integer maxCount) 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 = null; Predicate p_filter = null; // 限定范围 if (ListTools.isNotEmpty(inAppInfoIds)) { p_filter = root.get(AppInfo_.id).in(inAppInfoIds); } // 排队指定的ID列表 if (ListTools.isNotEmpty(excludAppInfoIds)) { if (p_filter == null) { p_filter = cb.not(root.get(AppInfo_.id).in(excludAppInfoIds)); } else { p_filter = cb.and(p_filter, cb.not(root.get(AppInfo_.id).in(excludAppInfoIds))); } } Predicate p_permission = null; p_permission = cb.isTrue(root.get(AppInfo_.allPeoplePublish)); if (StringUtils.isNotEmpty(personName)) { // 可以管理的栏目,肯定可以发布信息 p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.manageablePersonList))); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.publishablePersonList))); } if (ListTools.isNotEmpty(unitNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableUnitList).in(unitNames)); } if (ListTools.isNotEmpty(groupNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableGroupList).in(groupNames)); } // 使用新的条件将两个条件组合起来 if (p_filter != null) { p = p_filter; } if (p != null) { if (p_permission != null) { p = cb.and(p, p_permission); } } else { if (p_permission != null) { p = p_permission; } } if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and(p, cb.equal(root.get(AppInfo_.documentType), documentType)); } cq.select(root.get(AppInfo_.id)); return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList(); }
Example 16
Source File: AppInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 查询用户有权限访问的所有栏目ID列表(检测allPeopleView 和 allPeoplePublish ) * * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds * @param excludAppInfoIds * @return * @throws Exception */ public List<String> listViewableAppInfoIds(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> excludAppInfoIds, String documentType, Integer maxCount) 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 = null; Predicate p_filter = null; // 限定范围 if (ListTools.isNotEmpty(inAppInfoIds)) { p_filter = root.get(AppInfo_.id).in(inAppInfoIds); } // 排队指定的ID列表 if (ListTools.isNotEmpty(excludAppInfoIds)) { if (p_filter == null) { p_filter = cb.not(root.get(AppInfo_.id).in(excludAppInfoIds)); } else { p_filter = cb.and(p_filter, cb.not(root.get(AppInfo_.id).in(excludAppInfoIds))); } } Predicate p_permission = null; p_permission = cb.isTrue(root.get(AppInfo_.allPeopleView)); p_permission = cb.or(p_permission, cb.isTrue(root.get(AppInfo_.allPeoplePublish))); if (StringUtils.isNotEmpty(personName)) { // 可以管理的栏目,肯定可以发布信息 p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.manageablePersonList))); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.publishablePersonList))); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.viewablePersonList))); } if (ListTools.isNotEmpty(unitNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableUnitList).in(unitNames)); p_permission = cb.or(p_permission, root.get(AppInfo_.viewableUnitList).in(unitNames)); } if (ListTools.isNotEmpty(groupNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableGroupList).in(groupNames)); p_permission = cb.or(p_permission, root.get(AppInfo_.viewableGroupList).in(groupNames)); } // 使用新的条件将两个条件组合起来 if (p_filter != null) { p = p_filter; } if (p != null) { if (p_permission != null) { p = cb.and(p, p_permission); } } else { if (p_permission != null) { p = p_permission; } } if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and(p, cb.equal(root.get(AppInfo_.documentType), documentType)); } cq.select(root.get(AppInfo_.id)); return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList(); }
Example 17
Source File: AppInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 查询用户有权限访问的所有栏目ID列表(不检测allPeopleView) * * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds * @param excludAppInfoIds * @return * @throws Exception */ public List<String> listViewableAppIdsInPermission(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> excludAppInfoIds, String documentType, Integer maxCount) 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 = null; Predicate p_filter = null; // 限定范围 if (ListTools.isNotEmpty(inAppInfoIds)) { p_filter = root.get(AppInfo_.id).in(inAppInfoIds); } // 排队指定的ID列表 if (ListTools.isNotEmpty(excludAppInfoIds)) { if (p_filter == null) { p_filter = cb.not(root.get(AppInfo_.id).in(excludAppInfoIds)); } else { p_filter = cb.and(p_filter, cb.not(root.get(AppInfo_.id).in(excludAppInfoIds))); } } Predicate p_permission = null; if (StringUtils.isNotEmpty(personName)) { // 可以管理的栏目,肯定可以发布信息 p_permission = cb.isMember(personName, root.get(AppInfo_.manageablePersonList)); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.publishablePersonList))); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.viewablePersonList))); } if (ListTools.isNotEmpty(unitNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableUnitList).in(unitNames)); p_permission = cb.or(p_permission, root.get(AppInfo_.viewableUnitList).in(unitNames)); } if (ListTools.isNotEmpty(groupNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableGroupList).in(groupNames)); p_permission = cb.or(p_permission, root.get(AppInfo_.viewableGroupList).in(groupNames)); } // 使用新的条件将两个条件组合起来 if (p_filter != null) { p = p_filter; } if (p != null) { if (p_permission != null) { p = cb.and(p, p_permission); } } else { if (p_permission != null) { p = p_permission; } } if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and(p, cb.equal(root.get(AppInfo_.documentType), documentType)); } cq.select(root.get(AppInfo_.id)); return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList(); }
Example 18
Source File: CategoryInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 根据权限查询用户可以发布文档的分类ID列表(根据权限, 不检测allPeopleView和allPeoplePublish) * 可管理的分类也属于可发布的分类 * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds - 需要限定的栏目ID列表 * @param inCategoryIds - 栏目ID的最大范围 * @param excludCategoryIds - 需要排除的栏目ID * @return * @throws Exception */ public List<String> listPublishableCategoryInfoIdsWithPermission(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> inCategoryIds, List<String> excludCategoryIds, String documentType, Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get(CategoryInfo.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<CategoryInfo> root = cq.from(CategoryInfo.class); Predicate p = null; Predicate p_filter = null; //限定栏目范围 if( ListTools.isNotEmpty( inAppInfoIds )) { p_filter = root.get( CategoryInfo_.appId ).in( inAppInfoIds ); } //限定范围 if( ListTools.isNotEmpty( inCategoryIds )) { if( p_filter == null ) { p_filter = root.get( CategoryInfo_.id ).in( inCategoryIds ); }else { p_filter = cb.and( p_filter, root.get( CategoryInfo_.id ).in( inCategoryIds )); } } //排除指定的ID列表 if( ListTools.isNotEmpty( excludCategoryIds )) { if( p_filter == null ) { p_filter = cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds )); }else { p_filter = cb.and( p_filter, cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds ))); } } Predicate p_permission = null; if( StringUtils.isNotEmpty( personName )) { //可以管理的栏目,肯定可以发布信息 p_permission = cb.isMember( personName, root.get( CategoryInfo_.manageablePersonList )); p_permission = cb.or( p_permission, cb.isMember( personName, root.get( CategoryInfo_.publishablePersonList ))); } if( ListTools.isNotEmpty( unitNames )) { if( p_permission == null ) { p_permission = root.get( CategoryInfo_.publishableUnitList).in(unitNames); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableUnitList).in(unitNames)); } } if( ListTools.isNotEmpty( groupNames )) { if( p_permission == null ) { p_permission = root.get( CategoryInfo_.publishableGroupList).in(groupNames); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableGroupList).in(groupNames)); } } //使用新的条件将两个条件组合起来 if( p_filter != null ) { p = p_filter; } if( p != null ) { if( p_permission != null ) { p = cb.and(p, p_permission); } }else { if( p_permission != null ) { p = p_permission; } } if( StringUtils.isNotEmpty( documentType) && !"全部".equals(documentType)&& !"all".equalsIgnoreCase(documentType)) { p = cb.and( p, cb.equal( root.get( CategoryInfo_.documentType), documentType)); } cq.select(root.get( CategoryInfo_.id )); return em.createQuery( cq.where( p ) ).setMaxResults(maxCount).getResultList(); }
Example 19
Source File: CategoryInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 根据权限查询用户可以访问文档的分类ID列表(根据权限, 不检测allPeopleView和allPeoplePublish) * 可发布、可管理的分类也属于可见分类 * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds - 需要限定的栏目ID列表 * @param inCategoryIds - 栏目ID的最大范围 * @param excludCategoryIds - 需要排除的栏目ID * @return * @throws Exception */ public List<String> listViewableCategoryInfoIdsWithPermission(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> inCategoryIds, List<String> excludCategoryIds, String documentType, Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get(CategoryInfo.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<CategoryInfo> root = cq.from(CategoryInfo.class); Predicate p = null; Predicate p_filter = null; //限定栏目范围 if( ListTools.isNotEmpty( inAppInfoIds )) { p_filter = root.get( CategoryInfo_.appId ).in( inAppInfoIds ); } //限定范围 if( ListTools.isNotEmpty( inCategoryIds )) { if( p_filter == null ) { p_filter = root.get( CategoryInfo_.id ).in( inCategoryIds ); }else { p_filter = cb.and( p_filter, root.get( CategoryInfo_.id ).in( inCategoryIds )); } } //排除指定的ID列表 if( ListTools.isNotEmpty( excludCategoryIds )) { if( p_filter == null ) { p_filter = cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds )); }else { p_filter = cb.and( p_filter, cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds ))); } } Predicate p_permission = null; if( StringUtils.isNotEmpty( personName )) { //可以管理的栏目,肯定可以发布信息 p_permission = cb.isMember( personName, root.get( CategoryInfo_.manageablePersonList )); p_permission = cb.or( p_permission, cb.isMember( personName, root.get( CategoryInfo_.publishablePersonList ))); } if( ListTools.isNotEmpty( unitNames )) { if( p_permission == null ){ p_permission = root.get( CategoryInfo_.publishableUnitList).in(unitNames); p_permission = cb.or( p_permission, root.get( CategoryInfo_.viewableUnitList).in(unitNames)); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableUnitList).in(unitNames)); p_permission = cb.or( p_permission, root.get( CategoryInfo_.viewableUnitList).in(unitNames)); } } if( ListTools.isNotEmpty( groupNames )) { if( p_permission == null ){ p_permission = root.get( CategoryInfo_.publishableGroupList).in(groupNames); p_permission = cb.or( p_permission, root.get( CategoryInfo_.viewableGroupList).in(groupNames)); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableGroupList).in(groupNames)); p_permission = cb.or( p_permission, root.get( CategoryInfo_.viewableGroupList).in(groupNames)); } } //使用新的条件将两个条件组合起来 if( p_filter != null ) { p = p_filter; } if( p != null ) { if( p_permission != null ) { p = cb.and(p, p_permission); } }else { if( p_permission != null ) { p = p_permission; } } if( StringUtils.isNotEmpty( documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and( p, cb.equal( root.get( CategoryInfo_.documentType), documentType)); } cq.select(root.get( CategoryInfo_.id )); return em.createQuery( cq.where( p ) ).setMaxResults(maxCount).getResultList(); }
Example 20
Source File: GenericRsqlSpecification.java From tutorials with MIT License | 4 votes |
@Override public Predicate toPredicate(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { final List<Object> args = castArguments(root); final Object argument = args.get(0); switch (RsqlSearchOperation.getSimpleOperator(operator)) { case EQUAL: { if (argument instanceof String) { return builder.like(root.get(property), argument.toString().replace('*', '%')); } else if (argument == null) { return builder.isNull(root.get(property)); } else { return builder.equal(root.get(property), argument); } } case NOT_EQUAL: { if (argument instanceof String) { return builder.notLike(root.<String> get(property), argument.toString().replace('*', '%')); } else if (argument == null) { return builder.isNotNull(root.get(property)); } else { return builder.notEqual(root.get(property), argument); } } case GREATER_THAN: { return builder.greaterThan(root.<String> get(property), argument.toString()); } case GREATER_THAN_OR_EQUAL: { return builder.greaterThanOrEqualTo(root.<String> get(property), argument.toString()); } case LESS_THAN: { return builder.lessThan(root.<String> get(property), argument.toString()); } case LESS_THAN_OR_EQUAL: { return builder.lessThanOrEqualTo(root.<String> get(property), argument.toString()); } case IN: return root.get(property).in(args); case NOT_IN: return builder.not(root.get(property).in(args)); } return null; }