List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:co.com.siscomputo.administracion.logic.RolesLogic.java
/** * Mtodo que crea la lista de roles del sistema * * @param idRol// w ww . j a va 2 s . com * @return */ public RolesEntity rolPorId(int idRol) { RolesEntity retorna = new RolesEntity(); try { initOperation(); Criteria criteria = sesion.createCriteria(RolesEntity.class); criteria.add(Restrictions.ne("estado_rol", "E")); criteria.add(Restrictions.eq("id_rol", idRol)); retorna = (RolesEntity) criteria.uniqueResult(); retorna.setTrazaRespuesta("Carga de Roles exitosa"); retorna.setNumeroRespuesta(12); } catch (Exception e) { retorna.setNumeroRespuesta(3); retorna.setTrazaRespuesta("ERROR: " + e); e.printStackTrace(); } finally { try { sesion.close(); } catch (HibernateException hibernateException) { hibernateException.printStackTrace(); } } return retorna; }
From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java
License:Open Source License
private Criterion differentPricingTemplateOrNull(final PricingTemplate pricingTemplate) { Disjunction filterDisjunction = Restrictions.disjunction(); filterDisjunction.add(Restrictions.ne(Enterprise.PRICING_PROPERTY, pricingTemplate)); filterDisjunction.add(Restrictions.isNull(Enterprise.PRICING_PROPERTY)); return filterDisjunction; // return Restrictions.eq(Enterprise.PRICING_PROPERTY, pricingTemplate); }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
public List<Machine> findRackEnabledForHAMachines(final Rack rack) { if (rack instanceof UcsRack) { return findRackEnabledForHAMachinesInUcs((UcsRack) rack); }//from w w w . ja v a 2 s. co m Criteria criteria = createCriteria(sameRack(rack)); criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor"); // Is a managed one criteria.add(Restrictions.eq(Machine.STATE_PROPERTY, MachineState.MANAGED)); // Has fencing capabilities criteria.add(Restrictions.isNotNull(Machine.IPMI_IP_PROPERTY)); criteria.add(Restrictions.isNotNull(Machine.IPMI_USER_PROPERTY)); criteria.add(Restrictions.isNotNull(Machine.IPMI_PASSWORD_PROPERTY)); // XenServer does not support HA criteria.add(Restrictions.ne("hypervisor." + Hypervisor.TYPE_PROPERTY, HypervisorType.XENSERVER)); // Order by name criteria.addOrder(Order.asc(Machine.NAME_PROPERTY)); return getResultList(criteria); }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
public List<Machine> findRackEnabledForHAMachinesInUcs(final UcsRack rack) { Criteria criteria = createCriteria(sameRack(rack)); criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor"); // Is a managed one criteria.add(Restrictions.eq(Machine.STATE_PROPERTY, MachineState.MANAGED)); // XenServer does not support HA criteria.add(Restrictions.ne("hypervisor." + Hypervisor.TYPE_PROPERTY, HypervisorType.XENSERVER)); // Order by name criteria.addOrder(Order.asc(Machine.NAME_PROPERTY)); return getResultList(criteria); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??Criterion,.//from w w w . j a v 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
/** * ??/* w w w.j a va2 s. com*/ */ 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.aistor.modules.cms.service.ArticleService.java
License:Open Source License
public Page<Article> find(Page<Article> page, Article article) { DetachedCriteria dc = articleDao.createDetachedCriteria(); dc.createAlias("category", "category"); dc.createAlias("category.site", "category.site"); if (article.getCategory() != null && article.getCategory().getId() != null && !Category.isRoot(article.getCategory().getId())) { Category category = categoryDao.findOne(article.getCategory().getId()); if (category != null) { dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()), Restrictions.eq("category.parent.id", category.getId()), Restrictions.like("category.parentIds", "%," + category.getId() + ",%"))); dc.add(Restrictions.eq("category.site.id", category.getSite().getId())); article.setCategory(category); } else {// w w w . j a v a 2s.c o m dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } if (StringUtils.isNotEmpty(article.getTitle())) { dc.add(Restrictions.like("title", "%" + article.getTitle() + "%")); } if (StringUtils.isNotEmpty(article.getPosid())) { dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%")); } if (StringUtils.isNotEmpty(article.getThumb()) && "1".equals(article.getThumb())) { dc.add(Restrictions.and(Restrictions.isNotNull("thumb"), Restrictions.ne("thumb", ""))); } if (article.getUser() != null && article.getUser().getId() > 0) { dc.add(Restrictions.eq("user.id", article.getUser().getId())); } dc.add(Restrictions.eq("status", article.getStatus())); dc.addOrder(Order.desc("weight")); dc.addOrder(Order.desc("updateDate")); return articleDao.find(page, dc); }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. * * @param criteria/*from ww w .j av a2 s .com*/ * @param parameterName * @param parameterValue * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object parameterValue, int comparator, MatchMode matchMode) { switch (comparator) { case SearchParameter.NOT_NULL_COMPARATOR: { criteria.add(Restrictions.isNotNull(parameterName)); break; } case SearchParameter.NULL_COMPARATOR: { criteria.add(Restrictions.isNull(parameterName)); break; } case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { if (parameterValue != null) { switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.like(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.like(parameterName, parameterValue)); } break; } case SearchParameter.NOT_LIKE_COMPARATOR: { SimpleExpression expression; if ((matchMode != null) && (parameterValue instanceof String)) { expression = Restrictions.like(parameterName, (String) parameterValue, matchMode); } else { expression = Restrictions.like(parameterName, parameterValue); } criteria.add(Restrictions.not(expression)); break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.ilike(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.ilike(parameterName, parameterValue)); } break; } case SearchParameter.NOT_INSENSITIVE_LIKE_COMPARATOR: { Criterion criterion; if ((matchMode != null) && (parameterValue instanceof String)) { criterion = Restrictions.ilike(parameterName, (String) parameterValue, matchMode); } else { criterion = Restrictions.ilike(parameterName, parameterValue); } criteria.add(Restrictions.not(criterion)); break; } case SearchParameter.EQUAL_COMPARATOR: { criteria.add(Restrictions.eq(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.ge(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_COMPARATOR: { criteria.add(Restrictions.gt(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.le(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_COMPARATOR: { criteria.add(Restrictions.lt(parameterName, parameterValue)); break; } case SearchParameter.IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.in(parameterName, (Collection) parameterValue)); } break; } case SearchParameter.NOT_IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.not(Restrictions.in(parameterName, (Collection) parameterValue))); } break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { criteria.add(Restrictions.ne(parameterName, parameterValue)); break; } } } else { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code> * represents either an array of <code>String</code> or another object. The different values in the * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the * search./*from www .j av a 2 s. c o m*/ * * @param criteria * @param parameterName * @param parameterValues * @param searchIfNull * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator, MatchMode matchMode) { if (parameterValues != null) { Disjunction disjunction = null; Conjunction conjunction = null; switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.like(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( Restrictions.ilike(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ilike(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.eq(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ge(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.gt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.le(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.lt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.IN_COMPARATOR: { criteria.add(Restrictions.in(parameterName, parameterValues)); break; } case SearchParameter.NOT_IN_COMPARATOR: { criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues))); break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { conjunction = Restrictions.conjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { conjunction.add(Restrictions.ne(parameterName, parameterValues[index])); } else { conjunction.add(Restrictions.isNotNull(parameterName)); } } break; } } if (disjunction != null) { criteria.add(disjunction); } if (conjunction != null) { criteria.add(conjunction); } } else { switch (comparator) { case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.app.gpo.dao.OrderItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<OrderItem> findNotOrderStatus(OrderStatus orderStatus) { Criteria criteria = createEntityCriteria(); criteria.add(Restrictions.ne("orderStatus", orderStatus)); List<OrderItem> orderItems = (List<OrderItem>) criteria.list(); for (OrderItem s : orderItems) { Hibernate.initialize(s.getorderStatus()); Hibernate.initialize(s.getorderItemFields()); }// w w w . j a v a2s .co m return orderItems; }