List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:org.candlepin.policy.criteria.CriteriaRules.java
License:Open Source License
/** * Create a List of JPA criterion that can filter out pools that are not * applicable to consumer. Helps to scale down large numbers of pools * specifically with virt_limit subscriptions. * * @param consumer The consumer we are filtering pools for * @return List of Criterion/*from www.j a va2 s . c om*/ */ public List<Criterion> availableEntitlementCriteria(Consumer consumer) { // avoid passing in a consumerCurator just to get the host // consumer UUID Consumer hostConsumer = null; if (consumer.getFact("virt.uuid") != null) { hostConsumer = consumerCurator.getHost(consumer.getFact("virt.uuid"), consumer.getOwner()); } List<Criterion> criteriaFilters = new LinkedList<Criterion>(); // Don't load virt_only pools if this consumer isn't a guest // or a manifest consumer if (consumer.getType().isManifest()) { DetachedCriteria noRequiresHost = DetachedCriteria.forClass(PoolAttribute.class, "attr") .add(Restrictions.eq("name", "requires_host")) .add(Property.forName("this.id").eqProperty("attr.pool.id")) .setProjection(Projections.property("attr.id")); // we do want everything else criteriaFilters.add(Subqueries.notExists(noRequiresHost)); } else if (!"true".equalsIgnoreCase(consumer.getFact("virt.is_guest"))) { // not a guest DetachedCriteria noVirtOnlyPoolAttr = DetachedCriteria.forClass(PoolAttribute.class, "pool_attr") .add(Restrictions.eq("name", "virt_only")).add(Restrictions.eq("value", "true").ignoreCase()) .add(Property.forName("this.id").eqProperty("pool_attr.pool.id")) .setProjection(Projections.property("pool_attr.id")); criteriaFilters.add(Subqueries.notExists(noVirtOnlyPoolAttr)); // same criteria but for PoolProduct attributes // not sure if this should be two separate criteria, or if it's // worth it to combine in some clever fashion DetachedCriteria noVirtOnlyProductAttr = DetachedCriteria .forClass(ProductPoolAttribute.class, "prod_attr").add(Restrictions.eq("name", "virt_only")) .add(Restrictions.eq("value", "true").ignoreCase()) .add(Property.forName("this.id").eqProperty("prod_attr.pool.id")) .setProjection(Projections.property("prod_attr.id")); criteriaFilters.add(Subqueries.notExists(noVirtOnlyProductAttr)); } else { // we are a virt guest // add criteria for filtering out pools that are not for this guest if (consumer.hasFact("virt.uuid")) { String hostUuid = ""; // need a default value in case there is no host if (hostConsumer != null) { hostUuid = hostConsumer.getUuid(); } DetachedCriteria noRequiresHost = DetachedCriteria.forClass(PoolAttribute.class, "attr") .add(Restrictions.eq("name", "requires_host")) // Note: looking for pools that are not for this guest .add(Restrictions.ne("value", hostUuid).ignoreCase()) .add(Property.forName("this.id").eqProperty("attr.pool.id")) .setProjection(Projections.property("attr.id")); // we do want everything else criteriaFilters.add(Subqueries.notExists(noRequiresHost)); } // no virt.uuid, we can't try to filter } return criteriaFilters; }
From source file:org.caratarse.auth.model.util.CriteriaFilterHelper.java
License:Apache License
public static void addQueryFilter(final DetachedCriteria crit, QueryFilter filter) { if (filter == null) { return;// w w w . ja v a2s .co m } filter.iterate(new FilterCallback() { @Override public void filterOn(FilterComponent c) { switch (c.getOperator()) { case CONTAINS: // String-related crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.ANYWHERE)); break; case STARTS_WITH: // String-related crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.START)); break; case GREATER_THAN: crit.add(Restrictions.gt(c.getField(), c.getValue())); break; case GREATER_THAN_OR_EQUAL_TO: crit.add(Restrictions.ge(c.getField(), c.getValue())); break; case LESS_THAN: crit.add(Restrictions.lt(c.getField(), c.getValue())); break; case LESS_THAN_OR_EQUAL_TO: crit.add(Restrictions.le(c.getField(), c.getValue())); break; case NOT_EQUALS: crit.add(Restrictions.ne(c.getField(), c.getValue())); break; case EQUALS: default: crit.add(Restrictions.eq(c.getField(), c.getValue())); break; } } }); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
License:Apache License
protected void addSimplePropertyCriterionAdapters() { criterionAdaptors.put(Query.IdEquals.class, new CriterionAdaptor() { @Override// w w w .jav a2s. com public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Criterion criterion, String alias) { return Restrictions.idEq(((Query.IdEquals) criterion).getValue()); } }); criterionAdaptors.put(Query.Equals.class, new CriterionAdaptor<Query.Equals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Equals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).eq((DetachedCriteria) value); } return Restrictions.eq(propertyName, value); } }); criterionAdaptors.put(Query.NotEquals.class, new CriterionAdaptor<Query.NotEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.NotEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).ne((DetachedCriteria) value); } return Restrictions.ne(propertyName, value); } }); criterionAdaptors.put(Query.GreaterThan.class, new CriterionAdaptor<Query.GreaterThan>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThan criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).gt((DetachedCriteria) value); } return Restrictions.gt(propertyName, value); } }); criterionAdaptors.put(Query.GreaterThanEquals.class, new CriterionAdaptor<Query.GreaterThanEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).ge((DetachedCriteria) value); } return Restrictions.ge(propertyName, value); } }); criterionAdaptors.put(Query.LessThan.class, new CriterionAdaptor<Query.LessThan>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThan criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).lt((DetachedCriteria) value); } return Restrictions.lt(propertyName, value); } }); criterionAdaptors.put(Query.LessThanEquals.class, new CriterionAdaptor<Query.LessThanEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).le((DetachedCriteria) value); } return Restrictions.le(propertyName, value); } }); }
From source file:org.dspace.identifier.dao.impl.DOIDAOImpl.java
License:BSD License
@Override public List<DOI> findSimilarNotInState(Context context, String doi, List<Integer> excludedStatuses, boolean dsoNotNull) throws SQLException { // SELECT * FROM Doi WHERE doi LIKE ? AND resource_type_id = ? AND resource_id IS NOT NULL AND status != ? AND status != ? Criteria criteria = createCriteria(context, DOI.class); Conjunction conjunctionAnd = Restrictions.and(); Disjunction statusQuery = Restrictions.or(); for (Integer status : excludedStatuses) { statusQuery.add(Restrictions.ne("status", status)); }/* w w w. j a va 2 s .c om*/ conjunctionAnd.add(Restrictions.like("doi", doi)); conjunctionAnd.add(statusQuery); if (dsoNotNull) { conjunctionAnd.add(Restrictions.isNotNull("dSpaceObject")); } criteria.add(conjunctionAnd); return list(criteria); }
From source file:org.dspace.orm.dao.database.BitstreamDao.java
License:BSD License
@SuppressWarnings("unchecked") @Override//from w w w . ja va 2 s. co m public List<Bitstream> selectDuplicateInternalIdentifier(Bitstream bitstream) { return (List<Bitstream>) super.getSession().createCriteria(Bitstream.class) .add(Restrictions.and(Restrictions.eq("internalId", bitstream.getInternalId()), Restrictions.ne("ID", bitstream.getID()))) .list(); }
From source file:org.egov.api.controller.EmployeeController.java
License:Open Source License
@SuppressWarnings("unchecked") public List<StateAware> getWorkflowItemsByUserAndWFType(final Long userId, final List<Long> owners, final String workFlowType, final int resultsFrom, final int resultsTo, String priority) throws ClassNotFoundException { if (!owners.isEmpty()) { Criterion criterion = Restrictions .not(Restrictions.conjunction().add(Restrictions.eq("state.status", StateStatus.STARTED)) .add(Restrictions.eq("createdBy.id", userId))); criterion = addPriorityCondition(criterion, priority); return entityQueryService.getSession() .createCriteria(Class .forName(workflowTypeService.getEnabledWorkflowTypeByType(workFlowType).getTypeFQN())) .setFirstResult(resultsFrom).setMaxResults(resultsTo).setFetchMode("state", FetchMode.JOIN) .createAlias("state", "state").setFlushMode(FlushMode.MANUAL).setReadOnly(true) .setCacheable(true).add(Restrictions.eq("state.type", workFlowType)) .add(Restrictions.in("state.ownerPosition.id", owners)) .add(Restrictions.ne("state.status", StateStatus.ENDED)).add(criterion) .addOrder(Order.desc("state.createdDate")).list(); }/*from w ww . j a va2 s . c o m*/ return Collections.emptyList(); }
From source file:org.egov.api.controller.EmployeeController.java
License:Open Source License
@SuppressWarnings("unchecked") public Number getWorkflowItemsCountByWFType(final Long userId, final List<Long> owners, final String workFlowType, final String priority) throws ClassNotFoundException { if (!owners.isEmpty()) { Criterion criterion = Restrictions .not(Restrictions.conjunction().add(Restrictions.eq("state.status", StateStatus.STARTED)) .add(Restrictions.eq("createdBy.id", userId))); criterion = addPriorityCondition(criterion, priority); return (Number) entityQueryService.getSession() .createCriteria(Class .forName(workflowTypeService.getEnabledWorkflowTypeByType(workFlowType).getTypeFQN())) .setFetchMode("state", FetchMode.JOIN).createAlias("state", "state") .setFlushMode(FlushMode.MANUAL).setReadOnly(true).setCacheable(true) .setProjection(Projections.rowCount()).add(Restrictions.eq("state.type", workFlowType)) .add(Restrictions.in("state.ownerPosition.id", owners)) .add(Restrictions.ne("state.status", StateStatus.ENDED)).add(criterion).uniqueResult(); }/* ww w . jav a2 s. c om*/ return 0; }
From source file:org.egov.council.service.CouncilMeetingService.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CouncilMeeting> searchMeeting(CouncilMeeting councilMeeting) { return buildSearchCriteria(councilMeeting).add(Restrictions.ne(STATUS_DOT_CODE, MEETINGCANCELLED)).list(); }
From source file:org.egov.council.service.CouncilPreambleService.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CouncilPreamble> searchPreambleForWardwiseReport(CouncilPreamble councilPreamble) { final Criteria criteria = buildSearchCriteria(councilPreamble); criteria.add(Restrictions.ne(STATUS_CODE, REJECTED)); return criteria.list(); }
From source file:org.egov.council.service.CouncilPreambleService.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CouncilPreamble> search(CouncilPreamble councilPreamble) { final Criteria criteria = buildSearchCriteria(councilPreamble); criteria.add(Restrictions.ne(STATUS_CODE, REJECTED)); return criteria.list(); }