Example usage for org.hibernate.criterion CriteriaSpecification LEFT_JOIN

List of usage examples for org.hibernate.criterion CriteriaSpecification LEFT_JOIN

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaSpecification LEFT_JOIN.

Prototype

int LEFT_JOIN

To view the source code for org.hibernate.criterion CriteriaSpecification LEFT_JOIN.

Click Source Link

Document

Specifies joining to an entity based on a left outer join.

Usage

From source file:org.candlepin.model.EntitlementCurator.java

License:Open Source License

@Transactional
public Page<List<Entitlement>> listByConsumerAndProduct(Consumer consumer, String productId,
        PageRequest pageRequest) {//  w  w w . j a  v  a2 s.  c om
    Criteria query = createSecureCriteria().add(Restrictions.eq("consumer", consumer)).createAlias("pool", "p")
            .createAlias("p.providedProducts", "pp", CriteriaSpecification.LEFT_JOIN)
            // Never show a consumer expired entitlements
            .add(Restrictions.ge("p.endDate", new Date())).add(Restrictions
                    .or(Restrictions.eq("p.productId", productId), Restrictions.eq("pp.productId", productId)));

    Page<List<Entitlement>> page = listByCriteria(query, pageRequest);

    return page;
}

From source file:org.candlepin.model.PoolCurator.java

License:Open Source License

/**
 * List entitlement pools./* ww  w .  j  ava  2  s.  c  o m*/
 *
 * Pools will be refreshed from the underlying subscription service.
 *
 * @param c Consumer being entitled.
 * @param o Owner whose subscriptions should be inspected.
 * @param productId only entitlements which provide this product are included.
 * @param activeOn Indicates to return only pools valid on this date.
 *        Set to null for no date filtering.
 * @param activeOnly if true, only active entitlements are included.
 * @param filters filter builder with set filters to apply to the criteria.
 * @param pageRequest used to specify paging criteria.
 * @param postFilter if you plan on filtering the list in java
 * @return List of entitlement pools.
 */
@SuppressWarnings("unchecked")
@Transactional
public Page<List<Pool>> listAvailableEntitlementPools(Consumer c, Owner o, String productId, Date activeOn,
        boolean activeOnly, PoolFilterBuilder filters, PageRequest pageRequest, boolean postFilter) {
    if (o == null && c != null) {
        o = c.getOwner();
    }

    if (log.isDebugEnabled()) {
        log.debug("Listing available pools for:");
        log.debug("   consumer: " + c);
        log.debug("   owner: " + o);
        log.debug("   product: " + productId);
    }

    Criteria crit = createSecureCriteria();
    if (activeOnly) {
        crit.add(Restrictions.eq("activeSubscription", Boolean.TRUE));
    }
    if (c != null) {
        crit.add(Restrictions.eq("owner", c.getOwner()));

        // Ask the rules for any business logic criteria to filter with for
        // this consumer
        List<Criterion> filterCriteria = poolCriteria.availableEntitlementCriteria(c);

        if (log.isDebugEnabled()) {
            log.debug("Got " + filterCriteria.size() + "  query filters from database.");
        }

        for (Criterion rulesCriteria : filterCriteria) {
            crit.add(rulesCriteria);
        }
    }
    if (o != null) {
        crit.add(Restrictions.eq("owner", o));
        crit.add(Restrictions.ne("productName", Product.ueberProductNameForOwner(o)));
    }
    if (activeOn != null) {
        crit.add(Restrictions.le("startDate", activeOn));
        crit.add(Restrictions.ge("endDate", activeOn));
    }

    if (productId != null) {
        crit.createAlias("providedProducts", "providedProduct", CriteriaSpecification.LEFT_JOIN);

        crit.add(Restrictions.or(Restrictions.eq("productId", productId),
                Restrictions.eq("providedProduct.productId", productId)));
    }

    // Append any specified filters
    if (filters != null) {
        filters.applyTo(crit);
    }

    return listByCriteria(crit, pageRequest, postFilter);
}

From source file:org.candlepin.model.SubscriptionCurator.java

License:Open Source License

/**
 * Return a list of subscriptions for the given product.
 *
 * We do essentially 2 queries here, so there is room for optimization
 * both in speed and memory usage./* w w  w .  j  av  a2 s.c om*/
 *
 * @param product product to search for.
 * @return a list of subscriptions
 */
@SuppressWarnings("unchecked")
public List<Subscription> listByProduct(Product product) {

    Criteria subscriptionCriteria = currentSession().createCriteria(Subscription.class)
            .createAlias("providedProducts", "providedProduct", CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.or(Restrictions.eq("product", product),
                    Restrictions.eq("providedProduct.id", product.getId())));

    List<Subscription> subs = subscriptionCriteria.list();
    if (subs == null) {
        return new LinkedList<Subscription>();
    }
    return subs;
}

From source file:org.egov.council.service.CouncilPreambleService.java

License:Open Source License

