List of usage examples for org.hibernate.criterion Restrictions neProperty
public static PropertyExpression neProperty(String propertyName, String otherPropertyName)
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getAssignedChildStudyListForUser(ArkUserVO arkUserVo) { List<Study> studyList = new ArrayList<Study>(0); try {/* w ww. j a v a2s . c om*/ ArkUser arkUser = getArkUser(arkUserVo.getArkUserEntity().getLdapUserName()); /* Get only the studies the ArkUser is linked to via the ArkUserRole */ Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUser)); // Restrict to child studies (without parent) Criteria studyCriteria = criteria.createCriteria("study"); studyCriteria.add(Restrictions.eq("parentStudy", arkUserVo.getStudy())); studyCriteria.add(Restrictions.neProperty("id", "parentStudy.id")); studyCriteria.addOrder(Order.asc("name")); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); studyList = criteria.list(); } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } return studyList; }
From source file:com.qcadoo.model.api.search.SearchRestrictions.java
License:Open Source License
/** * Creates criterion which checks if field isn't equal to other field. * //w w w .ja v a2 s . c o m * @param field * field * @param otherField * other field * @return criterion */ public static SearchCriterion neField(final String field, final String otherField) { return new SearchCriterionImpl(Restrictions.neProperty(field, otherField)); }
From source file:fr.gael.dhus.olingo.v1.SQLVisitor.java
License:Open Source License
private Criterion getCriterionComparative(BinaryOperator operator, Object left, Object right) { Criterion criterion = null;//w w w. ja v a2 s. c o m if (left instanceof Member) { if (right instanceof Member) { // property <operator> property String lvalue = ((Member) left).getName(); String rvalue = ((Member) right).getName(); switch (operator) { case EQ: { criterion = Restrictions.eqProperty(lvalue, rvalue); break; } case NE: { criterion = Restrictions.neProperty(lvalue, rvalue); break; } case GT: { criterion = Restrictions.gtProperty(lvalue, rvalue); break; } case GE: { criterion = Restrictions.geProperty(lvalue, rvalue); break; } case LT: { criterion = Restrictions.ltProperty(lvalue, rvalue); break; } case LE: { criterion = Restrictions.leProperty(lvalue, rvalue); break; } default: throw new UnsupportedOperationException("Unsupported operation: " + operator.toUriLiteral()); } } else { // property <operator> literal String property = ((Member) left).getName(); criterion = internalCriterionComparative(operator, property, right); } } else if (right instanceof Member) { // literal <operator> property String property = ((Member) right).getName(); criterion = internalCriterionComparative(operator, property, left); } else if (left instanceof Comparable) { // literal <operator> literal Comparable comparable = (Comparable) left; boolean bool; int result = comparable.compareTo(right); switch (operator) { case EQ: { bool = result == 0; break; } case NE: { bool = result != 0; break; } case GT: { bool = result > 0; break; } case GE: { bool = result >= 0; break; } case LT: { bool = result < 0; break; } case LE: { bool = result <= 0; break; } default: throw new UnsupportedOperationException("Unsupported operation: " + operator.toUriLiteral()); } if (bool) { criterion = Restrictions.sqlRestriction("0=0"); } else { criterion = Restrictions.sqlRestriction("0<>0"); } } return criterion; }
From source file:grails.orm.HibernateCriteriaBuilder.java
License:Apache License
/** * Creates a Criterion that compares to class properties for !equality * @param propertyName The first property name * @param otherPropertyName The second property name * @return A Criterion instance/*from w ww .j a v a2s .c om*/ */ public org.grails.datastore.mapping.query.api.Criteria neProperty(String propertyName, String otherPropertyName) { if (!validateSimpleExpression()) { throwRuntimeException(new IllegalArgumentException("Call to [neProperty] with propertyName [" + propertyName + "] and other property name [" + otherPropertyName + "] not allowed here.")); } propertyName = calculatePropertyName(propertyName); otherPropertyName = calculatePropertyName(otherPropertyName); addToCriteria(Restrictions.neProperty(propertyName, otherPropertyName)); return this; }
From source file:net.firejack.platform.core.store.AbstractStore.java
License:Apache License
protected Criterion getRestrictions(SearchQuery query, Class<?> type) { Criterion criterion;/*w w w .java2 s . co m*/ Object value = query.getValue(); QueryOperation operation = query.getOperation(); if (value != null && !(QueryOperation.FIELDEQUALS.equals(operation) || QueryOperation.FIELDNOTEQUALS.equals(operation) || QueryOperation.FIELDGREATERTHAN.equals(operation) || QueryOperation.FIELDLESSTHAN.equals(operation))) { if (value instanceof Collection) { Collection values = (Collection) value; if (Integer.class.equals(type)) { List<Integer> list = new ArrayList<Integer>(); for (Object item : values) { list.add(Integer.parseInt(item.toString())); } value = list; } else if (Long.class.equals(type)) { List<Long> list = new ArrayList<Long>(); for (Object item : values) { list.add(Long.parseLong(item.toString())); } value = list; } else if (java.sql.Date.class.equals(type) || Date.class.equals(type)) { List<Date> list = new ArrayList<Date>(); for (Object item : values) { Tuple<Date, QueryOperation> tuple = convertToDate(item, operation); operation = tuple.getValue(); list.add(tuple.getKey()); } value = list; } else if (Enum.class.isAssignableFrom(type)) { List<Enum> enumValues = new ArrayList<Enum>(values.size()); for (Object item : values) { Enum enumItem = prepareEnumFromSearchCriteria((Class<? extends Enum>) type, item); enumValues.add(enumItem); } value = enumValues; } } else { if (Integer.class.equals(type)) { value = Integer.parseInt(value.toString()); } else if (Long.class.equals(type)) { value = Long.parseLong(value.toString()); } else if (Double.class.equals(type)) { value = Double.parseDouble(value.toString()); } else if (java.sql.Date.class.equals(type) || Date.class.equals(type)) { Tuple<Date, QueryOperation> tuple = convertToDate(value, operation); value = tuple.getKey(); operation = tuple.getValue(); } else if (Enum.class.isAssignableFrom(type)) { value = prepareEnumFromSearchCriteria((Class<? extends Enum>) type, value); } } } if (!String.class.equals(type) && (QueryOperation.LIKECS.equals(operation) || QueryOperation.LIKECSFIRST.equals(operation) || QueryOperation.LIKE.equals(operation) || QueryOperation.LIKEFIRST.equals(operation))) { operation = QueryOperation.EQUALS; } switch (operation) { case LIKECS: criterion = Restrictions.like(query.getField(), "%" + value + "%"); break; case LIKECSFIRST: criterion = Restrictions.like(query.getField(), value + "%"); break; case LIKE: criterion = Restrictions.ilike(query.getField(), "%" + value + "%"); break; case LIKEFIRST: criterion = Restrictions.ilike(query.getField(), value + "%"); break; case EQUALS: criterion = Restrictions.eq(query.getField(), value); break; case LESSTHAN: criterion = Restrictions.lt(query.getField(), value); break; case GREATERTHAN: criterion = Restrictions.gt(query.getField(), value); break; case ISNULL: criterion = Restrictions.isNull(query.getField()); break; case ISNOTNULL: criterion = Restrictions.isNotNull(query.getField()); break; case ISEMPTY: criterion = Restrictions.isEmpty(query.getField()); break; case ISNOTEMPTY: criterion = Restrictions.isNotEmpty(query.getField()); break; case NOTEQUALS: criterion = Restrictions.ne(query.getField(), value); break; case IN: criterion = generateInRestriction(query.getField(), (Collection) value); break; case NOTIN: criterion = Restrictions.not(generateInRestriction(query.getField(), (Collection) value)); break; case FIELDEQUALS: criterion = Restrictions.eqProperty(query.getField(), value != null ? value.toString() : ""); break; case FIELDNOTEQUALS: criterion = Restrictions.neProperty(query.getField(), value != null ? value.toString() : ""); break; case FIELDGREATERTHAN: criterion = Restrictions.gtProperty(query.getField(), value != null ? value.toString() : ""); break; case FIELDLESSTHAN: criterion = Restrictions.ltProperty(query.getField(), value != null ? value.toString() : ""); break; default: throw new RuntimeException("Operation " + query.getField() + " is not a valid operation"); } return criterion; }
From source file:org.balisunrise.daa.hibernate.HCriteria.java
License:Open Source License
private org.hibernate.criterion.Criterion makeCriterion(Criterion.Comparator comparator) { String fp = aliasMap.getPropertyName(comparator.getFirstProperty()); String sp = aliasMap.getPropertyName(comparator.getSecondProperty()); switch (comparator.getComparatorType()) { case EQUALS:/* ww w.j a v a 2 s .com*/ return Restrictions.eqProperty(fp, sp); case DIFFERENT: return Restrictions.neProperty(fp, sp); case GREATHER: return Restrictions.gtProperty(fp, sp); case GREATHER_EQUALS: return Restrictions.geProperty(fp, sp); case LESS: return Restrictions.ltProperty(fp, sp); case LESS_EQUALS: return Restrictions.leProperty(fp, sp); } return null; }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
License:Apache License
protected void addPropertyComparisonCriterionAdapters() { criterionAdaptors.put(Query.EqualsProperty.class, new CriterionAdaptor<Query.EqualsProperty>() { @Override/*from w w w. ja va 2 s. c o m*/ public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.EqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.eqProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.GreaterThanProperty.class, new CriterionAdaptor<Query.GreaterThanProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.gtProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.GreaterThanEqualsProperty.class, new CriterionAdaptor<Query.GreaterThanEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.geProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.LessThanProperty.class, new CriterionAdaptor<Query.LessThanProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.ltProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.LessThanEqualsProperty.class, new CriterionAdaptor<Query.LessThanEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.leProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.NotEqualsProperty.class, new CriterionAdaptor<Query.NotEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.NotEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.neProperty(propertyName, criterion.getOtherProperty()); } }); }
From source file:org.esn.esobase.data.DBService.java
@Transactional public HierarchicalContainer getTextForSpellCheck(Date startDate, Date endDate, HierarchicalContainer hc) { hc.removeAllItems();// www . jav a 2 s . c o m List<Criterion> searchTermitems = new ArrayList<>(); if (startDate == null) { searchTermitems.add(Restrictions.and(Restrictions.neProperty("textEn", "textRu"), Restrictions.isNull("changeTime"))); } else { searchTermitems.add(Restrictions.and(Restrictions.neProperty("textEn", "textRu"), Restrictions.ge("changeTime", startDate), Restrictions.le("changeTime", endDate))); } Disjunction searchTerms = Restrictions.or(searchTermitems.toArray(new Criterion[searchTermitems.size()])); Session session = (Session) em.getDelegate(); Criteria itemDescriptionCrit = session.createCriteria(GSpreadSheetsItemDescription.class); itemDescriptionCrit.add(searchTerms); List<GSpreadSheetsItemDescription> itemDescriptionList = itemDescriptionCrit.list(); for (GSpreadSheetsItemDescription row : itemDescriptionList) { Item item = hc.addItem(row); item.getItemProperty("textEn").setValue(row.getTextEn()); item.getItemProperty("textRu").setValue(row.getTextRu()); item.getItemProperty("translator").setValue(row.getTranslator()); item.getItemProperty("catalogType").setValue("? "); } Criteria questNameCrit = session.createCriteria(GSpreadSheetsQuestName.class); questNameCrit.add(searchTerms); List<GSpreadSheetsQuestName> questNameList = questNameCrit.list(); for (GSpreadSheetsQuestName row : questNameList) { Item item = hc.addItem(row); item.getItemProperty("textEn").setValue(row.getTextEn()); item.getItemProperty("textRu").setValue(row.getTextRu()); item.getItemProperty("translator").setValue(row.getTranslator()); item.getItemProperty("catalogType").setValue("? ?"); } Criteria questDescriptionCrit = session.createCriteria(GSpreadSheetsQuestDescription.class); questDescriptionCrit.add(searchTerms); List<GSpreadSheetsQuestDescription> questDescriptionList = questDescriptionCrit.list(); for (GSpreadSheetsQuestDescription row : questDescriptionList) { Item item = hc.addItem(row); item.getItemProperty("textEn").setValue(row.getTextEn()); item.getItemProperty("textRu").setValue(row.getTextRu()); item.getItemProperty("translator").setValue(row.getTranslator()); item.getItemProperty("catalogType").setValue("? ?"); } Criteria questDirectionCrit = session.createCriteria(GSpreadSheetsQuestDirection.class); questDirectionCrit.add(searchTerms); List<GSpreadSheetsQuestDirection> questDirectionList = questDirectionCrit.list(); for (GSpreadSheetsQuestDirection row : questDirectionList) { Item item = hc.addItem(row); item.getItemProperty("textEn").setValue(row.getTextEn()); item.getItemProperty("textRu").setValue(row.getTextRu()); item.getItemProperty("translator").setValue(row.getTranslator()); item.getItemProperty("catalogType").setValue(" ?"); } Criteria journalEntryCrit = session.createCriteria(GSpreadSheetsJournalEntry.class); journalEntryCrit.add(searchTerms); List<GSpreadSheetsJournalEntry> journalEntryList = journalEntryCrit.list(); for (GSpreadSheetsJournalEntry row : journalEntryList) { Item item = hc.addItem(row); item.getItemProperty("textEn").setValue(row.getTextEn()); item.getItemProperty("textRu").setValue(row.getTextRu()); item.getItemProperty("translator").setValue(row.getTranslator()); item.getItemProperty("catalogType").setValue("? "); } Criteria npcPhraseCrit = session.createCriteria(GSpreadSheetsNpcPhrase.class); npcPhraseCrit.add(searchTerms); List<GSpreadSheetsNpcPhrase> npcPhraseList = npcPhraseCrit.list(); for (GSpreadSheetsNpcPhrase gSpreadSheetsNpcPhrase : npcPhraseList) { Item item = hc.addItem(gSpreadSheetsNpcPhrase); item.getItemProperty("textEn").setValue(gSpreadSheetsNpcPhrase.getTextEn()); item.getItemProperty("textRu").setValue(gSpreadSheetsNpcPhrase.getTextRu()); item.getItemProperty("translator").setValue(gSpreadSheetsNpcPhrase.getTranslator()); item.getItemProperty("catalogType").setValue(" NPC"); } Criteria playerPhraseCrit = session.createCriteria(GSpreadSheetsPlayerPhrase.class); playerPhraseCrit.add(searchTerms); List<GSpreadSheetsPlayerPhrase> playerPhraseList = playerPhraseCrit.list(); for (GSpreadSheetsPlayerPhrase gSpreadSheetsPlayerPhrase : playerPhraseList) { Item item = hc.addItem(gSpreadSheetsPlayerPhrase); item.getItemProperty("textEn").setValue(gSpreadSheetsPlayerPhrase.getTextEn()); item.getItemProperty("textRu").setValue(gSpreadSheetsPlayerPhrase.getTextRu()); item.getItemProperty("translator").setValue(gSpreadSheetsPlayerPhrase.getTranslator()); item.getItemProperty("catalogType").setValue(" "); } return hc; }
From source file:org.n52.sos.ds.hibernate.util.TemporalRestriction.java
License:Open Source License
/** * Creates a <tt>Criterion</tt> that checks that the persisted period is a * "real" period (<tt>begin != end</tt>). * // w w w . j a v a 2 s . c o m * @param r * the property names * * @return the <tt>Criterion</tt> */ protected PropertyExpression isPeriod(TimePrimitiveFieldDescriptor r) { return Restrictions.neProperty(r.getBeginPosition(), r.getEndPosition()); }
From source file:org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao.java
License:Open Source License
@Deprecated public List<FIN_Payment> getCustomerPaymentsWithCredit(BusinessPartner bp, boolean isReceipt) { OBCriteria<FIN_Payment> obcPayment = OBDal.getInstance().createCriteria(FIN_Payment.class); obcPayment.add(Restrictions.eq(FIN_Payment.PROPERTY_BUSINESSPARTNER, bp)); obcPayment.add(Restrictions.eq(FIN_Payment.PROPERTY_RECEIPT, isReceipt)); obcPayment.add(Restrictions.ne(FIN_Payment.PROPERTY_GENERATEDCREDIT, BigDecimal.ZERO)); obcPayment.add(Restrictions.ne(FIN_Payment.PROPERTY_STATUS, "RPAP")); obcPayment.add(Restrictions.ne(FIN_Payment.PROPERTY_STATUS, "RPVOID")); obcPayment.add(//from w w w . j a v a 2 s . c o m Restrictions.neProperty(FIN_Payment.PROPERTY_GENERATEDCREDIT, FIN_Payment.PROPERTY_USEDCREDIT)); obcPayment.addOrderBy(FIN_Payment.PROPERTY_PAYMENTDATE, true); obcPayment.addOrderBy(FIN_Payment.PROPERTY_DOCUMENTNO, true); return obcPayment.list(); }