List of usage examples for org.hibernate.criterion Restrictions or
public static LogicalExpression or(Criterion lhs, Criterion rhs)
From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserAccountDao.java
License:Open Source License
/** * get an in-restriction. Eventually concatenated with an isNull-restriction if criteria-set contains a null-value. * * @param criteria criteria to put in in-restriction * @param fieldName field-name for in-restriction * @return Criterion// w w w .j a v a2s . c o m */ private static Criterion getInRestrictions(final Collection<String> criteria, final String fieldName) { if (criteria.contains("")) { criteria.remove(""); return criteria.isEmpty() ? Restrictions.isNull(fieldName) : Restrictions.or(Restrictions.isNull(fieldName), Restrictions.in(fieldName, criteria.toArray())); } else { return Restrictions.in(fieldName, criteria.toArray()); } }
From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserGroupDao.java
License:Open Source License
/** * See Interface for functional description. * * @param identityInfo identityInfo/*from w w w . ja v a 2 s . c om*/ * @return boolean * @throws SqlDatabaseSystemException e * @see UserGroupDaoInterface #userGroupExists(java.lang.String) */ @Override public boolean userGroupExists(final String identityInfo) throws SqlDatabaseSystemException { boolean result = false; if (identityInfo != null) { try { // try identification by id or label final DetachedCriteria criteria = DetachedCriteria.forClass(UserGroup.class).add(Restrictions .or(Restrictions.eq("id", identityInfo), Restrictions.eq("label", identityInfo))); result = !getHibernateTemplate().findByCriteria(criteria).isEmpty(); } catch (final DataAccessException e) { throw new SqlDatabaseSystemException(e); } catch (final IllegalStateException e) { throw new SqlDatabaseSystemException(e); } catch (final HibernateException e) { //noinspection ThrowableResultOfMethodCallIgnored throw new SqlDatabaseSystemException(convertHibernateAccessException(e)); // Ignore FindBugs } } return result; }
From source file:de.escidoc.core.common.business.filter.CqlFilter.java
License:Open Source License
/** * Evaluate a CQL boolean node.//from www .ja v a2s. c o m * * @param node * CQL node * @return Hibernate query reflecting the given CQL query * @throws InvalidSearchQueryException * thrown if the given search query could not be translated into a SQL query */ protected Criterion evaluate(final CQLBooleanNode node) throws InvalidSearchQueryException { Criterion result = null; final Criterion left = evaluate(node.left); final Criterion right = evaluate(node.right); if (node instanceof CQLAndNode) { if (left != null || right != null) { result = Restrictions.and(getAndRestriction(left), getAndRestriction(right)); } } else if (node instanceof CQLOrNode) { if (left != null || right != null) { result = Restrictions.or(getOrRestriction(left), getOrRestriction(right)); } } else { throw new InvalidSearchQueryException(node + ": node type not implemented"); } return result; }
From source file:de.escidoc.core.common.business.filter.CqlFilter.java
License:Open Source License
/** * get an in-restriction. Eventually concatenated with an isNull-restriction if criteria-set contains a null-value. * /*w ww . j a v a 2 s . com*/ * @param criteria * criteria to put in in-restriction * @param fieldName * field-name for in-restriction * @return Criterion */ protected Criterion getInRestrictions(final Collection<String> criteria, final String fieldName) { if (criteria.contains("")) { criteria.remove(""); return criteria.isEmpty() ? Restrictions.isNull(fieldName) : Restrictions.or(Restrictions.isNull(fieldName), Restrictions.in(fieldName, criteria.toArray())); } else { return Restrictions.in(fieldName, criteria.toArray()); } }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java
License:Open Source License
private Criterion getNoAssignmentCriterion(String effectivePropertyName, String attrType) { Criterion criterion = Restrictions.isNull(effectivePropertyName); if (!BBAttribute.FIXED_ATTRIBUTE_DATETYPE.equals(attrType)) { criterion = Restrictions.or(criterion, Restrictions.eq(effectivePropertyName, Constants.DB_NU1L)); }/* ww w . j a v a 2 s.com*/ return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.PropertyLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w . j a v a 2 s . com*/ DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { String effectivePropertyName = null; if (getExtensionSize() == 0) { effectivePropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), getPropertyName()); } else { effectivePropertyName = String.format("%s.%s", getLeafTypeDBNameShortWithSuffix(), getPropertyName()); } final String[] properties = StringUtils.split(getPropertyName(), '.'); if (!getResultType().isSpecialProperty(getPropertyName()) && properties != null && properties.length > 1) { final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), properties[0]); final String alias = String.format("%sAlias", properties[0]); criteria.createAlias(associationPath, alias); effectivePropertyName = String.format("%s.%s", alias, properties[1]); } if ("runtimePeriod.start".equals(getPropertyName()) || "runtimePeriod.end".equals(getPropertyName())) { criteria.add(Restrictions.or( getCriterionForComparator(effectivePropertyName, getComparator(), attributeType), Restrictions.isNull(effectivePropertyName))); } else if ("technicalComponent.availableForInterfaces".equals(getPropertyName())) { if (Comparator.LIKE.equals(getComparator())) { criteria.add(getCriterionForComparator(effectivePropertyName, Comparator.EQ, attributeType)); } else if (Comparator.NOT_LIKE.equals(getComparator())) { criteria.add(getCriterionForComparator(effectivePropertyName, Comparator.NEQ, attributeType)); } } else { criteria.add(getCriterionForComparator(effectivePropertyName, getComparator(), attributeType)); } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.ResponsibilityAttributeLeafNode.java
License:Open Source License
private Criterion createUserCriterion() { final DetachedCriteria user = DetachedCriteria.forClass(User.class, "user"); user.add(new IteraplanLikeExpression("user.loginName", (String) getProcessedPattern(), true)); user.setProjection(Property.forName("user.id")); final DetachedCriteria userGroup = DetachedCriteria.forClass(UserGroup.class, "userGroup"); userGroup.add(new IteraplanLikeExpression("userGroup.name", (String) getProcessedPattern(), true)); userGroup.setProjection(Property.forName("userGroup.id")); return Restrictions.or(Subqueries.propertyIn("userEntity", user), Subqueries.propertyIn("userEntity", userGroup)); }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/* w w w . j a v a 2s.c o m*/ DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { String effectivePropertyName = null; if (getExtensionSize() == 0) { effectivePropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), getPropertyName()); } else { effectivePropertyName = String.format("%s.%s", getLeafTypeDBNameShortWithSuffix(), getPropertyName()); } final String[] properties = StringUtils.split(getPropertyName(), '.'); if (!getResultType().isSpecialProperty(getPropertyName()) && properties != null && properties.length > 1) { final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), properties[0]); final String alias = String.format("%sAlias", properties[0]); criteria.createAlias(associationPath, alias); effectivePropertyName = String.format("%s.%s", alias, properties[1]); } SealState sealState = (SealState) getPattern(); switch (sealState) { case VALID: Criterion validCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null); Criterion notOutdatedCriterion = Restrictions.not(getOutdatedCriterion(effectivePropertyName)); criteria.add(Restrictions.and(validCriterion, notOutdatedCriterion)); break; case INVALID: criteria.add(getCriterionForComparator(effectivePropertyName, Comparator.EQ, null)); break; case NOT_AVAILABLE: Criterion isNull = Restrictions.isNull(effectivePropertyName); Criterion eqCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null); criteria.add(Restrictions.or(isNull, eqCriterion)); break; case OUTDATED: criteria.add(getOutdatedCriterion(effectivePropertyName)); break; default: throw new IllegalStateException("The seal state " + sealState + " is not supported!"); } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.service.InformationSystemReleaseServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w. j av a 2s. c o m public List<InformationSystemRelease> findByNames(Set<String> names) { if (names.isEmpty()) { return Collections.emptyList(); } DetachedCriteria criteria = DetachedCriteria.forClass(InformationSystemRelease.class); criteria.createAlias("informationSystem", "informationSystem"); Disjunction disjunction = Restrictions.disjunction(); for (String name : names) { String[] partsOfReleaseName = GeneralHelper.getPartsOfReleaseName(name); //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression nameExpression = Restrictions.like("informationSystem.name", partsOfReleaseName[0], MatchMode.EXACT).ignoreCase(); Criterion nameExpression = new IteraplanLikeExpression("informationSystem.name", partsOfReleaseName[0], true); String version = "version"; if (partsOfReleaseName[1] != null) { //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression versionExpression = Restrictions.like(version, partsOfReleaseName[1], MatchMode.EXACT).ignoreCase(); Criterion versionExpression = new IteraplanLikeExpression(version, partsOfReleaseName[1], true); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } else { Criterion versionExpression = Restrictions.or(Restrictions.isNull(version), Restrictions.eq(version, Constants.DB_NU1L)); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } } criteria.add(disjunction); return informationSystemReleaseDAO.findByCriteria(criteria); }
From source file:de.iteratec.iteraplan.businesslogic.service.TechnicalComponentReleaseServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w. j a va2 s .co m public List<TechnicalComponentRelease> findByNames(Set<String> names) { if (names.isEmpty()) { return Collections.emptyList(); } DetachedCriteria criteria = DetachedCriteria.forClass(TechnicalComponentRelease.class); criteria.createAlias("technicalComponent", "technicalComponent"); Disjunction disjunction = Restrictions.disjunction(); for (String name : names) { String[] partsOfReleaseName = GeneralHelper.getPartsOfReleaseName(name); //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression nameExpression = Restrictions.like("technicalComponent.name", partsOfReleaseName[0], MatchMode.EXACT).ignoreCase(); Criterion nameExpression = new IteraplanLikeExpression("technicalComponent.name", partsOfReleaseName[0], true); if (partsOfReleaseName[1] != null) { //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression versionExpression = Restrictions.like(VERSION, partsOfReleaseName[1], MatchMode.EXACT).ignoreCase(); Criterion versionExpression = new IteraplanLikeExpression(VERSION, partsOfReleaseName[1], true); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } else { Criterion versionExpression = Restrictions.or(Restrictions.isNull(VERSION), Restrictions.eq(VERSION, Constants.DB_NU1L)); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } } criteria.add(disjunction); return technicalComponentReleaseDAO.findByCriteria(criteria); }