List of usage examples for org.hibernate.criterion MatchMode END
MatchMode END
To view the source code for org.hibernate.criterion MatchMode END.
Click Source Link
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??Criterion,./*from w w w . j av a 2 s . c o m*/ */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object[] propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName should not be null!"); Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??/*from w w w. jav a2 s. co m*/ */ private Criterion getCriterion(String propertyName, Object[] propertyValue, MatchType matchType) { Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, String.valueOf(propertyValue[0]), MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } else if (MatchType.LEN.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.algoTrader.PropertySearch.java
/** * Constructor for PropertySearch. Creates a <code>PropertySearch</code> instance * from the given arguments.//from www .j av a 2 s.c o m * * @param session The Hibernate session. * @param entityType The <code>Class</code> of the result. * @param searchIn the object that specifies the search criteria. */ public PropertySearch(final Session session, final Class entityType, final Search searchIn) { super(session, entityType); this.search = searchIn; try { this.initializeConverters(); this.getConfiguration().setForceEagerLoading(searchIn.isEagerFetching()); final SearchParameter[] parameters = searchIn.getParameters(); if (parameters != null) { for (int ctr = 0; ctr < parameters.length; ctr++) { final SearchParameter searchParameter = parameters[ctr]; Object value; switch (searchParameter.getComparator()) { case SearchParameter.IN_COMPARATOR: value = searchParameter.getValue(); break; case SearchParameter.NOT_IN_COMPARATOR: value = searchParameter.getValue(); break; default: value = this.getValue(entityType, searchParameter); break; } // - now add the parameter. final CriteriaSearchParameter parameter = new CriteriaSearchParameter(value, searchParameter.getName(), searchParameter.getComparator()); parameter.setOrderDirection(searchParameter.getOrder()); parameter.setSearchIfNull(searchParameter.isSearchIfNull()); switch (searchParameter.getMatch()) { case SearchParameter.MATCH_ANYWHERE: parameter.setMatchMode(MatchMode.ANYWHERE); break; case SearchParameter.MATCH_START: parameter.setMatchMode(MatchMode.START); break; case SearchParameter.MATCH_END: parameter.setMatchMode(MatchMode.END); break; default: parameter.setMatchMode(MatchMode.EXACT); break; } this.addParameter(parameter); if (searchIn.isUseSqlLimiting()) { if (searchIn.getPageNumber() > 0 && searchIn.getPageSize() > 0) { // - set the first result as part of pagination support this.getConfiguration().setFirstResult(new Integer( this.calculateFirstResult(searchIn.getPageNumber(), searchIn.getPageSize()))); this.getConfiguration().setMaximumResultSize(new Integer(searchIn.getPageSize())); } } } } } catch (Exception exception) { throw new RuntimeException(exception); } }
From source file:com.eryansky.common.orm.core.hibernate.restriction.support.LLikeRestriction.java
License:Apache License
public Criterion build(String propertyName, Object value) { return Restrictions.like(propertyName, value.toString(), MatchMode.END); }
From source file:com.evolveum.midpoint.repo.sql.query.matcher.Matcher.java
License:Apache License
protected Criterion basicMatch(ItemRestrictionOperation operation, String propertyName, Object value, boolean ignoreCase) throws QueryException { Criterion criterion;/*from w w w. ja va2s . c o m*/ switch (operation) { case EQ: if (value == null) { criterion = Restrictions.isNull(propertyName); } else { criterion = Restrictions.eq(propertyName, value); } break; case GT: criterion = Restrictions.gt(propertyName, value); break; case GE: criterion = Restrictions.ge(propertyName, value); break; case LT: criterion = Restrictions.lt(propertyName, value); break; case LE: criterion = Restrictions.le(propertyName, value); break; case NOT_NULL: criterion = Restrictions.isNotNull(propertyName); break; case NULL: criterion = Restrictions.isNull(propertyName); break; case STARTS_WITH: criterion = Restrictions.like(propertyName, (String) value, MatchMode.START); break; case ENDS_WITH: criterion = Restrictions.like(propertyName, (String) value, MatchMode.END); break; case SUBSTRING: criterion = Restrictions.like(propertyName, (String) value, MatchMode.ANYWHERE); break; default: throw new QueryException("Unknown operation '" + operation + "'."); } if (ignoreCase && (value instanceof String) && (criterion instanceof SimpleExpression)) { criterion = ((SimpleExpression) criterion).ignoreCase(); } return criterion; }
From source file:com.evolveum.midpoint.repo.sql.query2.matcher.Matcher.java
License:Apache License
protected Condition basicMatch(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyPath, Object value, boolean ignoreCase) throws QueryException { Validate.notNull(hibernateQuery, "hibernateQuery"); if (ignoreCase && !(value instanceof String)) { LOGGER.warn("Ignoring ignoreCase setting for non-string value of {}", value); ignoreCase = false;/*www. ja v a 2 s. c o m*/ } Condition condition; switch (operation) { case EQ: if (value == null) { condition = hibernateQuery.createIsNull(propertyPath); } else { condition = hibernateQuery.createEq(propertyPath, value, ignoreCase); } break; case GT: case GE: case LT: case LE: condition = hibernateQuery.createSimpleComparisonCondition(propertyPath, value, operation.symbol(), ignoreCase); break; case NOT_NULL: condition = hibernateQuery.createIsNotNull(propertyPath); break; case NULL: condition = hibernateQuery.createIsNull(propertyPath); break; case STARTS_WITH: condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.START, ignoreCase); break; case ENDS_WITH: condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.END, ignoreCase); break; case SUBSTRING: condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.ANYWHERE, ignoreCase); break; default: throw new QueryException("Unknown operation '" + operation + "'."); } return condition; }
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,.//from www . j a v a 2 s . c o m */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; //?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LIKEEXACT: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.EXACT); break; case LIKESTART: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.START); break; case LIKEEND: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.END); 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 NEQ: criterion = Restrictions.ne(propertyName, propertyValue); break; case ISN: criterion = Restrictions.isNull(propertyName); break; case ISNN: criterion = Restrictions.isNotNull(propertyName); break; case IN: criterion = Restrictions.in(propertyName, (Object[]) propertyValue); break; } return criterion; }
From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java
License:Open Source License
static public MatchMode getMatchMode(String val) { if (val != null && !"".equals(val)) { if (val.equals("both")) return MatchMode.ANYWHERE; if (val.equals("left")) return MatchMode.END; if (val.equals("right")) return MatchMode.START; if (val.equals("equal")) return MatchMode.EXACT; if (val.equals("like") || val.equals("ilike")) return MatchMode.START; }/*from ww w .j a va2 s . c o m*/ //default return null; }
From source file:com.lushapp.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./* w ww . j a v a 2 s . c o m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; String value; Character ESCAPE = '!'; // ?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case NE: criterion = Restrictions.ne(propertyName, propertyValue); break; case LIKE: // value = (String) propertyValue; if ((ESCAPE.toString()).equals(value)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else { criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.ANYWHERE, ESCAPE, true); } break; case SLIKE: // value = (String) propertyValue; if ((ESCAPE.toString()).equals(value)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.START); } else { criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.START, ESCAPE, true); } break; case ELIKE: // value = (String) propertyValue; if ((ESCAPE.toString()).equals(value)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.END); } else { criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.END, ESCAPE, true); } 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 ISNULL: criterion = Restrictions.isNull(propertyName); } return criterion; }
From source file:com.reignite.parser.QueryParser.java
License:Open Source License
private Criterion processField(JSONObject where) throws ParserException { String field = JSONObject.getNames(where)[0]; JSONObject exp;/*from w w w . j a va 2s .c o m*/ try { exp = where.getJSONObject(field); } catch (JSONException e) { throw new ParserException("field expressions must be JSON Object: " + field); } ExpressionType type = ExpressionType.get(JSONObject.getNames(exp)[0]); Object value = null; // if the field is a join if (field.indexOf(".") > -1) { String join = field.substring(0, field.indexOf(".")); query.createJoin(join); } switch (type) { case IN: case NOT_IN: try { value = createArray(exp.getJSONArray(type.getName())); } catch (JSONException e) { throw new ParserException("in and not in expressions must be arrays: " + exp); } break; default: try { value = createValue(exp.get(type.getName())); } catch (JSONException e) { throw new ParserException("expressions must have a value: " + exp); } } switch (type) { case GREATER_THAN: return Restrictions.gt(field, value); case IN: return Restrictions.in(field, (Object[]) value); case LESS_THAN: return Restrictions.lt(field, value); case LIKE: MatchMode match = MatchMode.EXACT; String toMatch = value.toString(); if (value.toString().startsWith("%")) { match = MatchMode.END; toMatch = toMatch.substring(1); } if (value.toString().endsWith("%")) { toMatch = toMatch.substring(0, toMatch.length() - 1); if (match == MatchMode.END) { match = MatchMode.ANYWHERE; } else { match = MatchMode.START; } } return Restrictions.ilike(field, toMatch, match); case NOT_EQUAL: if (value == null) { return Restrictions.isNotNull(field); } return Restrictions.ne(field, value); case NOT_IN: return Restrictions.not(Restrictions.in(field, (Object[]) value)); case EQUAL: default: if (value == null) { return Restrictions.isNull(field); } return Restrictions.eq(field, value); } }