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.tonguetied.usermanagement.UserRepositoryImpl.java

License:Apache License

/**
 * Create a search criteria object.//  w  w w . ja v a  2s  . c  o m
 * 
 * @param user the object used to create the search criteria
 * @return the criteria object used to find matches
 */
private Criteria createCriteria(final User user) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.setCacheable(true);
    addCriteria(criteria, FIELD_USERNAME, user.getUsername());
    addCriteria(criteria, FIELD_FIRSTNAME, user.getFirstName());
    addCriteria(criteria, FIELD_LASTNAME, user.getLastName());
    addCriteria(criteria, FIELD_EMAIL, user.getEmail());
    return criteria;
}

From source file:org.unitime.timetable.model.base._BaseRootDAO.java

License:Open Source License

/**
 * Return all objects related to the implementation of this DAO with no filter.
 * Use the session given.//from   w  w w  . j  a  va2s. com
 */
@SuppressWarnings("unchecked")
public List<T> findAll(Session s, Order... orders) {
    Criteria crit = s.createCriteria(getReferenceClass());
    if (orders != null) {
        for (Order order : orders) {
            if (order != null)
                crit.addOrder(order);
        }
    }
    crit.setCacheable(true);
    return (List<T>) crit.list();
}

From source file:org.unitime.timetable.model.Roles.java

License:Open Source License

public static Set<Roles> findAll(boolean managerOnly, org.hibernate.Session hibSession) {
    Criteria criteria = hibSession.createCriteria(Roles.class);
    if (managerOnly)
        criteria = criteria.add(Restrictions.eq("manager", Boolean.TRUE));
    return new TreeSet<Roles>(criteria.setCacheable(true).list());
}

From source file:org.workin.persistence.hibernate.v4.dao.Hibernate4DaoSupport.java

License:Apache License

/**
 * @description ??Criteria/*from  ww w. j  a v  a  2 s. c  o  m*/
 * @author <a href="mailto:code727@gmail.com">?</a> 
 * @param criteria
 */
protected void prepareCriteria(Criteria criteria) {
    if (this.cacheConfiguration != null) {
        if (this.cacheConfiguration.isCacheQueries()) {
            criteria.setCacheable(true);
            if (StringUtils.isNotBlank(this.cacheConfiguration.getQueryCacheRegion())) {
                criteria.setCacheRegion(this.cacheConfiguration.getQueryCacheRegion());
            }
        }

        if (this.cacheConfiguration.getFetchSize() > 0)
            criteria.setFetchSize(this.cacheConfiguration.getFetchSize());

        if (this.cacheConfiguration.getMaxResults() > 0)
            criteria.setMaxResults(this.cacheConfiguration.getMaxResults());
    }
}

From source file:org.yamj.core.database.dao.ArtworkDao.java

License:Open Source License

public ArtworkLocated getStoredArtworkLocated(ArtworkLocated located) {
    Criteria criteria = currentSession().createCriteria(ArtworkLocated.class);
    criteria.add(Restrictions.eq("artwork", located.getArtwork()));
    if (located.getStageFile() != null) {
        criteria.add(Restrictions.eq("stageFile", located.getStageFile()));
    } else {//from w  w w.j  av  a  2 s.c  o m
        criteria.add(Restrictions.eq("source", located.getSource()));
        criteria.add(Restrictions.eq("url", located.getUrl()));
    }
    criteria.setCacheable(true);
    return (ArtworkLocated) criteria.uniqueResult();
}

From source file:org.yamj.core.database.dao.ArtworkDao.java

License:Open Source License

public ArtworkGenerated getStoredArtworkGenerated(ArtworkGenerated generated) {
    Criteria criteria = currentSession().createCriteria(ArtworkGenerated.class);
    criteria.add(Restrictions.eq("artworkLocated", generated.getArtworkLocated()));
    criteria.add(Restrictions.eq("artworkProfile", generated.getArtworkProfile()));
    criteria.setCacheable(true);
    return (ArtworkGenerated) criteria.uniqueResult();
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public Long getNextStageFileId(FileType fileType, StatusType... statusTypes) {
    Criteria criteria = currentSession().createCriteria(StageFile.class);
    criteria.add(Restrictions.eq("fileType", fileType));
    criteria.add(Restrictions.in("status", statusTypes));
    criteria.setProjection(Projections.min("id"));
    criteria.setCacheable(true);
    criteria.setCacheMode(CacheMode.NORMAL);
    return (Long) criteria.uniqueResult();
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<StageDirectory> getRootDirectories() {
    Criteria criteria = currentSession().createCriteria(StageDirectory.class);
    criteria.add(Restrictions.isNull("parentDirectory"));
    criteria.setCacheable(true);
    criteria.setCacheMode(CacheMode.NORMAL);
    return criteria.list();
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<StageDirectory> getChildDirectories(StageDirectory stageDirectory) {
    if (stageDirectory == null) {
        return Collections.emptyList();
    }/*  w  w  w .j  a  va 2 s  . c  om*/

    Criteria criteria = currentSession().createCriteria(StageDirectory.class);
    criteria.add(Restrictions.eq("parentDirectory", stageDirectory));
    criteria.setCacheable(true);
    criteria.setCacheMode(CacheMode.NORMAL);
    return criteria.list();
}

From source file:org.zanata.dao.AccountDAO.java

License:Open Source License

public HAccount getByUsername(String username) {
    Criteria cr = getSession().createCriteria(HAccount.class);
    cr.add(Restrictions.eq("username", username));
    cr.setCacheable(true).setComment("AccountDAO.getByUsername");
    return (HAccount) cr.uniqueResult();
}