Example usage for org.hibernate Criteria setCacheable

List of usage examples for org.hibernate Criteria setCacheable

Introduction

In this page you can find the example usage for org.hibernate Criteria setCacheable.

Prototype

public Criteria setCacheable(boolean cacheable);

Source Link

Document

Enable caching of this query result, provided query caching is enabled for the underlying session factory.

Usage

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static SecureUser getUserByName(String name, Session session) {
    Criteria userCriterion = session.createCriteria(SecureUser.class);
    userCriterion.add(Expression.eq("name", name));
    userCriterion.setCacheable(true);
    return (SecureUser) userCriterion.uniqueResult();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static List allOpenBinaryMarkets() {
    Criteria marketCriterion = currentSession().createCriteria(BinaryMarket.class);
    marketCriterion.add(Expression.eq("marketClosed", Boolean.FALSE));
    marketCriterion.setCacheable(true);
    return marketCriterion.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static List allOpenMultiMarkets() {
    Criteria marketCriterion = currentSession().createCriteria(MultiMarket.class);
    marketCriterion.add(Expression.eq("marketClosed", Boolean.FALSE));
    marketCriterion.setCacheable(true);
    return marketCriterion.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static List allClosedMarkets() {
    Criteria marketCriterion = currentSession().createCriteria(Market.class);
    marketCriterion.add(Expression.eq("marketClosed", Boolean.TRUE));
    marketCriterion.addOrder(Order.desc("id")); // we don't have the time of closure
    marketCriterion.setCacheable(true);
    return marketCriterion.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static BinaryClaim getBinaryClaimByName(String name) {
    Session session = HibernateUtil.currentSession();
    Criteria claimCriterion = session.createCriteria(BinaryClaim.class);
    claimCriterion.add(Expression.eq("name", name));
    claimCriterion.setCacheable(true);
    return (BinaryClaim) claimCriterion.uniqueResult();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static Claim getClaimByName(String name) {
    Session session = HibernateUtil.currentSession();
    Criteria claimCriterion = session.createCriteria(Claim.class);
    claimCriterion.add(Expression.eq("name", name));
    claimCriterion.setCacheable(true);
    return (Claim) claimCriterion.uniqueResult();
}

From source file:net.databinder.models.hib.BasicCacheableCriteriaBuilder.java

License:Open Source License

@Override
public void buildUnordered(Criteria criteria) {
    super.buildUnordered(criteria);
    criteria.setCacheable(true);
}

From source file:net.sf.xplanner.dao.impl.BaseDao.java

License:Open Source License

@Override
public Criteria createCriteria() {
    final Criteria criteria = this.getSession().createCriteria(this.domainClass);
    criteria.setCacheable(true);
    return criteria;
}

From source file:org.accada.epcis.repository.capture.CaptureOperationsModule.java

License:Open Source License

/**
 * Inserts vocabulary into the database by searching for already existing
 * entries; if found, the corresponding ID is returned. If not found, the
 * vocabulary is extended if "insertmissingvoc" is true; otherwise an
 * SQLException is thrown// w  w  w  .  j av  a  2s.com
 * 
 * @param tableName
 *            The name of the vocabulary table.
 * @param uri
 *            The vocabulary adapting the URI to be inserted into the
 *            vocabulary table.
 * @return The ID of an already existing vocabulary table with the given
 *         uri.
 * @throws UnsupportedOperationException
 *             If we are not allowed to insert a missing vocabulary.
 */
public VocabularyElement getOrInsertVocabularyElement(Session session, String vocabularyType,
        String vocabularyElement) throws SAXException {
    Class<?> c = vocClassMap.get(vocabularyType);
    Criteria c0 = session.createCriteria(c);
    c0.setCacheable(true);
    c0.add(Restrictions.eq("uri", vocabularyElement));
    VocabularyElement ve;
    try {
        ve = (VocabularyElement) c0.uniqueResult();
    } catch (ObjectNotFoundException e) {
        ve = null;
    }
    if (ve == null) {
        // the uri does not yet exist: insert it if allowed. According to
        // the specs, some vocabulary is not allowed to be extended; this is
        // currently ignored here
        if (!insertMissingVoc) {
            throw new UnsupportedOperationException(
                    "Not allowed to add new vocabulary - use existing vocabulary");
        } else {
            // VocabularyElement subclasses should always have public
            // zero-arg constructor to avoid problems here
            try {
                ve = (VocabularyElement) c.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }

            ve.setUri(vocabularyElement);
            session.save(ve);
            session.flush();
        }
    }
    return ve;
}

From source file:org.broadleafcommerce.core.offer.dao.OfferDaoImpl.java

License:Apache License

@Override
public List<Offer> readOffersByAutomaticDeliveryType() {
    //TODO change this to a JPA criteria
    Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class);

    Date myDate = getCurrentDateAfterFactoringInDateResolution();

    Calendar c = Calendar.getInstance();
    c.setTime(myDate);//  w ww. java 2s  .  co  m
    c.add(Calendar.DATE, +1);
    criteria.add(Restrictions.lt("startDate", c.getTime()));
    c = Calendar.getInstance();
    c.setTime(myDate);
    c.add(Calendar.DATE, -1);
    criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime())));
    criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'),
            Restrictions.isNull("archiveStatus.archived")));

    // Automatically Added or (Automatically Added is null and deliveryType is Automatic)
    criteria.add(Restrictions.or(Restrictions.eq("automaticallyAdded", true), Restrictions
            .and(Restrictions.isNull("automaticallyAdded"), Restrictions.eq("deliveryType", "AUTOMATIC"))));

    criteria.setCacheable(true);
    criteria.setCacheRegion("query.Offer");

    return criteria.list();
}