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.hyperic.hq.measurement.server.session.MeasurementDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
List<Measurement> findAvailMeasurementsByInstances(int type, Integer[] ids) {
    boolean checkIds = (ids != null && ids.length > 0);
    String sql = new StringBuilder().append("select m from Measurement m ").append("join m.template t ")
            .append("join t.monitorableType mt ").append("where mt.appdefType = :type and ")
            .append("m.resource is not null and ").append((checkIds ? "m.instanceId in (:ids) and " : ""))
            .append(ALIAS_CLAUSE).toString();

    Query q = getSession().createQuery(sql).setInteger("type", type);

    if (checkIds) {
        q.setParameterList("ids", ids);
    }/*ww w.ja va  2 s  .co m*/

    q.setCacheable(true);
    q.setCacheRegion("Measurement.findAvailMeasurementsByInstances");
    return q.list();
}

From source file:org.inbio.m3s.dao.core.impl.KeywordDAOImpl.java

License:Open Source License

public KeywordDTO getKeywordLite(final String keywordName, final String searchLocale) {
    //   logger.debug("getKeywordDBId... start ");
    HibernateTemplate template = getHibernateTemplate();
    return (KeywordDTO) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    //"select k.keywordId"
                    "select new org.inbio.m3s.dto.message.KeywordDTO(k.keywordId, tt.name)"
                            + " from TextTranslation as tt, Keyword as k" + " where tt.name = '" + keywordName
                            + "'" + " and tt.textId = k.nameTextId" + " and tt.locale = :searchLocale");
            query.setParameter("searchLocale", searchLocale);
            query.setCacheable(true);
            return query.uniqueResult();
        }/* ww  w  .  jav a 2s .  c  o m*/
    });
}

From source file:org.inbio.m3s.dao.core.impl.KeywordDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<KeywordDTO> getAllKeywordLiteForMedia(final Integer mediaId, final String searchLocale) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<KeywordDTO>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "select new org.inbio.m3s.dto.message.KeywordDTO(mk.keyword.keywordId, tt.name)"
                            + " from TextTranslation as tt, MediaKeyword as mk" + " where mk.id.mediaId = "
                            + mediaId + " and tt.textId = mk.keyword.nameTextId"
                            + " and tt.locale = :searchLocale");
            query.setParameter("searchLocale", searchLocale);
            query.setCacheable(true);
            return query.list();
        }//from   w  w  w.ja v  a 2s . c  o  m
    });
}

From source file:org.inbio.m3s.dao.core.impl.KeywordDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Keyword> findAllByMedia(final Integer mediaId) throws IllegalArgumentException {
    HibernateTemplate template = getHibernateTemplate();
    return (List<Keyword>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "select mk.keyword" + " from MediaKeyword as mk" + " where mk.id.mediaId = :mediaId");
            query.setParameter("mediaId", mediaId);
            query.setCacheable(true);
            return query.list();
        }//ww  w  . jav  a 2  s  .  com
    });
}

From source file:org.inbio.m3s.dao.core.impl.KeywordDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<KeywordDTO> findAllByPartialNamePaginated(final String partialKeywrod, final int maxResults,
        final String searchLocale) {
    logger.debug("findAllByPartialNamePaginated with[" + partialKeywrod + "]");
    HibernateTemplate template = getHibernateTemplate();
    return (List<KeywordDTO>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session
                    .createQuery("select new org.inbio.m3s.dto.message.KeywordDTO(k.keywordId, tt.name)"
                            + " from TextTranslation as tt, Keyword as k" + " where tt.locale = :searchLocale"
                            + " and tt.name like :keyword" + " and k.nameTextId = tt.textId");
            query.setParameter("searchLocale", searchLocale);
            query.setParameter("keyword", partialKeywrod);
            query.setFirstResult(0);//from w w w .  j  a v  a2 s .com
            query.setMaxResults(maxResults);
            query.setCacheable(true);
            return query.list();
        }
    });
}

From source file:org.inbio.m3s.dao.core.impl.MediaAttributeTypeDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<MediaAttributeType> findAllByMediaType(final String mediaTypeKey) throws IllegalArgumentException {
    logger.debug("findAllByMediaType");
    HibernateTemplate template = getHibernateTemplate();
    return (List<MediaAttributeType>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "select mat from MediaAttributeType as mat" + " where mat.mediaTypeId = " + mediaTypeKey);
            query.setCacheable(true);
            return query.list();
        }/*from  www  . j  a  v  a 2s  .co  m*/
    });
}

From source file:org.inbio.m3s.dao.core.impl.MediaDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Media> getLastPublicMedia(final int quantity) throws IllegalArgumentException {
    logger.debug("getting last public media in the DB");
    HibernateTemplate template = getHibernateTemplate();
    return (List<Media>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "select m from Media as m" + " where m.isPublic = 'Y'" + " order by m.mediaId desc");
            query.setCacheable(true);
            query.setFirstResult(0);//w ww .ja  v a  2s.  c  o  m
            query.setMaxResults(quantity);
            return query.list();
        }
    });
}

