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:edu.wisc.my.portlets.bookmarks.dao.hibernate.HibernateBookmarkStore.java

License:Apache License

/**
 * @see edu.wisc.my.portlets.bookmarks.dao.BookmarkStore#getBookmarkSet(java.lang.String, java.lang.String)
 *//*from   w  w  w. j  a va2s. c om*/
public BookmarkSet getBookmarkSet(String owner, String name) {
    try {
        final Session session = this.getSession(false);

        final Criteria c = session.createCriteria(BookmarkSet.class);
        c.add(Restrictions.and(this.smartEqual(PARAM_NAME, name), this.smartEqual(PARAM_OWNER, owner)));
        c.setCacheable(true);

        final BookmarkSet bs = (BookmarkSet) c.uniqueResult();

        return bs;
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:edu.wisc.my.portlets.bookmarks.dao.hibernate.HibernatePreferencesStore.java

License:Apache License

/**
 * @see edu.wisc.my.portlets.bookmarks.dao.PreferencesStore#getPreferences(java.lang.String, java.lang.String)
 *///from   w  w  w  .j  a v  a2 s.c  o m
public Preferences getPreferences(String owner, String name) {
    try {
        final Session session = this.getSession(false);

        final Criteria c = session.createCriteria(Preferences.class);
        c.add(Restrictions.and(this.smartEqual(PARAM_NAME, name), this.smartEqual(PARAM_OWNER, owner)));
        c.setCacheable(true);

        final Preferences bs = (Preferences) c.uniqueResult();

        return bs;
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

License:Apache License

@SuppressWarnings("unchecked")
public List<T> list() throws ServiceException {
    try {//  w ww  . jav  a 2s  . c  o  m
        EntityManager entityManager = currentEntityManager();

        Criteria criteria = ((Session) entityManager.getDelegate()).createCriteria(getObjectClass());
        criteria.setMaxResults(getMaxResults());
        return criteria.setCacheable(true).list();
    } catch (PersistenceException e) {
        logger.error(e.getCause(), e);
        throw new ServiceException("Can't get object list from database", e);
    } finally {
        closeEntityManager();
    }
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

License:Apache License

@SuppressWarnings("unchecked")
public List<T> search(final T exampleEntity) throws ServiceException {
    try {//  www . j  a v  a  2 s  .  c  o m
        Validate.notNull(exampleEntity, "Example entity must not be null");
        logger.debug("Search: " + exampleEntity.toString());
        Session session = ((Session) currentEntityManager().getDelegate());
        Criteria criteria = session.createCriteria(getObjectClass());
        Example example = Example.create(exampleEntity);
        example.setPropertySelector(NOT_NULL_OR_EMPTY);
        example.ignoreCase();
        example.enableLike();
        logger.debug("Search example object: " + example.toString());
        criteria.add(example);
        criteria.setMaxResults(getMaxResults());
        criteria.setCacheable(true);
        return criteria.list();
    } catch (PersistenceException e) {
        logger.error(e.getCause(), e);
        throw new ServiceException("Can't search object list from database", e);
    } finally {
        closeEntityManager();
    }
}

From source file:io.github.jonestimd.finance.dao.hibernate.HibernateDao.java

License:Open Source License

protected <T extends ENTITY> Criteria buildGetAllCriteria(Class<T> criteriaClass, String... associations) {
    Criteria criteria = getSession().createCriteria(criteriaClass);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.setCacheable(true);
    for (String path : associations) {
        criteria.setFetchMode(path, FetchMode.JOIN);
    }/*www  .j  a va  2  s  . co m*/
    return criteria;
}

From source file:io.milton.vfs.db.GroupFolder.java

License:Open Source License

public static List<GroupFolder> findByOrg(Organisation org, Session session) {
    Criteria crit = session.createCriteria(GroupFolder.class);
    crit.setCacheable(true);
    crit.add(Restrictions.eq("org", org));
    crit.addOrder(Order.asc("name"));
    return DbUtils.toList(crit, GroupFolder.class);
}

From source file:io.milton.vfs.db.GroupFolder.java

License:Open Source License

public static GroupFolder findByOrgAndName(Organisation org, String name, Session session) {
    Criteria crit = session.createCriteria(GroupFolder.class);
    crit.setCacheable(true);
    crit.add(Restrictions.eq("org", org));
    crit.add(Restrictions.eq("name", name));
    crit.addOrder(Order.asc("name"));
    return (GroupFolder) crit.uniqueResult();
}

From source file:io.milton.vfs.db.GroupFolder.java

License:Open Source License

public static List<Group> findGroupsInFolder(Organisation org, GroupFolder groupFolder, Session session) {
    Criteria crit = session.createCriteria(Group.class);
    crit.setCacheable(true);
    crit.add(Restrictions.eq("organisation", org));
    crit.add(Restrictions.eq("groupFolder", groupFolder));
    crit.add(Restrictions.isNull("deleted"));
    crit.addOrder(Order.asc("name"));
    return DbUtils.toList(crit, Group.class);
}

From source file:io.milton.vfs.db.GroupFolder.java

License:Open Source License

private static List<Group> findGroupsToRemove(Organisation org, GroupFolder groupFolder, Session session) {
    Criteria crit = session.createCriteria(Group.class);
    crit.setCacheable(true);
    crit.add(Restrictions.eq("organisation", org));
    crit.add(Restrictions.eq("groupFolder", groupFolder));

    crit.addOrder(Order.asc("name"));
    return DbUtils.toList(crit, Group.class);
}

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateDao.java

License:Apache License

@Override
@Transactional(readOnly = true)/*  ww w.j  a  v a  2 s . c  o  m*/
public final <T> List<T> findAll(Class<T> clazz, Order... orders) {
    if (ArrayTool.isEmpty(orders)) {
        Query query = getSession().createQuery("from " + clazz.getName());
        return (List<T>) query.setCacheable(cacheable).list();
    } else {
        Criteria criteria = getSession().createCriteria(clazz);
        HibernateTool.addOrders(criteria, orders);
        return criteria.setCacheable(cacheable).list();
    }
}