下面列出了org.hibernate.criterion.Restrictions#isNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
}
@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;
}
@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;
}
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));
}
}
/** {@inheritDoc} */
@Override
public Object visit(PropertyIsNull filter, Object userData) {
String propertyName = getPropertyName(filter.getExpression());
String finalName = parsePropertyName(propertyName, userData);
return Restrictions.isNull(finalName);
}
@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;
}
public static Criterion ofOpen() {
return Restrictions.isNull("closeInfo");
}
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
return Restrictions.isNull( queryPath.getPath() );
}
/**
* 按属性条件参数创建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;
}
public Criterion build(String propertyName, Object value) {
return value == null ? Restrictions.isNull(propertyName) : Restrictions.eq(propertyName, value);
}