Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java

License:Open Source License

private ExtensionData retrieveExtensionData(String name) throws WGAPIException {
    ExtensionData md = null;//from   w w  w .  ja  va 2 s .c  om
    Criteria c = getSession().createCriteria(ExtensionData.class);
    c.add(Restrictions.eq("name", name));
    c.add(Restrictions.isNull("entity"));
    List<ExtensionData> results = c.list();
    if (results.size() > 0) {
        md = results.get(0);
    }
    return md;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java

License:Open Source License

/**
 * Returns the {@link Criterion} for the specified {@code effectivePropertyName} and {@code comparator}.
 * /*from   ww w.  j a va2s .  c  om*/
 * @param effectivePropertyName the property name path
 * @param comparator the comparator describing the compare operation
 * @param attrType string representation of the property's attribute type as in {@link BBAttribute#getTypeOfAttribute(String)} 
 * @return the newly created {@link Criterion} for the specified {@code comparator} or {@code null} if the 
 *    comparator is not supported
 */
protected Criterion getCriterionForComparator(String effectivePropertyName, Comparator comparator,
        String attrType) {
    Criterion criterion = null;
    switch (comparator) {
    case EQ:
        criterion = Restrictions.eq(effectivePropertyName, getProcessedPattern());
        break;
    case GEQ:
        criterion = Restrictions.ge(effectivePropertyName, getProcessedPattern());
        break;
    case LEQ:
        criterion = Restrictions.le(effectivePropertyName, getProcessedPattern());
        break;
    case GT:
        criterion = Restrictions.gt(effectivePropertyName, getProcessedPattern());
        break;
    case LT:
        criterion = Restrictions.lt(effectivePropertyName, getProcessedPattern());
        break;
    case LIKE:
        criterion = new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true);
        break;
    case NOT_LIKE:
        criterion = Restrictions.not(
                new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true));
        break;
    case IS:
        // see Type#getSpecialPropertyHQLStrings
        criterion = "null".equals(getPattern()) ? Restrictions.isNull(effectivePropertyName)
                : Restrictions.isNotNull(effectivePropertyName);
        break;
    case ANY_ASSIGNMENT:
        criterion = getAnyAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NO_ASSIGNMENT:
        criterion = getNoAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NEQ:
        criterion = Restrictions.ne(effectivePropertyName, getProcessedPattern());
        break;
    default:
        break;
    }

    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java

License:Open Source License

private Criterion getAnyAssignmentCriterion(String effectivePropertyName, String attrType) {
    Criterion criterion;//  ww w. j  av  a  2 s  . c o m
    criterion = Restrictions.not(Restrictions.isNull(effectivePropertyName));
    if (!BBAttribute.FIXED_ATTRIBUTE_DATETYPE.equals(attrType)) {
        criterion = Restrictions.and(criterion,
                Restrictions.not(Restrictions.eq(effectivePropertyName, Constants.DB_NU1L)));
    }
    return criterion;
}

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));
    }//from w  w  w  .  j  a  va  2  s .  c o  m
    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.NotAssociatedLeafNode.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   w ww .j ava  2 s  .  co m*/
DetachedCriteria getWhereCriteria(DetachedCriteria criteria) {
    int lastIndex = getExtensionSize() - 1;
    if (indexOfLastAssociationType >= 0) {
        lastIndex = indexOfLastAssociationType;
    }

    if (getExtension().isIntermediaryTypeMultiEnd(lastIndex)) {
        final String intermediaryTypeNameDBShortWithSuffix = getIntermediaryTypeDBNameShortWithSuffix(
                lastIndex - 1);
        final String associationPath = String.format("%s.%s", intermediaryTypeNameDBShortWithSuffix,
                getExtension().getIntermediaryTypeJoinProperty(lastIndex));
        final String alias = String.format("%sAlias", getIntermediaryTypeDBNameShortWithSuffix(lastIndex));
        criteria.createAlias(associationPath, alias, Criteria.LEFT_JOIN);
        final String id = alias + ".id";
        criteria.add(Restrictions.isNull(id));
    } else {
        final String intermediaryTypeNameDBShortWithSuffix = getIntermediaryTypeDBNameShortWithSuffix(
                lastIndex - 1);
        final String joinProperty = getExtension().getIntermediaryTypeJoinProperty(lastIndex);
        final String associationPath = String.format("%s.%s", intermediaryTypeNameDBShortWithSuffix,
                joinProperty);
        criteria.add(Restrictions.isNull(associationPath));
    }

    return criteria;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.PropertyLeafNode.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  www  . ja  va  2  s  . c om
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.SealLeafNode.java

License:Open Source License

/** {@inheritDoc} */
@Override//  w ww . ja v a  2 s .  c  om
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 a  v a  2s  . co  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 ww  . j  ava2s.c om
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);
}

From source file:de.iteratec.iteraplan.persistence.dao.BusinessMappingDAOImpl.java

License:Open Source License

/** {@inheritDoc} */
public int deleteOrphanedBusinessMappings() {
    Criterion isrNull = Restrictions.isNull("informationSystemRelease.id");
    Criterion buNull = Restrictions.isNull("businessUnit.id");
    Criterion bpNull = Restrictions.isNull("businessProcess.id");
    Criterion prodNull = Restrictions.isNull("product.id");
    Junction invalidBusinessMappings = Restrictions.disjunction().add(isrNull).add(buNull).add(bpNull)
            .add(prodNull);/*from w w w  .j  a  v  a 2  s .c om*/

    List<BusinessMapping> orphanedMappings = getBusinessMappings(invalidBusinessMappings);
    for (BusinessMapping orphan : orphanedMappings) {
        delete(orphan);
    }

    return orphanedMappings.size();
}