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.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByEmail(String email) {
    Session session = getSession();/*  w  w  w  . j  ava2 s .co m*/
    Query hibQuery = session.getNamedQuery("user.byEmail").setParameter("email", email);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByEmailIgnoreCase(String email) {
    Session session = getSession();/*from w w w .  ja  v a  2  s.co m*/
    Query hibQuery = session.getNamedQuery("user.byEmail.ignorecase").setParameter("email", email);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByUid(String uid) {
    Session session = getSession();//from  w ww. j  a va  2s .  co m
    Query hibQuery = session.getNamedQuery("user.byUid").setParameter("uid", uid);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    return (User) hibQuery.uniqueResult();
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByActivationId(String id) {
    Session session = getSession();//  ww w.  jav  a2s  . com
    Query hibQuery = session.getNamedQuery("user.byActivationId").setParameter("activationId", id);
    hibQuery.setCacheable(true);
    return (User) hibQuery.uniqueResult();
}

From source file:org.osaf.cosmo.dao.hibernate.UserPreferencesScheduleDao.java

License:Apache License

public Set<User> getUsersWithSchedules() {
    Set<User> users = new HashSet<User>();

    try {/*from   w  ww . j  a v a 2s.  c  o m*/
        Query hibQuery = getSession().getNamedQuery("users.withSchedules");
        hibQuery.setCacheable(true);
        users.addAll(hibQuery.list());
        return users;
    } catch (HibernateException e) {
        getSession().clear();
        throw convertHibernateAccessException(e);
    }
}

From source file:org.oscarehr.phr.dao.hibernate.PHRDocumentDAOHibernate.java

License:Open Source License

public boolean hasIndex(String idx) {
    final String index = idx;
    Long num = (Long) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session
                    .createQuery("select count(*) from PHRDocument p where p.phrIndex= '" + index + "'");
            q.setCacheable(true);
            return q.uniqueResult();
        }/*  ww w  .j a  va 2s.c  om*/
    });
    log.debug("number of documents with that idx " + num);
    if (num > 0) {
        return true;
    }
    return false;
}

From source file:org.oscarehr.phr.dao.hibernate.PHRDocumentDAOHibernate.java

License:Open Source License

public int countUnreadDocuments(final String classification, final String providerNo) {
    Long num = (Long) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery("select count(*) from PHRDocument d where d.phrClassification = '"
                    + classification + "' and d.receiverOscar = '" + providerNo + "' and d.status = "
                    + PHRMessage.STATUS_NEW);
            q.setCacheable(true);
            return q.uniqueResult();
        }/*  w w w  .ja  v  a  2s.co  m*/
    });
    return num.intValue();
}

From source file:org.oscarehr.phr.dao.PHRActionDAO.java

License:Open Source License

public boolean ifActionsWithErrors(final String providerNo) {
    Long num = (Long) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery("select count(*) from PHRAction a where a.senderOscar = '"
                    + providerNo + "' AND a.status=" + PHRAction.STATUS_NOT_AUTHORIZED);
            q.setCacheable(true);
            return q.uniqueResult();
        }/*from www .j a  va 2  s . c  o  m*/
    });
    if (num > 0)
        return true;
    return false;
}

From source file:org.oscarehr.phr.dao.PHRActionDAO.java

License:Open Source License

public boolean isIndivoRegistered(final String classification, final String oscarId) {
    Long num = (Long) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery("select count(*) from PHRAction a where a.phrClassification = '"
                    + classification + "' and a.oscarId = '" + oscarId + "'");
            q.setCacheable(true);
            return q.uniqueResult();
        }/* w  ww .  j  a va2s  .  c  om*/
    });
    if (num > 0)
        return true;
    return false;

}

From source file:org.ow2.bonita.util.hibernate.HibernateListCommand.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<T> execute(Environment environment) throws Exception {
    Session session = (Session) environment.get(this.sessionName);

    Query query = session.createQuery(this.query);
    if (stringParameters != null) {
        for (Map.Entry<String, String> stringParameter : stringParameters.entrySet()) {
            query.setString(stringParameter.getKey(), stringParameter.getValue());
        }/*from www  . j  a v a2  s  .c  o  m*/
    }
    query.setCacheable(true);
    List<T> result = new ArrayList<T>();
    result.addAll((Collection<T>) query.list());
    return result;
}