Example usage for org.hibernate Query setCacheable

List of usage examples for org.hibernate Query setCacheable

Introduction

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

Prototype

Query<R> setCacheable(boolean cacheable);

Source Link

Document

Enable/disable second level query (result) caching for this query.

Usage

From source file:org.beangle.model.persist.hibernate.HibernateEntityDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public <T> List<T> searchNamedQuery(final String queryName, final Map<String, Object> params,
        boolean cacheable) {
    Query query = getSession().getNamedQuery(queryName);
    query.setCacheable(cacheable);
    return QuerySupport.setParameter(query, params).list();
}

From source file:org.beangle.orm.hibernate.HibernateEntityDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public <T extends Entity<?>> List<T> getAll(Class<T> clazz) {
    String hql = "from " + modelMeta.getEntityType(clazz).getEntityName();
    Query query = getSession().createQuery(hql);
    query.setCacheable(true);
    return query.list();
}

From source file:org.beangle.orm.hibernate.HibernateEntityDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public <T> List<T> search(String queryString, final Map<String, Object> params, PageLimit limit,
        boolean cacheable) {
    Query query = getNamedOrCreateQuery(queryString);
    query.setCacheable(cacheable);
    if (null == limit)
        return QuerySupport.setParameter(query, params).list();
    else//w ww . j  a  v  a2s  . c o  m
        return paginateQuery(query, params, limit);
}

From source file:org.bonitasoft.engine.persistence.AbstractHibernatePersistenceService.java

License:Open Source License

protected void setQueryCache(final Query query, final String name) {
    if (cacheQueries != null && cacheQueries.containsKey(name)) {
        query.setCacheable(true);
    }//w ww  . j ava  2  s .  c  o  m
}

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

License:Open Source License

public Query build(Session hibernateSession) {
    Query q;

    if (userId == null)
        throw new IllegalArgumentException("Must supply a user for query");

    if (word != null) {
        // Search for a single word card
        q = hibernateSession.createQuery("from WordCard wc where wc.creator.id=:userId and wc.sortForm = :word")
                .setLong("userId", userId).setString("word", word);
    } else {//ww w . j  a v a2  s.  c  o  m
        // Search for all words for the user
        q = hibernateSession.createQuery("from WordCard wc where wc.creator.id=:userId order by wc.sortForm")
                .setLong("userId", userId);
    }

    q.setCacheable(true);

    return q;
}

From source file:org.cast.isi.service.ISIResponseService.java

License:Open Source License

public ClassMessage getClassMessage(IModel<Period> p) {
    Query q = Databinder.getHibernateSession().getNamedQuery("ClassMessage.queryByPeriod");
    q.setParameter("period", p.getObject());
    q.setCacheable(true);
    ClassMessage m = (ClassMessage) q.uniqueResult();
    // Databinder.getHibernateSession().evict(m);
    // TODO: test without evict
    return m;/*from  w  w w .j  a va  2s  .c  om*/
}

From source file:org.cast.isi.service.ISIResponseService.java

License:Open Source License

public boolean isFlagged(User person, Period period) {
    Query q;
    if (period != null) {
        q = Databinder.getHibernateSession().getNamedQuery("StudentFlag.queryByPeriodAndFlaggerAndFlagee");
        q.setParameter("period", period);
    } else {//from w w w.j  a va  2s.c om
        q = Databinder.getHibernateSession().getNamedQuery("StudentFlag.queryByFlaggerAndFlagee");
    }
    q.setParameter("flagee", person);
    q.setParameter("flagger", ISISession.get().getUser());
    q.setCacheable(true);
    StudentFlag f = (StudentFlag) q.uniqueResult();
    // Databinder.getHibernateSession().evict(f);
    if (f == null) {
        return false;
    } else {
        return true;
    }
}

From source file:org.cast.isi.service.ISIResponseService.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<StudentFlag> getAllFlags() {
    Query q = Databinder.getHibernateSession().getNamedQuery("StudentFlag.queryByFlagger");
    q.setParameter("flagger", ISISession.get().getUser());
    q.setCacheable(true);
    return q.list();
}

From source file:org.cast.isi.service.ISIResponseService.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<FeedbackMessage> getFeedbackMessages(IModel<Prompt> promptM, User student) {
    Query q = Databinder.getHibernateSession()
            .getNamedQuery("FeedbackMessage.getAllMessagesByPromptAndStudent");
    q.setParameter("prompt", promptM.getObject());
    q.setParameter("student", student);
    q.setCacheable(true);
    return q.list();
}

From source file:org.cast.isi.service.ISIResponseService.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<String> getPagesWithNotes(User student, boolean isUnread) {
    if (student.getRole().equals(Role.GUEST))
        return Collections.EMPTY_LIST;

    Query q = Databinder.getHibernateSession()
            .getNamedQuery("FeedbackMessage.getPagesWithNotesByStudentAndUnreadStatus");
    q.setParameter("student", student);
    q.setParameter("isUnread", isUnread);
    q.setParameter("role", ISISession.get().getUser().getRole());
    q.setCacheable(true);
    return q.list();
}