Java Code Examples for org.hibernate.criterion.Restrictions#in()

The following examples show how to use org.hibernate.criterion.Restrictions#in() . 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: CriteriaParameter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public Criterion toHibernateCriterion() {
	Criterion restriction = null;
	switch (getMatch()) {
	case LIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE);
		break;
	case ILIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE).ignoreCase();
		break;
	case NOT_EQ:
		restriction = Restrictions.ne(getName(), getValue());
		break;
	case IN:
		restriction = Restrictions.in(getName(), (Object[]) getValue());
		break;
	case NOT_IN:
		restriction = Restrictions.not(Restrictions.in(getName(), (Object[]) getValue()));
		break;
	default:
		restriction = Restrictions.eq(getName(), getValue());
		break;
	}
	return restriction;
}
 
Example 2
Source File: JobDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<Job> handleFindPending(Long departmentId, Boolean daily, Boolean weekly, Boolean monthly) throws Exception {
	org.hibernate.Criteria jobCriteria = createJobCriteria();
	if (departmentId != null) {
		jobCriteria.createCriteria("modifiedUser").add(Restrictions.eq("department.id", departmentId.longValue()));
	}
	if (daily != null || weekly != null || monthly != null) {
		org.hibernate.Criteria typeCriteria = jobCriteria.createCriteria("type");
		if (daily != null) {
			typeCriteria.add(Restrictions.eq("daily", daily.booleanValue()));
		}
		if (weekly != null) {
			typeCriteria.add(Restrictions.eq("weekly", weekly.booleanValue()));
		}
		if (monthly != null) {
			typeCriteria.add(Restrictions.eq("monthly", monthly.booleanValue()));
		}
	}
	Restrictions.in("status", new Object[] {
			JobStatus.CREATED,
			JobStatus.FAILED,
			JobStatus.OK
	});
	jobCriteria.addOrder(Order.asc("id"));
	return jobCriteria.list();
}
 
Example 3
Source File: HibernateCriterionUtils.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public static Criterion CriterionInRestrictionSplitter(String property, Collection<?> values) {
    Objects.requireNonNull(property);
    Objects.requireNonNull(values);

    Criterion criterion = null;
    List<?> list = new ArrayList<>(values);
    int listSize = list.size();

    for (int i = 0; i < listSize; i += MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
        List<?> subList;
        if (listSize > i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
            subList = list.subList(i, (i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST));
        } else {
            subList = list.subList(i, listSize);
        }
        if (criterion == null) {
            criterion = Restrictions.in(property, subList);
        } else {
            criterion = Restrictions.or(criterion, Restrictions.in(property, subList));
        }
    }
    return criterion;
}
 
Example 4
Source File: HibernateCriterionUtils.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public static Criterion CriterionInRestrictionSplitter(String property, Collection<?> values) {
    Objects.requireNonNull(property);
    Objects.requireNonNull(values);

    Criterion criterion = null;
    List<?> list = new ArrayList<>(values);
    int listSize = list.size();

    for (int i = 0; i < listSize; i += MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
        List<?> subList;
        if (listSize > i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
            subList = list.subList(i, (i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST));
        } else {
            subList = list.subList(i, listSize);
        }
        if (criterion == null) {
            criterion = Restrictions.in(property, subList);
        } else {
            criterion = Restrictions.or(criterion, Restrictions.in(property, subList));
        }
    }
    return criterion;
}
 
Example 5
Source File: InOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    Property property = queryPath.getProperty();

    if ( property.isCollection() )
    {
        return Restrictions.in( queryPath.getPath(), getValue( Collection.class, queryPath.getProperty().getItemKlass(), args.get( 0 ) ) );
    }

    return Restrictions.in( queryPath.getPath(), getValue( Collection.class, queryPath.getProperty().getKlass(), args.get( 0 ) ) );
}
 
Example 6
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(Id filter, Object userData) {
	String idName;
	try {
		idName = featureModel.getEntityMetadata().getIdentifierPropertyName();
	} catch (LayerException e) {
		log.warn("Cannot read idName, defaulting to 'id'", e);
		idName = HIBERNATE_ID;
	}
	Collection<?> c = (Collection<?>) castLiteral(filter.getIdentifiers(), idName);
	return Restrictions.in(idName, c);
}
 
