Search in sources :

Example 1 with Junction

use of org.hibernate.criterion.Junction in project candlepin by candlepin.

the class PoolCurator method lookupOversubscribedBySubscriptionIds.

/**
 * Attempts to find pools which are over subscribed after the creation or
 * modification of the given entitlement. To do this we search for only the
 * pools related to the subscription ID which could have changed, the two
 * cases where this can happen are:
 * 1. Bonus pool (not derived from any entitlement) after a bind. (in cases
 * such as exporting to downstream)
 * 2. A derived pool whose source entitlement just had it's quantity
 * reduced.
 * This has to be done carefully to avoid potential performance problems
 * with virt_bonus on-site subscriptions where one pool is created per
 * physical entitlement.
 *
 * @param ownerId Owner - The owner of the entitlements being passed in. Scoping
 *        this to a single owner prevents performance problems in large datasets.
 * @param subIdMap Map where key is Subscription ID of the pool, and value
 *        is the Entitlement just created or modified.
 * @return Pools with too many entitlements for their new quantity.
 */
@SuppressWarnings("unchecked")
public List<Pool> lookupOversubscribedBySubscriptionIds(String ownerId, Map<String, Entitlement> subIdMap) {
    List<Criterion> subIdMapCriteria = new ArrayList<>();
    Criterion[] exampleCriteria = new Criterion[0];
    for (Entry<String, Entitlement> entry : subIdMap.entrySet()) {
        SimpleExpression subscriptionExpr = Restrictions.eq("sourceSub.subscriptionId", entry.getKey());
        Junction subscriptionJunction = Restrictions.and(subscriptionExpr).add(Restrictions.or(Restrictions.isNull("sourceEntitlement"), Restrictions.eqOrIsNull("sourceEntitlement", entry.getValue())));
        subIdMapCriteria.add(subscriptionJunction);
    }
    return currentSession().createCriteria(Pool.class).createAlias("sourceSubscription", "sourceSub").add(Restrictions.eq("owner.id", ownerId)).add(Restrictions.ge("quantity", 0L)).add(Restrictions.gtProperty("consumed", "quantity")).add(Restrictions.or(subIdMapCriteria.toArray(exampleCriteria))).list();
}
Also used : Criterion(org.hibernate.criterion.Criterion) ArrayList(java.util.ArrayList) Junction(org.hibernate.criterion.Junction) SimpleExpression(org.hibernate.criterion.SimpleExpression)

Example 2 with Junction

use of org.hibernate.criterion.Junction in project RecordManager2 by moravianlibrary.

the class ObalkyKnihTOCDAOHibernate method query.

@Override
@SuppressWarnings("unchecked")
public List<ObalkyKnihTOC> query(ObalkyKnihTOCQuery query) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(ObalkyKnihTOC.class);
    Junction oper = (query.getLogicalOperator() == LogicalOperator.AND) ? Restrictions.conjunction() : Restrictions.disjunction();
    crit.add(oper);
    if (query.getEans() != null && !query.getEans().isEmpty()) {
        oper.add(Restrictions.in("bibInfo.ean", query.getEans()));
    }
    if (query.getIsbns() != null && !query.getIsbns().isEmpty()) {
        oper.add(Restrictions.in("bibInfo.isbn", query.getIsbns()));
    }
    if (query.getOclcs() != null && !query.getOclcs().isEmpty()) {
        oper.add(Restrictions.in("bibInfo.oclc", query.getOclcs()));
    }
    if (query.getNbns() != null && !query.getNbns().isEmpty()) {
        oper.add(Restrictions.in("bibInfo.nbn", query.getNbns()));
    }
    return (List<ObalkyKnihTOC>) crit.list();
}
Also used : Junction(org.hibernate.criterion.Junction) List(java.util.List) Criteria(org.hibernate.Criteria)

Aggregations

Junction (org.hibernate.criterion.Junction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 Criterion (org.hibernate.criterion.Criterion)1 SimpleExpression (org.hibernate.criterion.SimpleExpression)1