List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Criterion,.//from w w w .ja v a2 s .c o m */ protected Criterion[] buildCriterionByPropertyFilter(final List<PropertyFilter> filters) { List<Criterion> criterionList = new ArrayList<Criterion>(); for (PropertyFilter filter : filters) { /*if (!filter.hasMultiProperties()) { //??. Criterion criterion = buildCriterion(filter.getPropertyName(), filter.getMatchValue(), filter .getMatchType()); criterionList.add(criterion); } else {//??,or?. Disjunction disjunction = Restrictions.disjunction(); for (String param : filter.getPropertyNames()) { Criterion criterion = buildCriterion(param, filter.getMatchValue(), filter.getMatchType()); disjunction.add(criterion); } criterionList.add(disjunction); }*/ //update by wucong // System.out.println("+++++++++++++++++++++++++++++++++++++++filter:"+filter); if (filter == null) continue; if (!filter.hasMultiProperties()) { //??. Disjunction disjunction = Restrictions.disjunction(); for (Object matchValue : filter.getMatchValues()) { Criterion criterion = buildCriterion(filter.getPropertyName(), matchValue, filter.getMatchType()); disjunction.add(criterion); } criterionList.add(disjunction); } else {//??,or?. Disjunction disjunction = Restrictions.disjunction(); for (String param : filter.getPropertyNames()) { for (Object matchValue : filter.getMatchValues()) { Criterion criterion = buildCriterion(param, matchValue, filter.getMatchType()); disjunction.add(criterion); } } criterionList.add(disjunction); } } //? // criterionList.add(Restrictions.gt("status", -100) ); return criterionList.toArray(new Criterion[criterionList.size()]); }
From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java
License:Open Source License
/** * convert the InputDTO to QueryHelper to get the count (omitting sort order) *//* w ww .j a va2 s. c o m*/ @SuppressWarnings("deprecation") public QueryHelper convertDtoToQhelperForCount(InputDTO dto) { if (dto == null) return this; this.dto = dto; int ind = 0; try { Junction j = null; Junction conj = Restrictions.conjunction(); Junction disj = Restrictions.disjunction(); String operator = ""; boolean disjB = false, conjB = false; if (dto.getFetchMode() != null) { for (Map.Entry<String, String> entry : dto.getFetchMode().entrySet()) { FetchMode fmode = null; logger.debug("FetchMode key=" + entry.getKey() + " val=" + entry.getValue()); if (entry.getValue().equals("join")) fmode = FetchMode.JOIN; else if (entry.getValue().equals("eager")) fmode = FetchMode.EAGER; else if (entry.getValue().equals("lazy")) fmode = FetchMode.LAZY; else fmode = FetchMode.LAZY; this.detCriteria.setFetchMode(entry.getKey(), fmode); } } for (String field : dto.getFields()) { operator = dto.getOperators().get(ind); if ("or".equals(operator)) { j = disj; disjB = true; } else { j = conj; conjB = true; } this.addFieldAndVal(createAliases(field), dto.getValues().get(ind), dto.getOperations().get(ind), j); ind++; } if (dto.getExpressions() != null) { for (String expr : dto.getExpressions()) { j.add(Expression.sql(expr)); } } if (dto.getFieldsToSelect() != null && dto.getFieldsToSelect().length > 0) { ProjectionList prList = Projections.projectionList(); Projection projection = null; for (String fld : dto.getFieldsToSelect()) { String als = this.createAliases(fld); prList.add(Projections.property(als)); } if (dto.isDistinct()) { projection = Projections.distinct(prList); } else { projection = prList; } this.detCriteria.setProjection(projection); } else { this.fldSelectedSet = false; } if (disjB) detCriteria.add(disj); if (conjB) detCriteria.add(conj); if (logger.isDebugEnabled()) { if (conjB) logger.debug("conjuction=" + conj.toString()); if (disjB) logger.debug("disjunction=" + disj.toString()); } if (dto.isDistinct()) detCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } catch (Exception e) { e.printStackTrace(); logger.error(e); } return this; }
From source file:com.inkubator.hrm.dao.impl.ApprovalDefinitionDaoImpl.java
@Override public Long getTotalDataWithSequenceLower(String approvalName, int sequance) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq("processType", HRMConstant.ON_APPROVE_INFO)); disjunction.add(Restrictions.eq("processType", HRMConstant.ON_REJECT_INFO)); criteria.add(Restrictions.eq("name", approvalName)); criteria.add(Restrictions.le("sequence", sequance)); criteria.add(disjunction);//from w w w . j a v a2 s .c o m return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.ApprovalDefinitionDaoImpl.java
@Override public Long getTotalDataWithSequenceLowerAndNotId(String approvalName, int sequance, long id) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq("processType", HRMConstant.ON_APPROVE_INFO)); disjunction.add(Restrictions.eq("processType", HRMConstant.ON_REJECT_INFO)); criteria.add(Restrictions.eq("name", approvalName)); criteria.add(Restrictions.le("sequence", sequance)); criteria.add(Restrictions.ne("id", id)); criteria.add(disjunction);// w w w . ja va2 s .com return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.BioDataDaoImpl.java
@Override public List<BioData> getByName(String name) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); // criteria.createAlias("empDatas", "emp",JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("firstName", name, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("lastName", name, MatchMode.ANYWHERE)); criteria.add(disjunction);/*from ww w . j av a 2 s . co m*/ criteria.add(Restrictions.isEmpty("empDatas")); criteria.addOrder(Order.asc("firstName")); criteria.setFirstResult(0); criteria.setMaxResults(7); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.BioPotensiSwotDaoImpl.java
public void doSearchByParam(BioPotensiSwotSearchParameter searchParameter, Criteria criteria) { if (searchParameter.getName() != null) { criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bio.firstName", searchParameter.getName(), MatchMode.START)); disjunction.add(Restrictions.like("bio.lastName", searchParameter.getName(), MatchMode.START)); criteria.add(disjunction);//w ww .j a va 2 s. co m } criteria.add(Restrictions.isNotNull("id")); }
From source file:com.inkubator.hrm.dao.impl.BioRelasiPerusahaanDaoImpl.java
public void doSearchByParam(BioRelasiPerusahaanSearchParameter searchParameter, Criteria criteria) { if (searchParameter.getName() != null) { criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bio.firstName", searchParameter.getName(), MatchMode.START)); disjunction.add(Restrictions.like("bio.lastName", searchParameter.getName(), MatchMode.START)); criteria.add(disjunction);/*from ww w .j ava 2s . c o m*/ } criteria.add(Restrictions.isNotNull("id")); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getAllDataByNameOrNik(String param, Long companyId) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**// w ww .j a v a 2 s .co m * automatically get relations of jabatanByJabatanId, department, * company don't create alias for that entity, or will get error : * duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, companyId); //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.add(Restrictions.isNotNull("status")); criteria.add(Restrictions .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED, HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION)))); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); criteria.setMaxResults(20); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getAllDataByNameOrNik(String param) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.add(Restrictions.isNotNull("status")); criteria.add(Restrictions/*w w w . j a va 2 s . c om*/ .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED, HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION)))); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); criteria.setMaxResults(20); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
private Criteria doSearchNotExistInUserByParam(String param, Criteria criteria) { /**//from w ww . j av a 2s . co m * automatically get relations of jabatanByJabatanId, department, * company don't create alias for that entity, or will get error : * duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); if (param != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); } return criteria; }