List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.RestTokenDAOImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED) @Override//w w w . j a v a 2 s .co m public void updateTokenExpiry(String hash) { Criteria criteria = getSession().createCriteria(RestToken.class); criteria.add(Restrictions.gt("expires", System.currentTimeMillis())); criteria.add(Restrictions.eq("hash", hash)); RestToken token = unique(criteria); if (token != null) { token.refreshToken(); update(token); } }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.RestTokenDAOImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED) @Override/*from w w w .ja va 2 s.c o m*/ public RestToken getToken(String hash) { Criteria criteria = getSession().createCriteria(RestToken.class); criteria.add(Restrictions.gt("expires", System.currentTimeMillis())); criteria.add(Restrictions.eq("hash", hash)); return unique(criteria); }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.TrialDAOImpl.java
License:Open Source License
@Override protected Criteria createCriteria(SearchFilter<Trial> filter) { Criteria criteria = getSession().createCriteria(Trial.class); if (filter instanceof TrialFilter) { TrialFilter cf = (TrialFilter) filter; if (cf.getStartAfter() != null) { criteria.createAlias("trialThread", "thread"); criteria.add(Restrictions.gt("thread.postTime", cf.getStartAfter())); }/*from w ww .j ava2 s. co m*/ if (cf.getRestrained() != null) { criteria.add(Restrictions.eq("restrained", cf.getRestrained())); } if (cf.getAccused() != null) { criteria.add(Restrictions.eq("accused", cf.getAccused())); } if (!cf.isWithTrialThread()) { criteria.add(Restrictions.isNull("trialThread")); } } return criteria; }
From source file:com.us.test.PageTest.java
License:Open Source License
public static void main(String[] args) { ApplicationContext app = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml"); IDao dao = app.getBean(IDao.class); DetachedCriteria criteria = dao.init(User.class); criteria.addOrder(Order.asc("uuid")); criteria.addOrder(Order.asc("name")); criteria.add(Restrictions.gt("uuid", 0l)); dao.findPage(criteria, 1, 20);/*from ww w . j a v a 2 s .c o m*/ }
From source file:com.usetheindexluke.FewerColumnsHibernate.java
License:Creative Commons License
public static void main(String[] args) { Session session = new Configuration().configure().buildSessionFactory().openSession(); try {// ww w. j a v a2 s . com Criteria q = session.createCriteria(Sales.class, "sales"); q.add(Restrictions.gt("saleDate", getSixMonthAgo())); q.createAlias("employee", "employee"); q.setProjection(Projections.projectionList().add(Projections.property("sales.saleDate"), "saleDate") .add(Projections.property("sales.eurValue"), "eurValue") .add(Projections.property("employee.lastName"), "lastName") .add(Projections.property("employee.firstName"), "firstName")); q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List<Map> result = q.list(); for (Map s : result) { String txt = " Employee: " + s.get("lastName") + " date: " + s.get("saleDate") + " EUR value: " + s.get("eurValue"); // System.out.println(txt); } } finally { session.close(); } }
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
License:Open Source License
public Criterion getCriterion() throws Exception { if (condition.equals(EQ)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNull(fullKey); } else {/*from w w w .java2s . co m*/ return Restrictions.eq(fullKey, value); } } if (condition.equals(NE)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNotNull(fullKey); } else { return Restrictions.ne(fullKey, value); } } if (condition.equals(GT)) { assertNonNullity(value); return Restrictions.gt(fullKey, value); } if (condition.equals(GE)) { assertNonNullity(value); return Restrictions.ge(fullKey, value); } if (condition.equals(LT)) { assertNonNullity(value); return Restrictions.lt(fullKey, value); } if (condition.equals(LE)) { assertNonNullity(value); return Restrictions.le(fullKey, value); } if (condition.equals(IN_A_RANGE)) { assertNonNullity(value); assertNonNullity(diff); return getPercentRange(); } if (condition.equals(ENDS_WITH)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString())); } if (condition.equals(STARTS_WITH)) { return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%"); } if (condition.equals(CONTAINS)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'); } if (condition.equals(NOT_CONTAIN)) { return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%')); } LOGGER.error( "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion", fullKey, value, condition); throw new RuntimeException("Undefined User Criteria: " + name); }
From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*www .j a v a 2s . c o m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final PropertyFilter.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 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); } return criterion; }
From source file:com.xbwl.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * Criterion,./*from w ww.j ava2 s. c o m*/ */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName"); Criterion criterion = null; try { //MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.xin.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./* w w w. ja v a 2 s . co m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { AssertUtils.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 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); } return criterion; }
From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java
License:Apache License
@Override public Criterion apply(FilterPredicate filterPredicate) { List<FilterPredicate.PathElement> path = filterPredicate.getPath(); /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */ String alias;//from w ww .j av a 2 s.co m if (path.size() > 1) { alias = getAlias(path); alias = alias + "." + path.get(path.size() - 1).getFieldName(); /* If the predicate refers to the root entity, the restriction should be 'fieldName' */ } else { alias = path.get(0).getFieldName(); } switch (filterPredicate.getOperator()) { case IN: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(false)"); } return Restrictions.in(alias, filterPredicate.getValues()); case NOT: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(true)"); } return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues())); case PREFIX: return Restrictions.like(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case PREFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case POSTFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case POSTFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case INFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case INFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case ISNULL: return Restrictions.isNull(alias); case NOTNULL: return Restrictions.isNotNull(alias); case LT: return Restrictions.lt(alias, filterPredicate.getValues().get(0)); case LE: return Restrictions.le(alias, filterPredicate.getValues().get(0)); case GT: return Restrictions.gt(alias, filterPredicate.getValues().get(0)); case GE: return Restrictions.ge(alias, filterPredicate.getValues().get(0)); case TRUE: return Restrictions.sqlRestriction("(true)"); case FALSE: return Restrictions.sqlRestriction("(false)"); default: throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator()); } }