Example usage for org.hibernate.criterion Restrictions conjunction

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

Introduction

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

Prototype

public static Conjunction conjunction() 

Source Link

Document

Group expressions together in a single conjunction (A and B and C...).

Usage

From source file:com.qcadoo.model.internal.search.SearchConjunctionImpl.java

License:Open Source License

public SearchConjunctionImpl() {
    conjunction = Restrictions.conjunction();
}

From source file:com.thesett.catalogue.impl.standalone.CatalogueManagerServiceImpl.java

License:Apache License

/** {@inheritDoc} */
public List<HierarchyInstance> retreiveHierarchyInstances(HierarchyInstance hierarchy, boolean queryChildren) {
    List<HierarchyInstance> result = new LinkedList<HierarchyInstance>();

    // Get name of hierarchy type to query.
    String hierarchyTypeName = hierarchy.getHierarchyType().getName();

    // Work out the database table name for the hierarchy.
    String databaseEntityName = getCatalogue().getModelPackage() + "."
            + StringUtils.toCamelCaseUpper(hierarchyTypeName);

    Session session = HibernateUtil.getCurrentSession();
    HibernateUtil.beginTransaction();//from  ww  w .java2s .  c o m

    Criteria selectCriteria = session.createCriteria(databaseEntityName);

    // Build up the query criteria.
    Conjunction subCriterion = Restrictions.conjunction();

    // Get the level names in the hierarchy.
    HierarchyAttribute hierarchyAttribute = hierarchy.getHierarchy();
    HierarchyAttributeFactory factory = hierarchyAttribute.getFactory();
    String[] levelNames = factory.getLevelNames();

    // Build up the property matching clause for this restriction. Levels defined in the restricting
    // hierarchy must be matched exactly on the joined hierarchy property.
    for (String level : levelNames) {
        String value = hierarchyAttribute.getValueAtLevel(level);

        // Only add restrictions for non null values specified in the grouping hierarchy.
        if (value != null) {
            subCriterion.add(Restrictions.eq(StringUtils.toCamelCase(hierarchyTypeName) + "." + level, value));
        }
    }

    selectCriteria.add(subCriterion);

    return selectCriteria.list();
}

From source file:com.thesett.catalogue.impl.standalone.CatalogueManagerServiceImpl.java

License:Apache License

/**
 * Build a map of entity field names and criterion to apply to them in order to select entities by the specified
 * attributes.//from  ww  w  .  j  a  va 2 s  .co m
 *
 * @param  matchings The attributes to match.
 *
 * @return A map of entity field names and criterion to apply to them.
 */