@SuppressWarnings({ "unchecked", "deprecation" })
public List<CouncilPreamble> searchFinalizedPreamble(CouncilPreamble councilPreamble) {
    final Criteria criteria = buildSearchCriteria(councilPreamble);
    criteria.createAlias("councilPreamble.implementationStatus", "implementationStatus",
            CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.or(Restrictions.isNull("implementationStatus.code"),
                    Restrictions.ne("implementationStatus.code", IMPLEMENTATION_STATUS_FINISHED)))
            .add(Restrictions.and(Restrictions.in(STATUS_CODE, RESOLUTION_APPROVED_PREAMBLE)));
    return criteria.list();
}

From source file:org.egov.demand.dao.DemandGenericHibDao.java

License:Open Source License

/**
 * Method called to get all the Bill Receipt Objects which exists for the
 * Demands . Bill Receipts are one to one with EgBill.So Bill needs to be
 * existed.//from w  w  w.ja va2s  .  com
 * 
 * @return java.util.List<EgDemand>
 * 
 */

@Override
public List<BillReceipt> getBillReceipts(List<EgDemand> egDemand) {
    List<BillReceipt> billReceipts = new ArrayList<BillReceipt>();
    Query qry = null;
    if (egDemand != null && !egDemand.isEmpty()) {
        Criteria criteria = getCurrentSession().createCriteria(BillReceipt.class, "billRct")
                .createAlias("billRct.billId", "egBill", CriteriaSpecification.LEFT_JOIN)
                .add(Restrictions.in("egBill.egDemand", egDemand))
                .add(Restrictions.eq("billRct.isCancelled", Boolean.FALSE))
                .addOrder(Order.asc("billRct.receiptDate"));

        billReceipts = criteria.list();
    }
    return billReceipts;
}

From source file:org.geoserver.taskmanager.data.impl.TaskManagerDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  ww w  .  jav  a2s .c  o  m
public List<Batch> getBatches(boolean hideSpecial) {
    Criteria criteria = getSession().createCriteria(BatchImpl.class)
            .createAlias("configuration", "configuration", CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.eq("removeStamp", 0L))
            .add(Restrictions.or(Restrictions.isNull("configuration"),
                    Restrictions.and(Restrictions.eq("configuration.removeStamp", 0L),
                            Restrictions.eq("configuration.validated", true))));
    if (hideSpecial) {
        criteria.add(Restrictions.or(Restrictions.isNull("configuration"),
                Restrictions.not(Restrictions.like("name", "@%"))));
    }
    return criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}

From source file:org.infoscoop.dao.OAuthConsumerDAO.java

License:Open Source License

public OAuthConsumerProp getConsumer(String gadgetUrl, String serviceName) {
    if (gadgetUrl == null || serviceName == null) {
        throw new RuntimeException("gadgetUrl and serviceName must be set.");
    }//from w w  w  . j a v a  2  s  . c o  m

    Iterator results = super.getHibernateTemplate()
            .findByCriteria(
                    DetachedCriteria.forClass(OAuthConsumerProp.class, "ocp")
                            .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN)
                            .add(Restrictions.conjunction().add(Restrictions.eq("ocp.ServiceName", serviceName))
                                    .add(Restrictions.eq("ogu.GadgetUrlKey", Crypt.getHash(gadgetUrl)))))
            .iterator();

    if (results.hasNext()) {
        return (OAuthConsumerProp) results.next();
    }

    return null;
}

From source file:org.infoscoop.dao.OAuthConsumerDAO.java

License:Open Source License

public Boolean validateConsumerByIdAndServiceAndURL(String id, String serviceName, String gadgetUrl) {
    // Refactoring: create hibernate object (mapping? criteria? and o)
    Iterator results = super.getHibernateTemplate()
            .findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class, "ocp")
                    .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN)
                    .add(Restrictions.conjunction().add(Restrictions.ne("ocp.Id", id))
                            .add(Restrictions.eq("ocp.ServiceName", serviceName))
                            .add(Restrictions.eq("ogu.GadgetUrlKey", Crypt.getHash(gadgetUrl)))))
            .iterator();//from   www  . ja  v  a  2s . c o  m

    if (results.hasNext()) {
        // if same contents are had, database is not updated.
        return true;
    }

    return false;
}

From source file:org.infoscoop.dao.OAuthConsumerDAO.java

License:Open Source License

public List<OAuthConsumerProp> getConsumersByUid(String uid) {
    return super.getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class)
            .createAlias("OAuthToken", "ot", CriteriaSpecification.LEFT_JOIN)
            .createAlias("OAuth2Token", "o2t", CriteriaSpecification.LEFT_JOIN)
            .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.or(/* w  ww.j  a v  a2s  .c  om*/
                    Restrictions.and(Restrictions.eq("ot.Id.Uid", uid),
                            Restrictions.isNotNull("ot.accessToken")),
                    Restrictions.and(Restrictions.eq("o2t.Id.Uid", uid),
                            Restrictions.isNotNull("o2t.accessToken")))));
}

From source file:org.infoscoop.dao.OAuthConsumerDAO.java

License:Open Source License

public List<OAuthConsumerProp> getConsumersJoinGadgetUrl() {
    return super.getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class)
            .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN));
}