List of usage examples for javax.persistence Query setHint
Query setHint(String hintName, Object value);
From source file:com.music.dao.Dao.java
protected void setCacheable(Query query) { //TODO consider if every query should be cached (hibernate advises against it) query.setHint("org.hibernate.cacheable", Boolean.TRUE); }
From source file:cn.guoyukun.spring.jpa.repository.RepositoryHelper.java
public void applyEnableQueryCache(Query query) { if (enableQueryCache) { query.setHint("org.hibernate.cacheable", true);//? }/* w ww . j av a 2 s . c om*/ }
From source file:org.opens.tgol.entity.dao.tanaguru.reference.TgolTestDAOImpl.java
@Override @SuppressWarnings("unchecked") public List<Test> retrieveAllByLevel(Level level) { if (StringUtils.equalsIgnoreCase(level.getCode(), GOLD_LEVEL)) { return this.findAll(); } else {/*from w w w . j a v a2 s.c om*/ StringBuilder queryStr = new StringBuilder(); queryStr.append("SELECT t FROM "); queryStr.append(getEntityClass().getName()); queryStr.append(" t WHERE t.level = :bronzeLevel"); if (StringUtils.equalsIgnoreCase(level.getCode(), SILVER_LEVEL)) { queryStr.append(" OR t.level = :silverLevel"); } Query query = entityManager.createQuery(queryStr.toString()); query.setParameter("bronzeLevel", bronzeLevel); if (StringUtils.equalsIgnoreCase(level.getCode(), SILVER_LEVEL)) { query.setParameter("silverLevel", level); } query.setHint("org.hibernate.cacheable", "true"); return query.getResultList(); } }
From source file:org.asqatasun.entity.dao.subject.WebResourceDAOImpl.java
@Override public WebResource ligthRead(Long webResourceId) { try {/*from w w w . ja v a2 s .com*/ Query query = entityManager .createQuery("SELECT wr FROM " + getEntityClass().getName() + " wr" + " WHERE wr.id = :id"); query.setParameter("id", webResourceId); query.setHint(CACHEABLE_OPTION, TRUE); return (WebResource) query.getSingleResult(); } catch (NoResultException nre) { return null; } }
From source file:org.asqatasun.entity.dao.subject.WebResourceDAOImpl.java
@Override public Long findChildWebResourceCount(WebResource parentWebResource) { if (parentWebResource == null) { return null; }//w w w .ja v a 2s.c o m Query query = entityManager.createQuery( "SELECT count (r.id) FROM " + getEntityClass().getName() + " r" + " WHERE r.parent.id = :id"); query.setParameter("id", parentWebResource.getId()); query.setHint(CACHEABLE_OPTION, TRUE); try { return (Long) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.broadleafcommerce.openadmin.server.security.dao.AdminPermissionDaoImpl.java
public boolean doesOperationExistForCeilingEntity(PermissionType permissionType, String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try {/*from w ww. jav a 2 s .c o m*/ for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_BY_TYPE_AND_CEILING_ENTITY"); query.setParameter("type", permissionType.getType()); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; }
From source file:net.sf.gazpachoquest.qbe.NamedQueryUtil.java
private Query recreateQuery(final Query current, final String newSqlString) { Query result = entityManager.createQuery(newSqlString); Map<String, Object> hints = current.getHints(); for (Entry<String, Object> entry : hints.entrySet()) { String hintName = entry.getKey(); Object hint = entry.getValue(); result.setHint(hintName, hint); }//from w w w . j av a2 s. c om return result; }
From source file:se.vgregion.webbisar.svc.impl.WebbisDaoHibernate.java
/** * {@inheritDoc}// ww w . j a va 2 s .c om */ public long getNumberOfWebbisar() { Object results = getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = em.createQuery("select count(*) from Webbis w where w.disabled = false"); q.setHint("org.hibernate.cacheable", true); return q.getSingleResult(); } }); return (Long) results; }
From source file:org.broadleafcommerce.openadmin.server.security.dao.AdminPermissionDaoImpl.java
public boolean isUserQualifiedForOperationOnCeilingEntityViaDefaultPermissions( String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try {/*from w w w . j a v a 2s. c o m*/ for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_BY_PERMISSION_AND_CEILING_ENTITY"); query.setParameter("permissionNames", Arrays.asList(AdminSecurityService.DEFAULT_PERMISSIONS)); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; }
From source file:org.broadleafcommerce.openadmin.server.security.dao.AdminPermissionDaoImpl.java
public boolean isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try {//w ww .j av a2s. co m for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_FOR_USER_BY_TYPE_AND_CEILING_ENTITY"); query.setParameter("adminUser", adminUser); query.setParameter("type", permissionType.getType()); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; }