protected Map<String, Criterion> getByAttributeCriterions(Map<String, Attribute> matchings) {
    Map<String, Criterion> criterions = new HashMap<String, Criterion>();

    // Loop over all the attribute matchings to create criterions for.
    for (String propName : matchings.keySet()) {
        // Get the attribute type name of the parameter to match against.
        Attribute attribute = matchings.get(propName);
        String attributeTypeName = attribute.getType().getName();

        if (attribute instanceof HierarchyAttribute) {
            // Create join criterions for selecting entities by hierarchies.
            // One join criterion, plus entity name, will be created for each property to be restricted by hierarchy.
            HierarchyAttribute hierarchyAttribute = (HierarchyAttribute) attribute;
            HierarchyAttributeFactory factory = hierarchyAttribute.getFactory();

            // Get the next property to restrict by attribute value and create a criterion to restrict on that property.
            Conjunction subCriterion = Restrictions.conjunction();
            criterions.put(propName, subCriterion);

            // Get the level names in the hierarchy.
            String[] levelNames = factory.getLevelNames();

            // Build up the property matching clause for this restriction. Levels defined in the restricting
            // hierarchy must be matched exactly on the joined hierarchy property.
            for (String level : levelNames) {
                String value = hierarchyAttribute.getValueAtLevel(level);

                // Only add restrictions for non null values specified in the grouping hierarchy.
                if (value != null) {
                    subCriterion.add(Restrictions.eq(attributeTypeName + "." + level, value));
                }
            }
        }
    }

    return criterions;
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.InactivityNotificationDAOImpl.java

License:Open Source License

private Criterion getRegularMemberInactivityCriterion() {
    Conjunction c = Restrictions.conjunction();

    c.add(Restrictions.eq("retired", false));
    c.add(Restrictions.eq("vacation", false));
    c.add(Restrictions.in("rank", MemberUtil.getNonTrialRanks()));
    c.add(Restrictions.le("lastAction", DateUtil.daysAgo(12)));

    return c;//from  ww w.  java2 s.  co  m
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.InactivityNotificationDAOImpl.java

License:Open Source License

private Criterion getRetiredMemberInactivityCriterion() {
    Conjunction c = Restrictions.conjunction();

    c.add(Restrictions.eq("retired", true));
    c.add(Restrictions.in("rank", MemberUtil.getNonTrialRanks()));
    c.add(Restrictions.le("lastAction", DateUtil.monthsAgo(11)));

    return c;/*from w w  w . j ava  2s  .c o m*/
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.InactivityNotificationDAOImpl.java

License:Open Source License

private Criterion getVacationMemberInactivityCriterion() {
    Conjunction c = Restrictions.conjunction();

    c.add(Restrictions.eq("retired", false));
    c.add(Restrictions.eq("vacation", true));
    c.add(Restrictions.in("rank", MemberUtil.getNonTrialRanks()));
    c.add(Restrictions.le("lastAction", DateUtil.daysAgo(55)));

    return c;/*  ww w . j  a va  2s.c o m*/
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.InactivityNotificationDAOImpl.java

License:Open Source License

private Criterion getTrialMemberInactivityCriterion() {
    Conjunction c = Restrictions.conjunction();

    c.add(Restrictions.eq("rank", Rank.TRIAL));
    c.add(Restrictions.le("lastAction", DateUtil.daysAgo(5)));

    return c;/* ww w  . j av a2s  .c  om*/
}

From source file:com.webbfontaine.valuewebb.action.pricedb.mp.MPCriteriaContainer.java

License:Open Source License

@Override
public Criteria transformUserCriteria(Session session) throws Exception {

    Criteria criteria = session.createCriteria(MarketPrice.class)
            .add(Example.create(new MarketPrice()).excludeZeroes());
    criteria.createCriteria("sourceOfPrice", "sourceOfPrice");

    Junction junction = getMatchAll() ? Restrictions.conjunction() : Restrictions.disjunction();

    List<UserCriterion> selectedUserCriteria = getSelectedUserCriteria();
    for (UserCriterion userCriterion : selectedUserCriteria) {

        Criterion transformedCriterion;/*from   w w w  . j  av  a  2 s  .  c  o  m*/
        if ("ageOfPrice".equals(userCriterion.getFullKey())) {
            transformedCriterion = transformAgeOfPriceToPriceDate(userCriterion,
                    getDefinedCriterion("priceDate"));
        } else {
            transformedCriterion = userCriterion.transform();
        }

        if (transformedCriterion != null) {
            criteria.add(junction.add(transformedCriterion));
        }
    }

    return criteria;
}

From source file:com.webbfontaine.valuewebb.action.pricedb.pdss.PdssCriteriaContainer.java

License:Open Source License

@Override
public Criteria transformUserCriteria(Session session) throws Exception {
    if (fakeToRealPropertyMap == null || entityClass == null) {
        throw new RuntimeException("Target bean/properties were not initialized");
    }/*w w w. j  a v  a  2 s.  com*/

    Criteria criteria = session.createCriteria(entityClass)
            .add(Example.create(entityClass.newInstance()).excludeZeroes());
    List<String> aliases = new ArrayList<>();

    Junction junction = getMatchAll() ? Restrictions.conjunction() : Restrictions.disjunction();

    List<UserCriterion> selectedUserCriteria = getSelectedUserCriteria();
    for (UserCriterion fakeCriterion : selectedUserCriteria) {

        if (beanHasCriterionProperty(fakeCriterion.getFullKey())) {
            UserCriterion realCriterion = prepareUCForBean(fakeCriterion);

            String alias = extractAlias(realCriterion.getFullKey());
            if (alias != null) {
                if (!aliases.contains(alias)) {
                    aliases.add(alias);
                    criteria.createCriteria(alias, alias);
                }
            }

            Criterion transformedCriterion;

            if ("ageOfPrice".equals(fakeCriterion.getFullKey())) {
                transformedCriterion = transformAgeOfPriceToPriceDate(fakeCriterion, realCriterion);
            } else {
                transformedCriterion = realCriterion.transform();
            }

            criteria.add(junction.add(transformedCriterion));
        }
    }

    return criteria;
}

From source file:com.webbfontaine.valuewebb.action.pricedb.prd.PRDCriteriaContainer.java

License:Open Source License

@Override
public Criteria transformUserCriteria(Session session) throws Exception {

    Criteria criteria = session.createCriteria(Pd.class).add(Example.create(new Pd()).excludeZeroes());
    criteria.createCriteria("ttGen", "ttGen");
    criteria.createCriteria("ttInv", "ttInv");

    Junction junction = getMatchAll() ? Restrictions.conjunction() : Restrictions.disjunction();

    List<UserCriterion> selectedUserCriteria = getSelectedUserCriteria();
    for (UserCriterion userCriterion : selectedUserCriteria) {

        Criterion transformedCriterion;/*from w  w  w . ja va  2s  .  c  o  m*/
        if ("ageOfPrice".equals(userCriterion.getFullKey())) {
            transformedCriterion = MPCriteriaContainer.transformAgeOfPriceToPriceDate(userCriterion,
                    getDefinedCriterion("ttInv.invDat"));
        } else {
            transformedCriterion = userCriterion.transform();
        }

        if (transformedCriterion != null) {
            criteria.add(junction.add(transformedCriterion));
        }
    }

    return criteria;
}