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:org.cast.cwm.data.builders.CachingCriteriaBuilder.java

License:Open Source License

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

From source file:org.cast.cwm.data.builders.LoginSessionCriteriaBuilder.java

License:Open Source License

@Override
public void buildUnordered(Criteria criteria) {
    if (openOnly)
        criteria.add(Restrictions.isNull("endTime"));

    criteria.createAlias("user", "user"); // Must be joined for sort on username to work.
    if (userId != null)
        criteria.add(Restrictions.eq("user.id", userId));

    criteria.setCacheable(true);
}

From source file:org.cast.cwm.data.builders.PeriodCriteriaBuilder.java

License:Open Source License

@Override
public void build(Criteria criteria) {
    if (name != null)
        criteria.add(Restrictions.eq("name", name));
    if (site != null)
        criteria.add(Restrictions.eq("site", site));
    if (maxResults != null)
        criteria.setMaxResults(maxResults);
    criteria.setCacheable(true);
}

From source file:org.cast.cwm.data.builders.PromptCriteriaBuilder.java

License:Open Source License

@Override
public void build(Criteria criteria) {
    if (identifier != null) {
        criteria.add(Restrictions.eq("identifier", identifier));
        criteria.setMaxResults(1); // identifier is unique
    }// w  w w.  jav a  2s  .  c  o m
    criteria.setCacheable(true);
}

From source file:org.cast.cwm.data.builders.ResponseCriteriaBuilder.java

License:Open Source License

@Override
public void buildUnordered(Criteria criteria) {
    if (promptModel != null && promptModel.getObject() != null)
        criteria.add(Restrictions.eq("prompt", promptModel.getObject()));
    if (userModel != null && userModel.getObject() != null)
        criteria.add(Restrictions.eq("user", userModel.getObject()));
    if (periodModel != null && periodModel.getObject() != null)
        criteria.createAlias("user", "user").createAlias("user.periods", "p")
                .add(Restrictions.eq("p.id", periodModel.getObject().getId()));
    if (responseType != null)
        criteria.add(Restrictions.eq("type", responseType));
    if (sortOrder != null)
        criteria.add(Restrictions.eq("sortOrder", sortOrder));
    if (maxResults != null)
        criteria.setMaxResults(maxResults);
    if (fromDate != null && toDate != null && fromDate.before(toDate))
        criteria.add(Restrictions.between("lastUpdated", fromDate, toDate));
    criteria.add(Restrictions.eq("valid", true));
    criteria.setCacheable(true);
}

From source file:org.cast.cwm.data.builders.UserCriteriaBuilder.java

License:Open Source License

@Override
public void buildUnordered(Criteria criteria) {
    if (role != null)
        criteria.add(Restrictions.eq("role", role));
    if (!getAllUsers)
        criteria.add(Restrictions.eq("valid", true));
    if (permissionedOnly)
        criteria.add(Restrictions.eq("permission", true));
    if (username != null)
        criteria.add(Restrictions.eq("username", username).ignoreCase());
    if (email != null)
        criteria.add(Restrictions.eq("email", email).ignoreCase());
    if (subjectId != null)
        criteria.add(Restrictions.eq("subjectId", subjectId).ignoreCase());
    if (firstName != null)
        criteria.add(Restrictions.eq("firstName", firstName).ignoreCase());
    if (lastName != null)
        criteria.add(Restrictions.eq("lastName", lastName).ignoreCase());
    if (period != null && period.getObject() != null)
        criteria.createAlias("periods", "p").add(Restrictions.eq("p.id", period.getObject().getId()));

    if (sites != null && sites.getObject() != null) {
        // Restricted by site membership
        criteria.createAlias("periods", "p");
        if (!sites.getObject().isEmpty())
            criteria.add(Restrictions.in("p.site", sites.getObject().toArray()));
        else/*w  w  w .j a va2  s . co  m*/
            criteria.add(Restrictions.idEq(0L)); // no sites selected, return no users
        // TODO should allow queries for users with no site at all, like @EventLog .
    }

    if (cacheResults)
        criteria.setCacheable(true);
}

From source file:org.cast.cwm.service.ResponseService.java

License:Open Source License

@Override
public Long getResponseCountForPrompt(IModel<? extends Prompt> mPrompt, IResponseType type,
        IModel<? extends User> mUser) {
    Criteria c = Databinder.getHibernateSession().createCriteria(Response.class);
    c.add(Restrictions.eq("prompt", mPrompt.getObject()));
    if (type != null)
        c.add(Restrictions.eq("type", type));
    if (mUser != null && mUser.getObject() != null)
        c.add(Restrictions.eq("user", mUser.getObject()));
    c.add(Restrictions.eq("valid", true));
    c.setProjection(Projections.rowCount());
    c.setCacheable(true);
    return (Long) c.uniqueResult();
}

From source file:org.cast.cwm.service.SiteService.java

License:Open Source License

@Override
public IModel<Site> getSiteByName(String name) {
    Criteria criteria = Databinder.getHibernateSession().createCriteria(Site.class);
    criteria.add(Restrictions.eq("name", name));
    criteria.setCacheable(true);
    return new HibernateObjectModel<Site>((Site) criteria.uniqueResult());
}

From source file:org.cast.isi.data.builder.ISIResponseCriteriaBuilder.java

License:Open Source License

@Override
public void buildUnordered(Criteria criteria) {
    // only get responses related to specific site(s)
    if (siteListModel != null && !siteListModel.getObject().isEmpty()) {
        criteria.createAlias("user", "user").createAlias("user.periods", "period", JoinType.LEFT_OUTER_JOIN);
        List<Site> siteList = siteListModel.getObject();
        Disjunction siteRestriction = Restrictions.disjunction();
        siteRestriction.add(Restrictions.in("period.site", siteList));
        criteria.add(siteRestriction);//from w ww.  j a va 2s.  c  o  m
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Remove duplicate rows as a result of the INNER JOIN
    }
    super.buildUnordered(criteria);

    // may want to push this to cwm - no cache used for large report data, more than 1000 objects
    criteria.setCacheable(canCache);
}

From source file:org.codehaus.grepo.query.hibernate.generator.CriteriaGeneratorBase.java

License:Apache License

protected void applyCachingSetting(HibernateQueryOptions queryOptions, HibernateQueryExecutionContext context,
        Criteria criteria) {
    if (HibernateGeneratorUtils.isCachingEnabled(queryOptions, context)) {
        criteria.setCacheable(true);
        String cacheRegion = HibernateGeneratorUtils.getCacheRegion(queryOptions, context);
        if (cacheRegion != null) {
            criteria.setCacheRegion(cacheRegion);
        }/*  w  ww. j a  v a  2  s.  co  m*/
    }
}