下面列出了怎么用org.hibernate.criterion.Criterion的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public List<ConfidenceData> getDataAfterTimestampGranularityInBin(String crisisCode, String attributeCode, String labelCode,
Long timestamp, Long granularity, Integer bin) {
Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.eq("attributeCode", attributeCode))
.add(Restrictions.eq("labelCode", labelCode))
.add(Restrictions.ge("timestamp", timestamp))
.add(Restrictions.eq("granularity", granularity))
.add(Restrictions.eq("bin", bin));
criteria.add(criterion);
try {
List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception", e);
e.printStackTrace();
}
return null;
}
@Sessional
@Override
public Map<ProjectAndBranch, PullRequest> findEffectives(ProjectAndBranch target, Collection<ProjectAndBranch> sources) {
EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
Collection<Criterion> criterions = new ArrayList<>();
for (ProjectAndBranch source: sources) {
Criterion merged = Restrictions.and(
Restrictions.eq(PullRequest.PROP_CLOSE_INFO + "." + CloseInfo.PROP_STATUS, CloseInfo.Status.MERGED),
Restrictions.eq(PullRequest.PROP_LAST_MERGE_PREVIEW + "." + MergePreview.PROP_HEAD_COMMIT_HASH, source.getObjectName()));
criterions.add(Restrictions.and(ofTarget(target), ofSource(source), Restrictions.or(ofOpen(), merged)));
}
criteria.add(Restrictions.or(criterions.toArray(new Criterion[0])));
Map<ProjectAndBranch, PullRequest> requests = new HashMap<>();
for(PullRequest request: query(criteria))
requests.put(new ProjectAndBranch(request.getSourceProject(), request.getSourceBranch()), request);
return requests;
}
/**
* Load all tablecolumn column linked to a table.
*
* @param session
* the session
*
* @return List of meta tables
*
* @throws EMFUserError
* the EMF user error
*
* @see it.eng.spagobi.metadata.dao.ISbiMetaTableColumnDAOHibImpl#loadTableColumnsFromTable(session, tableId)
*/
@Override
public List<SbiMetaTableColumn> loadTableColumnsFromTable(Session session, int tableId) throws EMFUserError {
logger.debug("IN");
List<SbiMetaTableColumn> toReturn = null;
try {
Criterion labelCriterrion = Expression.eq("sbiMetaTable.tableId", tableId);
Criteria criteria = session.createCriteria(SbiMetaTableColumn.class);
criteria.add(labelCriterrion);
toReturn = criteria.list();
} catch (HibernateException he) {
logException(he);
throw new HibernateException(he);
} finally {
logger.debug("OUT");
}
return toReturn;
}
@Override
public List<ConfidenceData> getDataInIntervalWithBin(String crisisCode, String attributeCode, String labelCode, Long timestamp1,
Long timestamp2, Integer bin) {
Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.eq("attributeCode", attributeCode))
.add(Restrictions.eq("labelCode", labelCode))
.add(Restrictions.ge("timestamp", timestamp1))
.add(Restrictions.le("timestamp", timestamp2))
.add(Restrictions.ge("bin", bin));
criteria.add(criterion);
try {
List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception", e);
e.printStackTrace();
}
return null;
}
@Override
public List<ConfidenceData> getDataByCrisisWithBin(String crisisCode, Integer bin) {
Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.ge("bin", bin));
criteria.add(criterion);
try {
List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception", e);
e.printStackTrace();
}
return null;
}
@Override
public List<ConfidenceData> getDataBeforeTimestampInBin(String crisisCode, String attributeCode, String labelCode,
Long timestamp, Integer bin) {
Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.eq("attributeCode", attributeCode))
.add(Restrictions.eq("labelCode", labelCode))
.add(Restrictions.le("timestamp", timestamp))
.add(Restrictions.eq("bin", bin));
criteria.add(criterion);
try {
List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception", e);
e.printStackTrace();
}
return null;
}
@Override
public List<TagData> getDataBeforeTimestampGranularity(String crisisCode, String attributeCode, String labelCode,
Long timestamp, Long granularity) {
Criteria criteria = getCurrentSession().createCriteria(TagData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.eq("attributeCode", attributeCode))
.add(Restrictions.le("timestamp", timestamp))
.add(Restrictions.eq("granularity", granularity));
if (labelCode != null) {
criterion = Restrictions.conjunction()
.add(criterion)
.add(Restrictions.eq("labelCode", labelCode));
}
criteria.add(criterion);
try {
List<TagData> objList = (List<TagData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception in getDataBeforeTimestampGranularity for crisisCode : " + crisisCode
+ " attributeCode : " + attributeCode + " timestamp : " + timestamp
+ " granularity : " + granularity, e);
}
return null;
}
@Override
public List<ConfidenceData> getDataAfterTimestamp(String crisisCode, String attributeCode, String labelCode, Long timestamp) {
Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisCode", crisisCode))
.add(Restrictions.eq("attributeCode", attributeCode))
.add(Restrictions.eq("labelCode", labelCode))
.add(Restrictions.ge("timestamp", timestamp));
criteria.add(criterion);
try {
List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
return objList;
} catch (HibernateException e) {
logger.error("exception", e);
e.printStackTrace();
}
return null;
}
@Test
public void testPaginatedQueryWitCriterionWithLimit() {
int numberOfElements = 817;
String identifier = "testPaginatedQueryWitCriterionWithLimit";
generateDataTest(identifier, numberOfElements);
//
DataField[] structure = dataField.toArray(new DataField[]{});
HibernateStorage storage = HibernateStorage.newInstance(dbInfo, identifier, dataField.toArray(new DataField[]{}), false);
assertNotNull(storage);
//
int[] pageSizes = new int[]{1, 11, numberOfElements / 2, numberOfElements / 3, numberOfElements / 3 - 1, numberOfElements / 3 + 1, numberOfElements - 1, numberOfElements + 1, numberOfElements * 2};
//
for (int pageSize : pageSizes) {
System.out.println("testPaginatedQueryWitCriterionWithLimit with pageSize: " + pageSize);
// Set the limit to a fixed number: 1 and timed > numberOfElements/2
checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 1), numberOfElements/2+1, numberOfElements/2+1);
// Set the limit to a fixed number: 11 and timed > numberOfElements/2
checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 11), numberOfElements/2+1, numberOfElements/2+11);
// Set the limit to 0 and timed > numberOfElements/2
checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 0), -1, -1);
}
}
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;
}
@Override
public Role findByRoleType(RoleType roleType) {
Role role = null;
try {
Criteria criteria = getHibernateTemplate().getSessionFactory()
.getCurrentSession().createCriteria(Role.class);
Criterion criterion = Restrictions.eq("roleType", roleType);
criteria.add(criterion);
role = (Role) criteria.uniqueResult();
} catch(Exception e) {
logger.error("Error in fetching data by roleType : " +roleType, e);
}
return role;
}
@Override
public List<DocumentDTO> findLabeledDocumentsByCrisisID(Long crisisId) throws PropertyNotSetException {
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("collection.id",crisisId))
.add(Restrictions.eq("hasHumanLabels", true));
List<DocumentDTO> dtoList = new ArrayList<DocumentDTO>();
List<Document> list = this.getAllByCriteria(criterion);
if (list != null && !list.isEmpty()) {
for (Document doc : list) {
DocumentDTO dto = new DocumentDTO(doc);
dtoList.add(dto);
}
}
logger.info("Done creating DTO list, size = " + dtoList.size());
return dtoList;
}
@Override
public List<CustomUiTemplateDTO> getCustomUITemplateBasedOnTypeByCrisisIDAttributeIDAndStatus(long crisisID, long attributeID, int templateType, int status) {
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("crisisID",crisisID))
.add(Restrictions.eq("templateType", templateType))
.add(Restrictions.eq("nominalAttributeID", attributeID))
.add(Restrictions.eq("status", status));
List<CustomUiTemplateDTO> dtoList = null;
try {
List<CustomUiTemplate> customUITemplates = this.getAllByCriteria(criterion);
if (customUITemplates != null) {
dtoList = new ArrayList<CustomUiTemplateDTO>(0);
for (CustomUiTemplate c: customUITemplates) {
CustomUiTemplateDTO dto = new CustomUiTemplateDTO(c);
dtoList.add(dto);
}
}
return dtoList;
} catch (Exception e) {
logger.error("Error in getCustomUITemplateBasedOnTypeByCrisisIDAttributeIDAndStatus for crisisID : " + crisisID
+ " and attributeID : " + attributeID);
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public List<T> findAllByCriteria(Criterion criterion){
try {
Criteria crit = getSession().createCriteria(getPersistentClass());
crit.add(criterion);
return crit.list();
} catch (Exception e) {
// e.printStackTrace();
getTransaction().rollback();
return null;
}
}
public Article findUnique(Criterion... criterions) {
Criteria criteria = getSession().createCriteria(Article.class);
for (Criterion c : criterions) {
criteria.add(c);
}
criteria.setCacheable(true);
return (Article)criteria.uniqueResult();
}
@Override
public TaskAnswerDTO getTaskAnswer(Long documentID, Long userID) {
Criterion criterion = Restrictions.conjunction()
.add(Restrictions.eq("id.documentId", documentID))
.add(Restrictions.eq("id.userId", userID));
TaskAnswer t = getByCriteria(criterion);
return t != null ? new TaskAnswerDTO(t) : null;
}
public Article findUnique(Criterion... criterions) {
Criteria criteria = getSession().createCriteria(Article.class);
for (Criterion c : criterions) {
criteria.add(c);
}
criteria.setCacheable(true);
return (Article)criteria.uniqueResult();
}
/**
* Load bi object by label.
*
* @param label the label
* @return the BI object
* @throws EMFUserError the EMF user error
* @see it.eng.spagobi.analiticalmodel.document.dao.IBIObjectDAO#loadBIObjectByLabel(java.lang.String)
*/
@Override
public BIObject loadBIObjectByLabel(String label) throws EMFUserError {
logger.debug("IN");
BIObject biObject = null;
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
Criterion labelCriterrion = Expression.eq("label", label);
Criteria criteria = aSession.createCriteria(SbiObjects.class);
criteria.add(labelCriterrion);
SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();
if (hibObject != null) {
biObject = toBIObject(hibObject, aSession);
} else {
logger.warn("Unable to load document whose label is equal to [" + label + "]");
}
tx.commit();
} catch (HibernateException he) {
logger.error(he);
he.printStackTrace();
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
logger.debug("OUT");
return biObject;
}
@Override
public List<SbiMetaTable> loadTablesFromSource(int sourceId) throws EMFUserError {
logger.debug("IN");
List toReturn = null;
Session tmpSession = null;
Transaction tx = null;
try {
tmpSession = getSession();
tx = tmpSession.beginTransaction();
Criterion labelCriterrion = Expression.eq("sourceid", sourceId);
Criteria criteria = tmpSession.createCriteria(SbiMetaTable.class);
criteria.add(labelCriterrion);
toReturn = criteria.list();
if (toReturn == null)
return null;
tx.commit();
} catch (HibernateException he) {
logException(he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
if (tmpSession != null) {
if (tmpSession.isOpen())
tmpSession.close();
}
}
logger.debug("OUT");
return toReturn;
}
/**
* This implementation does not support the 'offset' parameter. The maxResultSize parameter is not used (limiting
* the result needs to be done after security {@link org.geomajas.internal.layer.vector.GetFeaturesEachStep}). If
* you expect large results to be returned enable scrollableResultSet to retrieve only as many records as needed.
*/
public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException {
try {
Session session = getSessionFactory().getCurrentSession();
Criteria criteria = session.createCriteria(getFeatureInfo().getDataSourceName());
if (filter != null) {
if (filter != Filter.INCLUDE) {
CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) featureModel, dateFormat);
Criterion c = (Criterion) filter.accept(visitor, criteria);
if (c != null) {
criteria.add(c);
}
}
}
// Sorting of elements.
if (getFeatureInfo().getSortAttributeName() != null) {
if (SortType.ASC.equals(getFeatureInfo().getSortType())) {
criteria.addOrder(Order.asc(getFeatureInfo().getSortAttributeName()));
} else {
criteria.addOrder(Order.desc(getFeatureInfo().getSortAttributeName()));
}
}
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
if (isScrollableResultSet()) {
return (Iterator<?>) new ScrollIterator(criteria.scroll());
} else {
List<?> list = criteria.list();
return list.iterator();
}
} catch (HibernateException he) {
throw new HibernateLayerException(he, ExceptionCode.HIBERNATE_LOAD_FILTER_FAIL, getFeatureInfo()
.getDataSourceName(), filter.toString());
}
}
@Test
public void should_add_filter_if_user_is_not_logged_in() {
LoggedUser user = new LoggedUser(null, null);
InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);
invisibleForUsersRule.addFilter("x", criteria);
verify(criteria, only()).add(Mockito.any(Criterion.class));
}
@SuppressWarnings("unchecked")
public E findByCriterionID(Criterion criterion) {
Criteria criteria = getCurrentSession().createCriteria(entityClass);
criteria.add(criterion);
try {
return (E) criteria.uniqueResult();
} catch (HibernateException e) {
logger.error("Error in findByCriterionID for criteria : " + criteria.toString(),e);
return null;
}
}
/**
* 用户列表查询
* @param request
* @param response
* @param dataGrid
*/
@RequestMapping(params = "roleUserDatagrid")
public void roleUserDatagrid(TSUser user,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
CriteriaQuery cq = new CriteriaQuery(TSUser.class, dataGrid);
//查询条件组装器
String roleId = request.getParameter("roleId");
List<TSRoleUser> roleUser = systemService.findByProperty(TSRoleUser.class, "TSRole.id", roleId);
/*
// zhanggm:这个查询逻辑也可以使用这种 子查询的方式进行查询
CriteriaQuery subCq = new CriteriaQuery(TSRoleUser.class);
subCq.setProjection(Property.forName("TSUser.id"));
subCq.eq("TSRole.id", roleId);
subCq.add();
cq.add(Property.forName("id").in(subCq.getDetachedCriteria()));
cq.add();
*/
Criterion cc = null;
if (roleUser.size() > 0) {
for(int i = 0; i < roleUser.size(); i++){
if(i == 0){
cc = Restrictions.eq("id", roleUser.get(i).getTSUser().getId());
}else{
cc = cq.getor(cc, Restrictions.eq("id", roleUser.get(i).getTSUser().getId()));
}
}
}else {
cc =Restrictions.eq("id", "-1");
}
cq.add(cc);
cq.eq("deleteFlag", Globals.Delete_Normal);
cq.add();
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, user);
this.systemService.getDataGridReturn(cq, true);
TagUtil.datagrid(response, dataGrid);
}
@Override
public List<SbiMetaBcAttribute> loadAllBCAttributeFromTableColumn(int columnId) throws EMFUserError {
logger.debug("IN");
List toReturn = null;
Session tmpSession = null;
Transaction tx = null;
try {
tmpSession = getSession();
tx = tmpSession.beginTransaction();
Criterion labelCriterrion = Expression.eq("columnId", columnId);
Criteria criteria = tmpSession.createCriteria(SbiMetaTableColumn.class);
criteria.add(labelCriterrion);
toReturn = criteria.list();
if (toReturn == null)
return null;
tx.commit();
} catch (HibernateException he) {
logException(he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
if (tmpSession != null) {
if (tmpSession.isOpen())
tmpSession.close();
}
}
logger.debug("OUT");
return toReturn;
}
@SuppressWarnings("unchecked")
public String list() {
int pageNum=1;
int pageSize=20;
String name=getRequest().getParameter("name");
String queryOrderBy=getRequest().getParameter("queryOrderBy");
String pageSizeStr=getRequest().getParameter("pageSize");
String pageNumStr=getRequest().getParameter("pageNo");
Set<Criterion> criterions=new HashSet<Criterion>(2);
Set<Order> orders=new HashSet<Order>(1);
Order orderByIdDesc=Order.desc("id");
orders.add(orderByIdDesc);
if(!StringUtil.isNullOrEmpty(name)){
criterions.add(Restrictions.like("name", "%"+name.trim()+"%"));
}
if(!StringUtil.isNullOrEmpty(queryOrderBy)&&queryOrderBy.equals("asc")){
orders.remove(orderByIdDesc);
orders.add(Order.asc("id"));
}
if(!StringUtil.isNullOrEmpty(pageSizeStr)){
pageSize=Integer.parseInt(pageSizeStr);
}
if (!StringUtil.isNullOrEmpty(pageNumStr)) {
pageNum=Integer.parseInt(pageNumStr);
}
Page page=tagService.pageCQuery(pageNum, pageSize, criterions,orders,"id");
getContextMap().put("page", page);
getContextMap().put("params", getParameters());
return "list";
}
@Test
public void should_add_filter_if_user_is_not_moderator() {
LoggedUser user = new LoggedUser(user("leonardo", "[email protected]"), null);
InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);
invisibleForUsersRule.addFilter("x", criteria);
verify(criteria, only()).add(Mockito.any(Criterion.class));
}
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAllEntities(Class<T> entityClass, List<Criterion> criterions, String orderField, boolean orderAsc) {
Session session = null;
try {
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(entityClass);
for (Criterion criterion : criterions) {
criteria.add(criterion);
}
criteria.addOrder(orderAsc ? Order.asc(orderField) : Order.desc(orderField));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return criteria.list();
} finally {
if(session != null) {
session.close();
}
}
}
@Test
public void should_not_add_filter_if_user_is_moderator() {
LoggedUser user = new LoggedUser(user("leonardo", "[email protected]").asModerator(), null);
ModeratorOrVisibleNewsFilter moderatorOrVisible = new ModeratorOrVisibleNewsFilter(user, null);
moderatorOrVisible.addFilter("x", criteria);
verify(criteria, never()).add(Mockito.any(Criterion.class));
}
@Override
public ResponseWrapper removeTrainingExample(Long documentID) {
// Alternative way of doing the same update
//qa.qcri.aidr.task.dto.DocumentDTO fetchedDoc = remoteTaskManager.getTaskById(id);
//fetchedDoc.setHasHumanLabels(false);
//fetchedDoc.setNominalLabelCollection(null);
//taskManager.updateTask(fetchedDoc);
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("setHasHumanLabels", new Boolean(false).toString());
try {
DocumentDTO newDoc = (DocumentDTO) remoteTaskManager.setTaskParameter(qa.qcri.aidr.dbmanager.entities.task.Document.class, documentID, paramMap);
if (newDoc != null) {
Criterion criterion = Restrictions.eq("id.documentId", documentID);
remoteDocumentNominalLabel.deleteByCriteria(criterion);
if (!remoteDocumentNominalLabel.isDocumentExists(documentID)) {
logger.info("Removed training example: " + newDoc.getDocumentID() + ", for crisisID = " + newDoc.getCrisisDTO().getCrisisID());
return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_SUCCESS),
"Deleted training example id " + documentID);
} else {
logger.error("Could NOT remove document from document nominal label table! id = " + documentID + "hasHumanLabels = " + remoteDocument.findDocumentByID(documentID).getHasHumanLabels());
return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
"Error while deleting training example id " + documentID);
}
} else {
logger.error("Could NOT remove document from document nominal label table! id = " + documentID + "hasHumanLabels = " + remoteDocument.findDocumentByID(documentID).getHasHumanLabels());
return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
"Error while deleting training example id " + documentID);
}
} catch (Exception e) {
logger.error("Error while deleting training example id " + documentID, e);
return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
"Error while deleting training example id " + documentID);
}
}
/**
* 按属性条件参数创建Criterion,辅助函数.
*/
protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) {
AssertUtils.hasText(propertyName, "propertyName不能为空");
Criterion criterion = null;
//根据MatchType构造criterion
switch (matchType) {
case EQ:
criterion = Restrictions.eq(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 NE:
criterion = Restrictions.ne(propertyName, propertyValue);
}
return criterion;
}