Example 7
Source File: DocumentResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<DocumentDTO> getDocumentForNominalLabelAndCrisis(List<Long> nominalLabelID, Long crisisId) {
	
	List<DocumentDTO> dtoList = new ArrayList<DocumentDTO>();
	
	if (nominalLabelID != null) {
		String aliasTable = "documentNominalLabels";
		String aliasTableKeyField = "documentNominalLabels.id.nominalLabelId";
		Criteria criteria = null;
		
		try {
			
			Criterion criterion = Restrictions.conjunction()
					.add(Restrictions.eq("collection.id", crisisId))
					.add(Restrictions.eq("hasHumanLabels", true));
			
			Criterion aliasCriterion =  Restrictions.in(aliasTableKeyField, nominalLabelID);
			
			// get just the documentIDs
			Projection projection = Projections.property("documentId");
			
			//List<Document> docList = this.getByCriteriaWithInnerJoinByOrder(criterion, "DESC", orderBy, null, aliasTable, aliasCriterion);
			criteria = createCriteria(criterion, null, null, null, aliasTable, aliasCriterion, null, JoinType.INNER_JOIN);
			List<Document> docList = criteria.list();
			
			if (docList != null && !docList.isEmpty()) {
				for (Document doc : docList) {
					DocumentDTO dto = new DocumentDTO(doc);
					dtoList.add(dto);
				}
			}
		} catch (Exception e) {
			logger.error("getDocumentCountForNominalLabelAndCrisis failed, criteria = " + criteria.toString(), e);
		}
	}
	
	return dtoList;
}
 
Example 8
Source File: DrugsDAOImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private Criterion getTypesCriterion(List<String> types) {
    return Restrictions.in("type", types);
}
 
Example 9
Source File: DrugsDAOImpl.java    From icure-backend with GNU General Public License v2.0 4 votes vote down vote up
private Criterion getTypesCriterion(List<String> types) {
	return Restrictions.in("type", types);
}
 
Example 10
Source File: BookDao.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<BookDO> getList(final BaseSearchFilter filter)
{
  final BookFilter myFilter;
  if (filter instanceof BookFilter) {
    myFilter = (BookFilter) filter;
  } else {
    myFilter = new BookFilter(filter);
  }
  final QueryFilter queryFilter = new QueryFilter(myFilter);
  if (StringUtils.isBlank(myFilter.getSearchString()) == true) {
    Collection<BookStatus> col = null;
    if (myFilter.isPresent() == true || myFilter.isMissed() == true || myFilter.isDisposed() == true) {
      col = new ArrayList<BookStatus>();
      if (myFilter.isPresent() == true) {
        // Book must be have status 'present'.
        col.add(BookStatus.PRESENT);
      }
      if (myFilter.isMissed() == true) {
        // Book must be have status 'missed'.
        col.add(BookStatus.MISSED);
      }
      if (myFilter.isDisposed() == true) {
        // Book must be have status 'disposed'.
        col.add(BookStatus.DISPOSED);
      }
    }
    myFilter.setIgnoreDeleted(false);
    if (col != null) {
      final Criterion inCrit = Restrictions.in("status", col);
      if (myFilter.isDeleted() == true) {
        queryFilter.add(Restrictions.or(inCrit, Restrictions.eq("deleted", true)));
        myFilter.setIgnoreDeleted(true);
      } else {
        queryFilter.add(inCrit);
      }
    }
  }
  queryFilter.addOrder(Order.desc("created"));
  queryFilter.addOrder(Order.asc("authors"));
  return getList(queryFilter);
}
 
Example 11
Source File: InRestriction.java    From base-framework with Apache License 2.0 4 votes vote down vote up
public Criterion buildRestriction(String propertyName, Object[] values) {
	return Restrictions.in(propertyName,values);
}
 
Example 12
Source File: HibernateGenericDao.java    From lemon with Apache License 2.0 3 votes vote down vote up
/**
 * find by ids.
 * 
 * @param entityClass
 *            Class
 * @param ids
 *            List
 * @param <T>
 *            generic
 * @return List
 */
@Transactional(readOnly = true)
public <T> List<T> findByIds(Class<T> entityClass, List ids) {
    Assert.notEmpty(ids);

    String idName = this.getIdName(entityClass);
    Criterion criterion = Restrictions.in(idName, ids);

    return this.find(entityClass, criterion);
}
 
Example 13
Source File: HibernateUtils.java    From lemon with Apache License 2.0 2 votes vote down vote up
/**
 * 按属性条件参数创建Criterion,辅助函数.
 * 
 * @param propertyName
 *            String
 * @param propertyValue
 *            Object
 * @param matchType
 *            MatchType
 * @return Criterion
 */
public static Criterion buildCriterion(String propertyName,
        Object propertyValue, MatchType matchType) {
    Assert.hasText(propertyName, "propertyName不能为空");

    Criterion criterion = null;

    // 根据MatchType构造criterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);

        break;

    case NOT:
        criterion = Restrictions.ne(propertyName, propertyValue);

        break;

    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue,
                MatchMode.ANYWHERE);

        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);

        break;

    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);

        break;

    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);

        break;

    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);

        break;

    case IN:
        criterion = Restrictions.in(propertyName,
                (Collection) propertyValue);

        break;

    case INL:
        criterion = Restrictions.isNull(propertyName);

        break;

    case NNL:
        criterion = Restrictions.isNotNull(propertyName);

        break;

    default:
        criterion = Restrictions.eq(propertyName, propertyValue);

        break;
    }

    return criterion;
}