Java Code Examples for org.hibernate.criterion.Restrictions#and()
The following examples show how to use
org.hibernate.criterion.Restrictions#and() .
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: DefaultPullRequestManager.java From onedev with MIT License | 6 votes |
@Sessional @Override public Map<ProjectAndBranch, PullRequest> findEffectives(ProjectAndBranch target, Collection<ProjectAndBranch> sources) { EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class); Collection<Criterion> criterions = new ArrayList<>(); for (ProjectAndBranch source: sources) { Criterion merged = Restrictions.and( Restrictions.eq(PullRequest.PROP_CLOSE_INFO + "." + CloseInfo.PROP_STATUS, CloseInfo.Status.MERGED), Restrictions.eq(PullRequest.PROP_LAST_MERGE_PREVIEW + "." + MergePreview.PROP_HEAD_COMMIT_HASH, source.getObjectName())); criterions.add(Restrictions.and(ofTarget(target), ofSource(source), Restrictions.or(ofOpen(), merged))); } criteria.add(Restrictions.or(criterions.toArray(new Criterion[0]))); Map<ProjectAndBranch, PullRequest> requests = new HashMap<>(); for(PullRequest request: query(criteria)) requests.put(new ProjectAndBranch(request.getSourceProject(), request.getSourceBranch()), request); return requests; }
Example 2
Source File: DefaultPullRequestManager.java From onedev with MIT License | 5 votes |
@Sessional @Override public PullRequest findEffective(ProjectAndBranch target, ProjectAndBranch source) { EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class); Criterion merged = Restrictions.and( Restrictions.eq(PullRequest.PROP_CLOSE_INFO + "." + CloseInfo.PROP_STATUS, CloseInfo.Status.MERGED), Restrictions.eq(PullRequest.PROP_LAST_MERGE_PREVIEW + "." + MergePreview.PROP_HEAD_COMMIT_HASH, source.getObjectName())); criteria.add(ofTarget(target)).add(ofSource(source)).add(Restrictions.or(ofOpen(), merged)); return find(criteria); }
Example 3
Source File: DefaultPullRequestManager.java From onedev with MIT License | 5 votes |
@Transactional @Listen public void on(RefUpdated event) { String branch = GitUtils.ref2branch(event.getRefName()); if (branch != null && !event.getOldCommitId().equals(ObjectId.zeroId())) { ProjectAndBranch projectAndBranch = new ProjectAndBranch(event.getProject(), branch); Criterion criterion = Restrictions.and( ofOpen(), Restrictions.or(ofSource(projectAndBranch), ofTarget(projectAndBranch))); checkAsync(query(EntityCriteria.of(PullRequest.class).add(criterion))); } }
Example 4
Source File: SQLVisitor.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
private Criterion getCriterionLogical(BinaryOperator operator, Criterion left, Criterion right) { Criterion criterion; if (left == null && right == null) { criterion = null; } else if (left != null && right != null) { switch (operator) { case AND: { criterion = Restrictions.and(left, right); break; } case OR: { criterion = Restrictions.or(left, right); break; } default: { throw new UnsupportedOperationException( "Unsupported operator: " + operator.toUriLiteral()); } } } else if (left == null) { criterion = right; } else { criterion = left; } return criterion; }
Example 5
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public Collection getRunningCollectionStatusByUser(Long userId) { Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); //criteria.add(Restrictions.eq("user.id", userId)); //criteria.add(Restrictions.eq("status", CollectionStatus.RUNNING)); LogicalExpression or = Restrictions.or( Restrictions.eq("status", CollectionStatus.RUNNING), Restrictions.eq("status", CollectionStatus.RUNNING_WARNING) ); LogicalExpression orAll = Restrictions.or( or, Restrictions.eq("status", CollectionStatus.WARNING) ); /*Is this check needed? * * LogicalExpression and = Restrictions.and( orAll, Restrictions.ne("status", CollectionStatus.TRASHED) );*/ LogicalExpression andAll = Restrictions.and( orAll, Restrictions.eq("owner.id", userId) ); criteria.add(andAll); //criteria.add(Restrictions.ne("status", CollectionStatus.TRASHED)); return (Collection) criteria.uniqueResult(); }
Example 6
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public Long getRunningCollectionsCount(String terms) { Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteria.setProjection(Projections.projectionList() .add(Projections.property("id"), "id")); LogicalExpression or = Restrictions.or( Restrictions.eq("status", CollectionStatus.RUNNING), Restrictions.eq("status", CollectionStatus.RUNNING_WARNING) ); LogicalExpression or2 = Restrictions.or( or, Restrictions.eq("status", CollectionStatus.INITIALIZING) ); LogicalExpression orAll = Restrictions.or( or2, Restrictions.eq("status", CollectionStatus.WARNING) ); LogicalExpression andAll = Restrictions.and( orAll, Restrictions.ne("status", CollectionStatus.TRASHED) ); criteria.add(andAll); addCollectionSearchCriteria(terms, criteria); ScrollableResults scroll = criteria.scroll(); int i = scroll.last() ? scroll.getRowNumber() + 1 : 0; return Long.valueOf(i); }
Example 7
Source File: PullRequest.java From onedev with MIT License | 4 votes |
public static Criterion ofTarget(ProjectAndBranch target) { return Restrictions.and( Restrictions.eq("targetProject", target.getProject()), Restrictions.eq("targetBranch", target.getBranch())); }
Example 8
Source File: PullRequest.java From onedev with MIT License | 4 votes |
public static Criterion ofSource(ProjectAndBranch source) { return Restrictions.and( Restrictions.eq("sourceProject", source.getProject()), Restrictions.eq("sourceBranch", source.getBranch())); }
Example 9
Source File: CheckDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * Insert check. * * @param check * the check * * @throws EMFUserError * the EMF user error * * @see it.eng.spagobi.behaviouralmodel.check.dao.ICheckDAO#insertCheck(it.eng.spagobi.behaviouralmodel.check.bo.Check) */ @Override public Integer insertCheck(Check check) throws EMFUserError { Session aSession = null; Transaction tx = null; try { aSession = getSession(); tx = aSession.beginTransaction(); SbiChecks hibCheck = new SbiChecks(); Criteria criteria = aSession.createCriteria(SbiDomains.class); Criterion aCriterion = Restrictions.and(Restrictions.eq("valueId".trim(), check.getValueTypeId()), Restrictions.eq("valueCd".trim(), check.getValueTypeCd()).ignoreCase()); criteria.add(aCriterion); SbiDomains checkType = (SbiDomains) criteria.uniqueResult(); if (checkType == null) { SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, "CheckDAOHibImpl", "insertCheck", "The Domain with value_id=" + check.getValueTypeId() + " and value_cd=" + check.getValueTypeCd() + " does not exist."); throw new EMFUserError(EMFErrorSeverity.ERROR, 1035); } hibCheck.setCheckType(checkType); hibCheck.setDescr(check.getDescription()); hibCheck.setName(check.getName()); hibCheck.setLabel(check.getLabel()); hibCheck.setValue1(check.getFirstValue()); hibCheck.setValue2(check.getSecondValue()); hibCheck.setValueTypeCd(check.getValueTypeCd()); updateSbiCommonInfo4Insert(hibCheck); aSession.save(hibCheck); tx.commit(); return hibCheck.getCheckId(); } catch (HibernateException he) { logException(he); if (tx != null) tx.rollback(); throw new EMFUserError(EMFErrorSeverity.ERROR, 100); } finally { if (aSession != null) { if (aSession.isOpen()) aSession.close(); } } }
Example 10
Source File: CheckDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * Modify check. * * @param check * the check * * @throws EMFUserError * the EMF user error * * @see it.eng.spagobi.behaviouralmodel.check.dao.ICheckDAO#modifyCheck(it.eng.spagobi.behaviouralmodel.check.bo.Check) */ @Override public void modifyCheck(Check check) throws EMFUserError { Session aSession = null; Transaction tx = null; try { aSession = getSession(); tx = aSession.beginTransaction(); SbiChecks hibCheck = (SbiChecks) aSession.load(SbiChecks.class, check.getCheckId().intValue()); Criteria criteria = aSession.createCriteria(SbiDomains.class); Criterion aCriterion = Restrictions.and(Restrictions.eq("valueId".trim(), check.getValueTypeId().intValue()), Restrictions.eq("valueCd".trim(), check.getValueTypeCd()).ignoreCase()); criteria.add(aCriterion); SbiDomains aSbiDomains = (SbiDomains) criteria.uniqueResult(); if (aSbiDomains == null) { SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, "CheckDAOHibImpl", "modifyCheck", "The Domain with value_id=" + check.getValueTypeId() + " and value_cd=" + check.getValueTypeCd() + " does not exist."); throw new EMFUserError(EMFErrorSeverity.ERROR, 1036); } hibCheck.setDescr(check.getDescription()); hibCheck.setName(check.getName()); hibCheck.setLabel(check.getLabel()); hibCheck.setValue1(check.getFirstValue()); hibCheck.setValue2(check.getSecondValue()); hibCheck.setCheckType(aSbiDomains); hibCheck.setValueTypeCd(aSbiDomains.getValueCd()); updateSbiCommonInfo4Update(hibCheck); tx.commit(); } catch (HibernateException he) { logException(he); if (tx != null) tx.rollback(); throw new EMFUserError(EMFErrorSeverity.ERROR, 100); } finally { if (aSession != null) { if (aSession.isOpen()) aSession.close(); } } }
Example 11
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public List<Collection> getRunningCollections(Integer start, Integer limit, String terms, String sortColumn, String sortDirection) { Criteria criteriaIds = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteriaIds.setProjection(Projections.projectionList() .add(Projections.property("id"), "id")); LogicalExpression or = Restrictions.or( Restrictions.eq("status", CollectionStatus.RUNNING), Restrictions.eq("status", CollectionStatus.RUNNING_WARNING) ); LogicalExpression or2 = Restrictions.or( or, Restrictions.eq("status", CollectionStatus.INITIALIZING) ); LogicalExpression orAll = Restrictions.or( or2, Restrictions.eq("status", CollectionStatus.WARNING) ); LogicalExpression andAll = Restrictions.and( orAll, Restrictions.ne("status", CollectionStatus.TRASHED) ); criteriaIds.add(andAll); addCollectionSearchCriteria(terms, criteriaIds); searchCollectionsAddOrder(sortColumn, sortDirection, criteriaIds); if (start != null) { criteriaIds.setFirstResult(start); } if (limit != null) { criteriaIds.setMaxResults(limit); } List<Integer> ids = criteriaIds.list(); if (ids.size() == 0){ return Collections.emptyList(); } Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.in("id", ids)); searchCollectionsAddOrder(sortColumn, sortDirection, criteria); return criteria.list(); }
Example 12
Source File: CriteriaQuery.java From jeecg with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * @return */ public Criterion and(Criterion c1, Criterion c2) { return Restrictions.and(c1, c2); }
Example 13
Source File: CriteriaQuery.java From jeecg with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * hql:(this_.0 like ? or this_.1 like ?) 表示法:cq.add(cq.or(cq, 0, * 1)); * @return */ public Criterion and(Criterion c, CriteriaQuery query, int souce) { return Restrictions.and(c, query.getCriterionList().getParas(souce)); }
Example 14
Source File: CriteriaQuery.java From jeecg with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * hql((this_.0 like ? and this_.1 like ?) or this_.2 like ?) * 表示法cq.add(cq.or(cq.and(cq, 0, 1), cq, 2)) * @return */ public Criterion and(CriteriaQuery query, int source, int dest) { return Restrictions.and(query.getCriterionList().getParas(source), query.getCriterionList().getParas(dest)); }
Example 15
Source File: CriteriaQuery.java From jeewx with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * @return */ public Criterion and(Criterion c1, Criterion c2) { return Restrictions.and(c1, c2); }
Example 16
Source File: CriteriaQuery.java From jeewx with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * hql:(this_.0 like ? or this_.1 like ?) 表示法:cq.add(cq.or(cq, 0, * 1)); * @return */ public Criterion and(Criterion c, CriteriaQuery query, int souce) { return Restrictions.and(c, query.getCriterionList().getParas(souce)); }
Example 17
Source File: CriteriaQuery.java From jeewx with Apache License 2.0 | 2 votes |
/** * 设置条件之间and关系 * * @param query * @param source * @param dest * hql((this_.0 like ? and this_.1 like ?) or this_.2 like ?) * 表示法cq.add(cq.or(cq.and(cq, 0, 1), cq, 2)) * @return */ public Criterion and(CriteriaQuery query, int source, int dest) { return Restrictions.and(query.getCriterionList().getParas(source), query.getCriterionList().getParas(dest)); }