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

The following examples show how to use org.hibernate.criterion.Restrictions#isNull() . 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: DocumentResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<Long> getUnassignedDocumentIDsByCrisisID(Long crisisID, Integer count) {
	
	List<Long> docIDList = new ArrayList<Long>();
	Criteria criteria = null;
	try {
		String aliasTable = "taskAssignments";
		String order = "ASC";
		String aliasTableKey = "taskAssignments.id.documentId";
		String[] orderBy = {"valueAsTrainingSample", "documentId"};
		Criterion criterion = Restrictions.conjunction()
				.add(Restrictions.eq("collection.id",crisisID))
				.add(Restrictions.eq("hasHumanLabels",false));

		// get just the documentIDs
		Projection projection = Projections.property("documentId");
		Criterion aliasCriterion =  (Restrictions.isNull(aliasTableKey));
		criteria = createCriteria(criterion, order, orderBy, count, aliasTable, aliasCriterion, new Projection[] {projection}, JoinType.LEFT_OUTER_JOIN);
		docIDList = criteria.list();
		return docIDList;
			
	} catch (Exception e) {
		logger.error("getByCriteriaWithAliasByOrder failed, criteria = " + criteria.toString(), e);
		throw new HibernateException("getByCriteriaWithAliasByOrder failed, criteria = " + criteria.toString());
	}
}
 
Example 2
Source File: SurveyDirectoryManagerImpl.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SurveyDirectory> findByIndex() {
    Criterion cri1=Restrictions.eq("visibility", 1);
    Criterion cri2=Restrictions.eq("parentId", "402880e5428a2dca01428a2f1f290000");
    Criterion cri3=Restrictions.eq("surveyTag", 1);
    Criterion cri4=Restrictions.isNull("sid");
    Page<SurveyDirectory> page=new Page<SurveyDirectory>();
    page.setOrderBy("createDate");
	page.setOrderDir("desc");
	page.setPageSize(10);
    List<SurveyDirectory> surveys = surveyDirectoryDao.findPage(page, cri1,cri2,cri3,cri4).getResult();
    return surveys;
}
 
Example 3
Source File: SurveyDirectoryManagerImpl.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SurveyDirectory> findByT1() {
    Criterion cri1=Restrictions.eq("visibility", 1);
    Criterion cri2=Restrictions.eq("parentId", "402880e5428a2dca01428a2f1f290000");
    Criterion cri3=Restrictions.eq("surveyTag", 1);
    Criterion cri4=Restrictions.isNull("sid");
    Page<SurveyDirectory> page=new Page<SurveyDirectory>();
    page.setOrderBy("createDate");
	page.setOrderDir("desc");
	page.setPageSize(10);
    List<SurveyDirectory> surveys = surveyDirectoryDao.findPage(page, cri1,cri2,cri3,cri4).getResult();
    return surveys;
}
 
Example 4
Source File: CriteriaUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static org.hibernate.criterion.Criterion getRestrictionCriterion(RestrictionCriterionTypes restriction, String propertyName) {
	if (PROPERTY_NAME_REGEXP.matcher(propertyName).find()) {
		switch (restriction) {
			case IS_NULL:
				return Restrictions.isNull(propertyName);
			case IS_NOT_NULL:
				return Restrictions.isNotNull(propertyName);
			default:
				throw new IllegalArgumentException(MessageFormat.format(UNSUPPORTED_UNARY_RESTRICTION_CRITERION_TYPE, restriction.toString()));
		}
	} else {
		return Restrictions.sqlRestriction(MessageFormat.format(restriction.toString(), propertyName));
	}
}
 
Example 5
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(PropertyIsNull filter, Object userData) {
	String propertyName = getPropertyName(filter.getExpression());
	String finalName = parsePropertyName(propertyName, userData);
	return Restrictions.isNull(finalName);
}
 
Example 6
Source File: TaskManagerBean.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<DocumentDTO> getNewTaskCollection(Long crisisID, Integer count, String order, Criterion criterion) {
	logger.debug("Received request for crisisID = " + crisisID + ", count = " + count);
	String aliasTable = "taskAssignments";
	String aliasTableKey = "taskAssignments.id.documentId";
	String[] orderBy = {"valueAsTrainingSample","documentId"};
	Criterion newCriterion = criterion;
	if (criterion != null) {
		newCriterion = Restrictions.conjunction()
				.add(criterion)
				.add(Restrictions.eq("collection.id",crisisID))
				.add(Restrictions.eq("hasHumanLabels",false));
	} else {
		newCriterion = Restrictions.conjunction()
				.add(Restrictions.eq("collection.id",crisisID))
				.add(Restrictions.eq("hasHumanLabels",false));
	}
	Criterion aliasCriterion =  (Restrictions.isNull(aliasTableKey));
	try {
		List<Document> docList = remoteDocumentEJB.getByCriteriaWithAliasByOrder(newCriterion, order, orderBy, count, aliasTable, aliasCriterion);
		if (docList != null) {
			logger.debug("[getNewTaskCollection] Fetched size = " + docList.size());
			return createDocumentDTOList(docList);
		} else {
			return null;
		}
	} catch (Exception e) {
		logger.error("Error in getting new Task collection for crisisID: " + crisisID);
	}
	return null;
}
 
Example 7
Source File: PullRequest.java    From onedev with MIT License 4 votes vote down vote up
public static Criterion ofOpen() {
	return Restrictions.isNull("closeInfo");
}
 
Example 8
Source File: NullOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    return Restrictions.isNull( queryPath.getPath() );
}
 
Example 9
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;
}
 
Example 10
Source File: EqRestriction.java    From base-framework with Apache License 2.0 2 votes vote down vote up
public Criterion build(String propertyName, Object value) {
	
	return value == null ? Restrictions.isNull(propertyName) : Restrictions.eq(propertyName, value);
	
}