Example usage for org.hibernate Query setCacheMode

List of usage examples for org.hibernate Query setCacheMode

Introduction

In this page you can find the example usage for org.hibernate Query setCacheMode.

Prototype

Query<R> setCacheMode(CacheMode cacheMode);

Source Link

Document

(Re)set the current CacheMode in effect for this query.

Usage

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

License:Open Source License

public List<StageFile> findStageFiles(FileType fileType, String searchName, String searchExtension,
        StageDirectory stageDirectory) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct sf ");
    sb.append("FROM StageFile sf ");
    sb.append("WHERE sf.fileType=:fileType ");
    sb.append("AND lower(sf.baseName)=:searchName ");
    if (searchExtension != null) {
        sb.append("AND lower(sf.extension)=:searchExtension ");
    }/*from  w  ww. j  ava  2 s.  c om*/
    sb.append("AND sf.stageDirectory=:stageDirectory ");
    sb.append("AND sf.status != :duplicate ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setParameter("fileType", fileType);
    query.setString("searchName", searchName.toLowerCase());
    if (searchExtension != null) {
        query.setString("searchExtension", searchExtension.toLowerCase());
    }
    query.setParameter("stageDirectory", stageDirectory);
    query.setParameter("duplicate", StatusType.DUPLICATE);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

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

License:Open Source License

public List<StageFile> findStageFiles(FileType fileType, String searchName, String searchExtension,
        Library library) {/*from  www.ja  v  a2 s  . c om*/
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct sf ");
    sb.append("FROM StageFile sf ");
    if (library != null) {
        sb.append("JOIN sf.stageDirectory sd ");
    }
    sb.append("WHERE sf.fileType=:fileType ");
    sb.append("AND lower(sf.baseName)=:searchName ");
    if (searchExtension != null) {
        sb.append("AND lower(sf.extension)=:searchExtension ");
    }
    if (library != null) {
        sb.append("AND sd.library=:library ");
    }
    sb.append("AND sf.status != :duplicate ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setParameter("fileType", fileType);
    query.setString("searchName", searchName.toLowerCase());
    if (searchExtension != null) {
        query.setString("searchExtension", searchExtension.toLowerCase());
    }
    if (library != null) {
        query.setParameter("library", library);
    }
    query.setParameter("duplicate", StatusType.DUPLICATE);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

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

License:Open Source License

public List<StageFile> findVideoStageFiles(Artwork artwork) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct sf ");

    long id;//from  www  .j  a v a  2s . com
    if (artwork.getSeries() != null) {
        id = artwork.getSeries().getId();
        sb.append("FROM Series ser ");
        sb.append("JOIN ser.seasons sea ");
        sb.append("JOIN sea.videoDatas vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE sea.id=:id ");
    } else if (artwork.getSeason() != null) {
        id = artwork.getSeason().getId();
        sb.append("FROM Season sea ");
        sb.append("JOIN sea.videoDatas vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE sea.id=:id ");
    } else {
        id = artwork.getVideoData().getId();
        sb.append("FROM VideoData vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE vd.id=:id ");
    }
    sb.append("AND sf.fileType=:fileType ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setLong("id", id);
    query.setParameter("fileType", FileType.VIDEO);
    query.setBoolean("extra", Boolean.FALSE);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java

License:Apache License

/**
 * {@inheritDoc}/*from ww w .  j  a  va 2 s  . c  o m*/
 */
@SuppressWarnings("unchecked")
public List<T> findByNamedQueryCached(final String namedQueryName, final Object... parameters) {
    Query query = sessionFactory.getCurrentSession().getNamedQuery(namedQueryName);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    setQueryParameters(query, parameters);
    return query.list();
}