List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
/** * Complete criteria with translations./* w ww . j av a2s .c om*/ * * @param currentCriteria * the current criteria * @param translationsPath * the translations path * @param translationsAlias * the translations alias * @param property * the property * @param propertyDescriptor * the property descriptor * @param prefixedProperty * the prefixed property * @param locale * the locale * @param componentDescriptor * the component descriptor * @param queryComponent * the query component * @param context * the context */ @SuppressWarnings("unchecked") protected void completeCriteriaWithTranslations(DetachedCriteria currentCriteria, String translationsPath, String translationsAlias, Map.Entry<String, Object> property, IPropertyDescriptor propertyDescriptor, String prefixedProperty, Locale locale, IComponentDescriptor<?> componentDescriptor, IQueryComponent queryComponent, Map<String, Object> context) { if (propertyDescriptor instanceof IStringPropertyDescriptor && ((IStringPropertyDescriptor) propertyDescriptor).isTranslatable()) { String nlsOrRawValue = null; String nlsValue = (String) property.getValue(); String barePropertyName = property.getKey(); if (property.getKey().endsWith(IComponentDescriptor.NLS_SUFFIX)) { barePropertyName = barePropertyName.substring(0, barePropertyName.length() - IComponentDescriptor.NLS_SUFFIX.length()); } else { nlsOrRawValue = nlsValue; } if (nlsValue != null) { Junction translationRestriction = Restrictions.conjunction(); translationRestriction.add(createStringRestriction( ((ICollectionPropertyDescriptor<IPropertyTranslation>) componentDescriptor .getPropertyDescriptor(translationsPath)).getCollectionDescriptor() .getElementDescriptor() .getPropertyDescriptor(IPropertyTranslation.TRANSLATED_VALUE), translationsAlias + "." + IPropertyTranslation.TRANSLATED_VALUE, nlsValue, componentDescriptor, queryComponent, context)); String languagePath = translationsAlias + "." + IPropertyTranslation.LANGUAGE; translationRestriction.add(Restrictions.eq(languagePath, locale.getLanguage())); translationRestriction.add(Restrictions .eq(translationsAlias + "." + IPropertyTranslation.PROPERTY_NAME, barePropertyName)); Junction disjunction = Restrictions.disjunction(); disjunction.add(translationRestriction); if (nlsOrRawValue != null) { Junction rawValueRestriction = Restrictions.conjunction(); rawValueRestriction.add(Restrictions.disjunction().add(Restrictions.isNull(languagePath)) .add(Restrictions.ne(languagePath, locale.getLanguage()))); String rawPropertyName = barePropertyName + IComponentDescriptor.RAW_SUFFIX; rawValueRestriction .add(createStringRestriction(componentDescriptor.getPropertyDescriptor(rawPropertyName), rawPropertyName, nlsOrRawValue, componentDescriptor, queryComponent, context)); disjunction.add(rawValueRestriction); } currentCriteria.add(disjunction); } } else { completeCriteria(currentCriteria, createStringRestriction(propertyDescriptor, prefixedProperty, (String) property.getValue(), componentDescriptor, queryComponent, context)); } }
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
/** * Complements a criteria by processing an enumeration query structure. * * @param path/*from w w w .ja v a 2 s . c o m*/ * the path to the comparable property. * @param enumQueryStructure * the collection of checked / unchecked enumeration values. * @return the created criterion or null if no criterion necessary. */ protected Criterion createEnumQueryStructureRestriction(String path, EnumQueryStructure enumQueryStructure) { Set<String> inListValues = new HashSet<>(); boolean nullAllowed = false; for (EnumValueQueryStructure inListValue : enumQueryStructure.getSelectedEnumerationValues()) { if (inListValue.getValue() == null || "".equals(inListValue.getValue())) { nullAllowed = true; } else { inListValues.add(inListValue.getValue()); } } Junction queryStructureRestriction = null; if (!inListValues.isEmpty()) { queryStructureRestriction = Restrictions.disjunction(); queryStructureRestriction.add(Restrictions.in(path, inListValues)); if (nullAllowed) { queryStructureRestriction.add(Restrictions.isNull(path)); } } return queryStructureRestriction; }
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
/** * Creates a string based restriction./* w w w . j a v a2 s . co m*/ * * @param propertyDescriptor * the property descriptor. * @param prefixedProperty * the full path of the property. * @param propertyValue * the string property value. * @param componentDescriptor * the component descriptor * @param queryComponent * the query component * @param context * the context * @return the created criterion or null if no criterion necessary. */ protected Criterion createStringRestriction(IPropertyDescriptor propertyDescriptor, String prefixedProperty, String propertyValue, IComponentDescriptor<?> componentDescriptor, IQueryComponent queryComponent, Map<String, Object> context) { Junction stringRestriction = null; if (propertyValue.length() > 0) { String[] propValues = propertyValue.split(IQueryComponent.DISJUNCT); stringRestriction = Restrictions.disjunction(); for (String propValue : propValues) { String val = propValue; if (val.length() > 0) { Criterion crit; boolean negate = false; if (val.startsWith(IQueryComponent.NOT_VAL)) { val = val.substring(1); negate = true; } if (IQueryComponent.NULL_VAL.equals(val)) { crit = Restrictions.isNull(prefixedProperty); } else { if (IEntity.ID.equals(propertyDescriptor.getName()) || propertyDescriptor instanceof IEnumerationPropertyDescriptor) { crit = Restrictions.eq(prefixedProperty, val); } else { crit = createLikeRestriction(propertyDescriptor, prefixedProperty, val, componentDescriptor, queryComponent, context); } } if (negate) { crit = Restrictions.not(crit); } stringRestriction.add(crit); } } } return stringRestriction; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.GridCQLToDetachedCriteria.java
License:Open Source License
private Criterion processGroup(Group group, String alias, DetachedCriteria criteria, String parentClass) throws TranslationException { LogicalOperator groupOperator = group.getLogicRelation(); String operator = groupOperator.getValue(); Junction op = null;//www. jav a2s . com if (operator.equals(LogicalOperator.AND.getValue())) { op = Restrictions.conjunction(); } if (operator.equals(LogicalOperator.OR.getValue())) { op = Restrictions.disjunction(); } //Process the Attributes Attribute[] atts = group.getAttribute(); if (atts != null) { for (Attribute at : atts) { op.add(processAttribute(at, alias)); } } //Process the Associations Association[] assocs = group.getAssociation(); if (assocs != null) { for (Association assoc : assocs) { op.add(processAssociation(assoc, alias, criteria, parentClass)); } } //Process Nested Groups Group[] groups = group.getGroup(); if (groups != null) { for (Group nestedGroup : groups) { op.add(processGroup(nestedGroup, alias, criteria, parentClass)); } } return op; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.NestedObjectToCriteria.java
License:Open Source License
public DetachedCriteria translate(Class searchClass, List searchObjectList, String eagerFetchAssociation) throws TranslationException { DetachedCriteria crit = DetachedCriteria.forClass(searchClass); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (eagerFetchAssociation != null) { crit.setFetchMode(eagerFetchAssociation, FetchMode.JOIN); }/* ww w . j a v a 2 s . c om*/ //Apply the List of Associated Objects (OR'ed) Disjunction disjunction = Restrictions.disjunction(); for (Object searchObject : searchObjectList) { Criterion criterion = translator.buildCriterionFromNestedObjects(searchObject, crit); disjunction.add(criterion); } crit.add(disjunction); return crit; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.QBEPathToDetachedCriteria.java
License:Open Source License
public DetachedCriteria translate(String path, List searchObjectList) throws TranslationException { List<String> pathList = new ArrayList<String>(); StringTokenizer tokens = new StringTokenizer(path, ","); while (tokens.hasMoreTokens()) { pathList.add(tokens.nextToken().trim()); }//w w w . j a va2 s .c om String rootClass = pathList.remove(0); DetachedCriteria dCrit = DetachedCriteria.forEntityName(rootClass); dCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); //Set the Association Path String alias = dCrit.getAlias(); for (String pathElement : pathList) { String roleName = LexEVSTranslatorsUtil.getRoleName(rootClass, pathElement); dCrit.createAlias(alias + "." + roleName, roleName); rootClass = pathElement; alias = roleName; } //Apply the List of Associated Objects (OR'ed) Disjunction disjunction = Restrictions.disjunction(); for (Object searchObject : searchObjectList) { Criterion crit = translator.buildCriterionFromNestedObjects(searchObject, alias, dCrit); disjunction.add(crit); } dCrit.add(disjunction); return dCrit; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.SDKCQLToDetachedCriteria.java
License:Open Source License
private Criterion processGroup(CQLGroup group, String alias, DetachedCriteria criteria, String parentClass) throws TranslationException { CQLLogicalOperator groupOperator = group.getLogicOperator(); String operator = groupOperator.getValue(); Junction op = null;/*from w ww .ja va2s . c om*/ if (operator.equals(CQLLogicalOperator.AND.getValue())) { op = Restrictions.conjunction(); } if (operator.equals(CQLLogicalOperator.OR.getValue())) { op = Restrictions.disjunction(); } //Process the Attributes Collection<CQLAttribute> atts = group.getAttributeCollection(); if (atts != null) { for (CQLAttribute at : atts) { op.add(processAttribute(at, alias)); } } //Process the Associations Collection<CQLAssociation> assocs = group.getAssociationCollection(); if (assocs != null) { for (CQLAssociation assoc : assocs) { op.add(processAssociation(assoc, alias, criteria, parentClass)); } } //Process Nested Groups Collection<CQLGroup> groups = group.getGroupCollection(); if (groups != null) { for (CQLGroup nestedGroup : groups) { op.add(processGroup(nestedGroup, alias, criteria, parentClass)); } } return op; }
From source file:org.linagora.linshare.core.repository.hibernate.AbstractDomainRepositoryImpl.java
License:Open Source License
@Override public List<AbstractDomain> findAllTopAndSubDomain() { return findByCriteria(Restrictions.disjunction().add(Restrictions.eq("class", TopDomain.class)) .add(Restrictions.eq("class", SubDomain.class))); }
From source file:org.linagora.linshare.core.repository.hibernate.LogEntryRepositoryImpl.java
License:Open Source License
public List<LogEntry> findByCriteria(LogCriteriaBean logCriteria, String domainId) { DetachedCriteria criteria = DetachedCriteria.forClass(LogEntry.class); if (CollectionUtils.isNotEmpty(logCriteria.getActorMails())) { Disjunction or = Restrictions.disjunction(); for (String mail : logCriteria.getActorMails()) { if (StringUtils.isNotBlank(mail)) or.add(Restrictions.like("actorMail", mail, MatchMode.ANYWHERE)); }//from ww w .j a v a 2 s . c o m criteria.add(or); } if (CollectionUtils.isNotEmpty(logCriteria.getTargetMails())) { Disjunction or = Restrictions.disjunction(); for (String mail : logCriteria.getTargetMails()) { if (StringUtils.isNotBlank(mail)) or.add(Restrictions.like("targetMail", mail, MatchMode.ANYWHERE)); } criteria.add(or); } if (StringUtils.isNotBlank(logCriteria.getActorFirstname())) { criteria.add(Restrictions.like("actorFirstname", logCriteria.getActorFirstname(), MatchMode.ANYWHERE) .ignoreCase()); } if (StringUtils.isNotBlank(logCriteria.getActorLastname()) && (logCriteria.getActorLastname().length() > 0)) { criteria.add(Restrictions.like("actorLastname", logCriteria.getActorLastname(), MatchMode.ANYWHERE) .ignoreCase()); } if (StringUtils.isNotBlank(domainId)) { criteria.add(Restrictions.like("actorDomain", domainId)); } else if (StringUtils.isNotBlank(logCriteria.getActorDomain())) { criteria.add(Restrictions.like("actorDomain", logCriteria.getActorDomain())); } if (StringUtils.isNotBlank(logCriteria.getTargetFirstname())) { criteria.add(Restrictions.like("targetFirstname", logCriteria.getTargetFirstname(), MatchMode.ANYWHERE) .ignoreCase()); } if (StringUtils.isNotBlank(logCriteria.getTargetLastname())) { criteria.add(Restrictions.like("targetLastname", logCriteria.getTargetLastname(), MatchMode.ANYWHERE) .ignoreCase()); } if (StringUtils.isNotBlank(logCriteria.getTargetDomain())) { criteria.add(Restrictions.like("targetDomain", logCriteria.getTargetDomain())); } if (CollectionUtils.isNotEmpty(logCriteria.getLogActions())) { criteria.add(Restrictions.in("logAction", logCriteria.getLogActions())); } if (logCriteria.getBeforeDate() != null) { criteria.add(Restrictions.gt("actionDate", logCriteria.getBeforeDate())); } if (logCriteria.getAfterDate() != null) { criteria.add(Restrictions.lt("actionDate", logCriteria.getAfterDate())); } if (StringUtils.isNotBlank(logCriteria.getFileName())) { if (logCriteria.getFileNameMatchMode().equals(CriterionMatchMode.ANYWHERE)) { criteria.add( Restrictions.like("fileName", logCriteria.getFileName(), MatchMode.ANYWHERE).ignoreCase()); } else { criteria.add( Restrictions.like("fileName", logCriteria.getFileName(), MatchMode.ANYWHERE).ignoreCase()); } } if (StringUtils.isNotBlank(logCriteria.getFileExtension())) { criteria.add(Restrictions.like("fileName", logCriteria.getFileExtension(), MatchMode.END).ignoreCase()); } criteria.addOrder(Order.desc("actionDate")); return findBy(criteria); }
From source file:org.linagora.linshare.core.repository.hibernate.MailConfigRepositoryImpl.java
License:Open Source License
@Override public boolean isMailLayoutReferenced(MailLayout layout) { return !findByCriteria(Restrictions.disjunction().add(Restrictions.eq("mailLayoutHtml", layout)) .add(Restrictions.eq("mailLayoutText", layout))).isEmpty(); }