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.tonguetied.administration.ServerDataRepositoryImpl.java

License:Apache License

public ServerData getLatestData() {

    ServerData serverData;/*from   w w w . j a  va2 s  .  co  m*/
    try {
        Query query = getSession().getNamedQuery(QUERY_GET_LATEST_SERVER_DATA);
        query.setCacheable(true);
        serverData = (ServerData) query.uniqueResult();
    } catch (SQLGrammarException sge) {
        // if the table cannot be found in the database then return null
        DataAccessException dae = convertHibernateAccessException(sge);
        if (dae instanceof InvalidDataAccessResourceUsageException)
            serverData = null;
        else
            throw dae;
    }
    return serverData;
}

From source file:org.tonguetied.keywordmanagement.BundleRepositoryImpl.java

License:Apache License

public Bundle getDefaultBundle() {
    Query query = getSession().getNamedQuery(QUERY_GET_DEFAULT_BUNDLE);
    query.setCacheable(true);
    return (Bundle) query.uniqueResult();
}

From source file:org.tonguetied.keywordmanagement.BundleRepositoryImpl.java

License:Apache License

public List<Bundle> getBundles() {
    Query query = getSession().getNamedQuery(QUERY_GET_BUNDLES);
    query.setCacheable(true);
    return query.list();
}

From source file:org.tonguetied.keywordmanagement.CountryRepositoryImpl.java

License:Apache License

public List<Country> getCountries() {
    Query query = getSession().getNamedQuery(QUERY_GET_COUNTRIES);
    query.setCacheable(true);
    return query.list();
}

From source file:org.tonguetied.keywordmanagement.LanguageRepositoryImpl.java

License:Apache License

public List<Language> getLanguages() {
    Query query = getSession().getNamedQuery(QUERY_GET_LANAGUAGES);
    query.setCacheable(true);
    return query.list();
}

From source file:org.tonguetied.usermanagement.UserRepositoryImpl.java

License:Apache License

public PaginatedList<User> getUsers(final Integer firstResult, final Integer maxResults) {
    Query query = getSession().getNamedQuery(QUERY_GET_USERS);
    query.setCacheable(true);
    if (firstResult != null)
        query.setFirstResult(firstResult);
    if (maxResults != null)
        query.setMaxResults(maxResults);

    Long maxListSize = 0L;/*from  ww  w  . ja v  a 2 s .  c  o  m*/
    final List<User> queryList = query.list();
    if (queryList.size() > 0)
        maxListSize = (Long) getSession().getNamedQuery(QUERY_USER_COUNT).uniqueResult();

    return new PaginatedList<User>(queryList, maxListSize.intValue());
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

License:Apache License

public Ticket findTicket(String key) {
    if (key == null) {
        throw new IllegalArgumentException("key cannot be null");
    }/*from   www . j a v  a 2 s  . c  o  m*/

    try {
        // prevent auto flushing when looking up ticket
        getSession().setFlushMode(FlushMode.MANUAL);
        Query hibQuery = getSession().getNamedQuery("ticket.by.key").setParameter("key", key);
        hibQuery.setCacheable(true);
        hibQuery.setFlushMode(FlushMode.MANUAL);
        return (Ticket) hibQuery.uniqueResult();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

License:Apache License

public PasswordRecovery getPasswordRecovery(String key) {
    try {/*from   w w w.java2  s  .c  o  m*/
        Query hibQuery = getSession().getNamedQuery("passwordRecovery.byKey").setParameter("key", key);
        hibQuery.setCacheable(true);
        return (PasswordRecovery) hibQuery.uniqueResult();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

License:Apache License

private User findUserByUsernameIgnoreCase(String username) {
    Session session = getSession();//from   w  w  w  .  jav a  2s.  c  o  m
    Query hibQuery = session.getNamedQuery("user.byUsername.ignorecase").setParameter("username", username);
    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.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByUsernameOrEmailIgnoreCaseAndId(Long userId, String username, String email) {
    Session session = getSession();//from   w  ww  . j a  v  a2s  . c  o m
    Query hibQuery = session.getNamedQuery("user.byUsernameOrEmail.ignorecase.ingoreId")
            .setParameter("username", username).setParameter("email", email).setParameter("userid", userId);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0) {
        return (User) users.get(0);
    } else {
        return null;
    }
}