From source file:org.inbio.m3s.dao.core.impl.MediaTypeDAOImpl.java

License:Open Source License

/**
 * sugested languge: Properties.DEFAULT_LANGUAGE
public MediaTypeDTO getMediaTypeLite(final Integer mediaTypeId, final int language) throws IllegalArgumentException {
   logger.debug("getMediaTypeLite()...");
   HibernateTemplate template = getHibernateTemplate();
   return (MediaTypeDTO) template.execute(new HibernateCallback() {
 public Object doInHibernate(Session session) {
    Query query = session.createQuery(/*from   w ww.ja v a 2  s .c  o m*/
          "select new org.inbio.m3s.dto.message.MediaTypeDTO(mt.mediaTypeId, tt.name)"
          + "from TextTranslation as tt, MediaType as mt"
          + " where mt.mediaTypeId = " + mediaTypeId
          + " and mt.textByNameTextId = tt.text"
          + " and tt.language.languageId = " + language);
    //query.setParameter(0, nomenclaturalGroupId);
    query.setCacheable(true);
    return query.uniqueResult();
 }
   });
}
 */

/*
public MediaTypeDTO getMediaTypeLite(final String mediaTypeName) throws IllegalArgumentException {
   logger.debug("getMediaTypeLite()...");
   HibernateTemplate template = getHibernateTemplate();
   return (MediaTypeDTO) template.execute(new HibernateCallback() {
 public Object doInHibernate(Session session) {
    Query query = session.createQuery(
          "select new org.inbio.m3s.dto.message.MediaTypeDTO(mt.mediaTypeId, tt.name)"
          + " from TextTranslation as tt, MediaType as mt"
          + " where tt.language.languageId  = "   + MessageManager.DEFAULT_LOCALE
          + " and tt.name = '"+ mediaTypeName   + "'"
          + " and tt.textId = mt.textByNameTextId.textId");
    //query.setParameter(0, nomenclaturalGroupId);
    query.setCacheable(true);
    return query.uniqueResult();
 }
   });
}
*/

/*
@SuppressWarnings("unchecked")
public List<MediaTypeDTO> listAllForMediaCategoryLite(final Integer mediaCategoryId) throws IllegalArgumentException {
   logger.debug("listAllForMediaCategoryLite()...");
   HibernateTemplate template = getHibernateTemplate();
   return (List<MediaTypeDTO>) template.execute(new HibernateCallback() {
 public Object doInHibernate(Session session) {
    Query query = session.createQuery(
          "select new org.inbio.m3s.dto.message.MediaTypeDTO(mt.mediaTypeId, tt.name)"
          + " from TextTranslation as tt, MediaType as mt"
          + " where mt.mediaCategory.mediaCategoryId = " + mediaCategoryId
          + " and tt.textId = mt.textByNameTextId.textId"
          + " and tt.locale = "+ MessageManager.DEFAULT_LOCALE);
    query.setCacheable(true);
    return query.list();
 }
   });
           
}
*/

/*
 * 
 */
public MediaType findByName(final String mediaTypeName) {
    logger.debug("getMediaTypeLite()...");
    HibernateTemplate template = getHibernateTemplate();
    return (MediaType) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "select mt from TextTranslation as tt, MediaType as mt" + " where tt.locale = :locale"
                            + " and tt.name = :mediaTypeName" + " and tt.textId = mt.mediaTypeNameTextId");
            query.setParameter("locale", MessageManager.DEFAULT_LOCALE);
            query.setParameter("mediaTypeName", mediaTypeName);
            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
}

From source file:org.inbio.m3s.dao.core.impl.ProjectDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Project> findAllByMedia(final Integer mediaId) throws IllegalArgumentException {
    logger.debug("findAllByMedia with param [" + mediaId + "]");
    HibernateTemplate template = getHibernateTemplate();
    return (List<Project>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select p from Project as p, MediaProject as mp"
                    + " where mp.id.mediaId = :mediaId" + " and mp.id.projectId = p.projectId");
            query.setParameter("mediaId", mediaId);
            query.setCacheable(true);
            return query.list();
        }//from  w ww .j  a v a  2s.c  om
    });
}

From source file:org.inbio.m3s.dao.core.impl.ProjectDAOImpl.java

License:Open Source License

public Project findByName(final String projectName) throws IllegalArgumentException {
    logger.debug("findByName with[" + projectName + "]");
    HibernateTemplate template = getHibernateTemplate();
    return (Project) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session
                    .createQuery("select p from Project as p" + " where p.name = '" + projectName + "'");
            query.setCacheable(true);
            return query.uniqueResult();
        }//  ww w  .  j  a va2  s.  c o  m
    });
}